In fact, there may be a situation in which the virtual machine needs to change the IP, and the IP assigned by DHCP is not used.
Network configuration FlatDHCP
virtual machine original IP 192.168.1.77
new IP 192.168.1.18
1. Shut down the virtual machine
poweroff
2. Delete the network interface of the virtual machine
$ neutron port-list --fixed-ips ip_address=192.168.1.77 +--------------------------------------+------+-------------------+----------------------------------------------------+ | id | name | mac_address | fixed_ips | +--------------------------------------+------+-------------------+----------------------------------------------------+ | 37eac017-af9c-4fc8-a541-be0ba1019a43 | | fa:16:3e:cb:4a:79 | {"subnet_id": | | | | | "a0f6a183-cc8d-4011-8354-c7e53c4c9f72", | | | | | "ip_address": "192.168.1.77"} | +--------------------------------------+------+-------------------+----------------------------------------------------+ $ neutron port-delete 37eac017-af9c-4fc8-a541-be0ba1019a43 Deleted port: 37eac017-af9c-4fc8-a541-be0ba1019a43
3. Add a new network interface
c842228b-71e3-49d6-a5b5-33e6416e2669 is the instance ID of the server
nova interface-attach --fixed-ip 192.168.1.18 --net-id 26f6d6f9-0ff6-4825-99e8-35c3821f855f c842228b-71e3-49d6-a5b5-33e6416e2669
4. Log in to the virtual machine with VNC and modify the IP
# /etc/udev/rules.d/70-persistent-net.rules #Note out the one with the original MAC address # PCI device 0x1af4:0x1000 (virtio-pci) #SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="fa:16:3e:f8:d5:f3", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" #Change the newly added to eth0 # PCI device 0x1af4:0x1000 (virtio-pci) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="fa:16:3e:22:bd:6b", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
Take effect after restart