KVM默认安装好后,会有一个virbr0,该网卡一般只做为物理机和虚拟机之间nat使用。其默认使用的网段是192.168.122.0/24网段,这就造成对应的内部虚拟机有一个在192.168.122.0/24段的IP。而有时这并不符合我们的要求,我们可以修改该网段的地址,当然也可以删除或禁用该网卡,改用其他网卡。

1、查看IP信息

1[root@localhost ~]# ifconfig virbr0
2virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
3        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
4        ether 52:54:00:2f:c8:44  txqueuelen 1000  (Ethernet)
5        RX packets 0  bytes 0 (0.0 B)
6        RX errors 0  dropped 0  overruns 0  frame 0
7        TX packets 0  bytes 0 (0.0 B)
8        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2、查看网络情况

1[root@localhost ~]# virsh net-list
2 名称               状态     自动开始  持久
3----------------------------------------------------------
4 default              活动     是           是

3、查看当前的网段配置

virbr0
virbr0

4、修改并启用

通过上面的net-edit命令打开后,我们修改对应的网段为172.25.0.0/24,并将对应的DHCP段的地址也修改掉。可以重启服务器生效,也可以通过下面的命令生效

 1[root@localhost ~]# virsh net-destroy  default
 2网络 default 被删除
 3[root@localhost ~]# virsh net-start default
 4网络 default 已启用
 5[root@localhost ~]# ifconfig virbr0
 6virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
 7        inet 172.25.0.1  netmask 255.255.255.0  broadcast 172.25.0.255
 8        ether 52:54:00:2f:c8:44  txqueuelen 1000  (Ethernet)
 9        RX packets 0  bytes 0 (0.0 B)
10        RX errors 0  dropped 0  overruns 0  frame 0
11        TX packets 0  bytes 0 (0.0 B)
12        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

destroy之前,建议先通过net-dumpxml将配置导出。

5、其他

新增网卡也是一样的道理,与网段相关的命令如下:

 1virsh # help network
 2 Networking (help keyword 'network'):
 3    net-autostart                  autostart a network
 4    net-create                     create a network from an XML file
 5    net-define                     define an inactive persistent virtual network or modify an existing persistent one from an XML file
 6    net-destroy                    destroy (stop) a network
 7    net-dhcp-leases                print lease info for a given network
 8    net-dumpxml                    network information in XML
 9    net-edit                       edit XML configuration for a network
10    net-event                      Network Events
11    net-info                       network information
12    net-list                       list networks
13    net-name                       convert a network UUID to network name
14    net-start                      start a (previously defined) inactive network
15    net-undefine                   undefine a persistent network
16    net-update                     update parts of an existing network's configuration
17    net-uuid                       convert a network name to network UUID