1. 程式人生 > >KVM系列-網絡管理

KVM系列-網絡管理

route turn ive in out config cli oca queue cti

網絡管理

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連接驗證

技術分享圖片

KVM系列-網絡管理