网络管理
1、查看原有网卡信息
kvm默认网络模式是基于nat转换的。如下可以看到
由于是基于iptables nat转换,如果iptables挂掉的话,就无法正常访问,顾下面使用桥接模式。(其实吧,各有各的优势吧,存在即合理~)
[root@linux-node1 ~]# brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.5254000cd692 yes virbr0-nic
vnet0
[root@linux-node1 ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.110 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::7ad7:e78f:d792:b0c1 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:ea:5b:27 txqueuelen 1000 (Ethernet)
RX packets 19840 bytes 1275665 (1.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 18495 bytes 1808646 (1.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:0c:d6:92 txqueuelen 1000 (Ethernet)
RX packets 289 bytes 19866 (19.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 232 bytes 20251 (19.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fc54:ff:fee8:b2b6 prefixlen 64 scopeid 0x20<link>
ether fe:54:00:e8:b2:b6 txqueuelen 1000 (Ethernet)
RX packets 118 bytes 9378 (9.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3140 bytes 166973 (163.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@linux-node1 ~]# iptables -t nat -vnL
Chain PREROUTING (policy ACCEPT 211 packets, 16603 bytes)
pkts bytes target prot opt in out source destination
Chain INPUT (policy ACCEPT 26 packets, 2543 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 176 packets, 13692 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 176 packets, 13692 bytes)
pkts bytes target prot opt in out source destination
0 0 RETURN all -- * * 192.168.122.0/24 224.0.0.0/24
0 0 RETURN all -- * * 192.168.122.0/24 255.255.255.255
0 0 MASQUERADE tcp -- * * 192.168.122.0/24 !192.168.122.0/24 masq ports: 1024-65535
185 14060 MASQUERADE udp -- * * 192.168.122.0/24 !192.168.122.0/24 masq ports: 1024-65535
0 0 MASQUERADE all -- * * 192.168.122.0/24 !192.168.122.0/24
2、修改网卡
注意:这个最好是用脚本执行
brctl addbr br0 ##添加网卡 brctl addif br0 eth0 ##绑定br0到eth0 ip addr del dev eth0 192.168.1.110/24 # ifconfig br0 192.168.1.110/24 up # route add default gw 192.168.1.2 #绑定网关
3、查看修改后的网卡信息
[root@linux-node1 ~]# brctl show bridge name bridge id STP enabled interfaces virbr0 8000.5254000cd692 yes virbr0-nic
这里 eth0的IP转到了br0上。
4、如果修改虚拟机的默认网卡信息
virsh edit CentOS7 ##编辑配置文件
5、重启虚拟机
如果无法关闭虚拟机,就强制关闭
[root@linux-node1 ~]# virsh edit CentOS7 Domain CentOS7 XML configuration edited. [root@linux-node1 ~]# virsh shutdown CentOS7 Domain CentOS7 is being shutdown [root@linux-node1 ~]# virsh start CentOS7 error: Domain is already active
6、vnc进入虚拟机修改网卡信息
7、测试网络
8、如果此处无法ping通百度,记住查看下dns设置
9、xshell连接验证