实际情况下也可能存在虚拟机要换IP的情况,不使用DHCP分配的IP。
网络配置 FlatDHCP
虚拟机原IP 192.168.1.77
新IP 192.168.1.18
1、关闭虚拟机
poweroff
2、删除虚拟机的网络接口
$ 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、添加新网络接口
c842228b-71e3-49d6-a5b5-33e6416e2669 是服务器的实例ID
nova interface-attach --fixed-ip 192.168.1.18 --net-id 26f6d6f9-0ff6-4825-99e8-35c3821f855f c842228b-71e3-49d6-a5b5-33e6416e2669
4、VNC登录虚拟机,修改IP
# /etc/udev/rules.d/70-persistent-net.rules #注掉原来MAC地址的那个 # 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" #将新添加的改为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"
重启后生效