缺省情况下kvm会保留一个nat的网络,ip a命令查看,会看到virbr0和virbr0-nic
18: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
2 link/ether 52:54:00:6c:22:2c brd ff:ff:ff:ff:ff:ff
3 inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
49: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 500
5 link/ether 52:54:00:6c:22:2c brd ff:ff:ff:ff:ff:ff
这个如果虚机都是静态IP,且不做NAT的话,则无必要保留,可以彻底删掉。
kvm删除掉缺省网络
1virsh net-destroy default
2virsh net-undefine default
那么如果非用不可,还需要给特定虚机用dhcp指定固定IP 方法如下:
查看缺省网络
1$ virsh net-list
2 Name State Autostart Persistent
3----------------------------------------------------------
4 default active yes yes
找出虚机的mac地址
1$ virsh dumpxml vis-16-10-33 | grep -i '<mac'
2 <mac address='f0:00:ac:10:0a:21'/>
编辑网络
1$ virsh net-edit default
2
3<network>
4 <name>default</name>
5 <uuid>58e86841-ef4b-4d63-bf4f-7888515b8474</uuid>
6 <forward mode='nat'/>
7 <bridge name='virbr0' stp='on' delay='0' />
8 <mac address='52:54:00:6C:22:2C'/>
9 <ip address='192.168.122.1' netmask='255.255.255.0'>
10 <dhcp>
11 <range start='192.168.122.2' end='192.168.122.254' />
12 </dhcp>
13 </ip>
14</network>
在range下面来一列
1 <dhcp>
2 <range start='192.168.122.2' end='192.168.122.254' />
3 <host mac='f0:00:ac:10:0a:21' name='vis-16-10-33' ip='192.168.122.10'/>
4 </dhcp>
保存退出,重启网络
1$ virsh net-destroy default
2$ virsh net-start default
然后就可以了。