虛擬化網絡技術
阿新 • • 發佈:2018-11-07
ould ket prot troy 空間配置 ces end 20.23 4.3 虛擬化網絡工具:
創建物理橋: 1 virsh命令 virsh iface-bridge eth0 br0 2 /etc/sysconfig/network-scripts/ 編輯配置文件方式: [root@www08:26:15network-scripts]#cat ifcfg-eth0 DEVICE=eth0 #IPADDR=172.20.23.30 #NETMASK=255.255.0.0 #GATEWAY=172.20.0.1 #DNS1=114.114.114.114 #DNS2=8.8.8.8 BRIDGE=br0 [root@www08:26:42network-scripts]#cat ifcfg-br0 DEVICE=br0 TYPE=Bridge IPADDR=172.20.23.30 NETMASK=255.255.0.0 GATEWAY=172.20.0.1 DNS1=114.114.114.114 DNS2=172.20.0.1 BOOTPROTO=none ONBOOT=yes 重啟網絡服務~
virsh和網絡相關的命令: [root@www14:09:43~]#virsh help network Networking (help keyword ‘network‘): net-autostart net-create net-define 創建網絡 net-destroy net-dhcp-leases net-dumpxml 查看網橋創建配置文件 net-edit net-event net-info net-list 查看網橋列表 net-name net-start net-undefine 刪除網橋 net-update net-uuid 如何創建一個虛擬網絡: [root@www19:48:51networks]#cat mynet0.xml <!-- WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE OVERWRITTEN AND LOST. Changes to this xml configuration should be made using: virsh net-edit default or other application using the libvirt API. <forward mode=‘nat‘/> --> <network> <name>mynet0</name> <uuid>72c15a3e-89ab-4d2c-819b-841342262eb1</uuid> <bridge name=‘mybr1‘ stp=‘on‘ delay=‘0‘/> <mac address=‘52:54:00:d7:ee:54‘/> <ip address=‘192.168.24.3‘ netmask=‘255.255.255.0‘> <dhcp> <range start=‘192.168.24.10‘ end=‘192.168.24.100‘/> </dhcp> </ip> </network> [root@www19:52:19networks]#virsh net-create ./mynet0.xml Network mynet0 created from ./mynet0.xml 拆除之前mybr0的接口: brctl delif mybr0 eth1 查看拆除結果: [root@www19:56:07networks]#brctl show bridge name bridge id STP enabled interfaces br0 8000.000c2970f727 yes eth0 mybr0 8000.000000000000 yes 將接口添加至mybr1: [root@www19:56:17networks]#brctl addif mybr1 eth1 [root@www19:57:07networks]#brctl show bridge name bridge id STP enabled interfaces br0 8000.000c2970f727 yes eth0 mybr0 8000.000000000000 yes mybr1 8000.525400d7ee54 yes eth1 mybr1-nic 測試和外面的mybr1鏈接: [root@www19:59:38networks]#ip netns exec r1 ping 192.168.24.3 PING 192.168.24.3 (192.168.24.3) 56(84) bytes of data. 64 bytes from 192.168.24.3: icmp_seq=1 ttl=64 time=0.069 ms 64 bytes from 192.168.24.3: icmp_seq=2 ttl=64 time=0.093 ms 創建一個虛擬機,選擇和 mynet0 在同一網絡!
brctl工具: 來自----bridge-utils包 [root@www14:09:24~]#rpm -qf `which brctl` bridge-utils-1.5-9.el7.x86_64 常見選項: addbr --添加橋設備[軟] delbr --刪除橋設備[硬] addif --給網橋添加接口 delif --網橋中拆除網線 show --查看所有橋信息 stp --開啟生成樹 常見命令: 添加網橋: brctl addbr mybr0 啟用禁用生成樹: brctl stp mybr0 on/off 激活網橋: ip link set [網橋名] up 創建虛擬網卡對: ip link add veth1.1 type veth peer name veth1.2 刪除虛擬網卡對: ip link del veth1.1 查看關聯網卡對: ip link show 更改虛擬網卡名稱: ip link set veth1.1 name eth1 啟用虛擬網卡: ip link set eth1 up ip link set eth2 up 同樣可以激活網橋: ip link set mybr0 up 將網卡關聯至網橋: brctl addif mybr0 eth1 查看結果: [root@www19:26:30~]#brctl show bridge name bridge id STP enabled interfaces br0 8000.000c2970f727 yes eth0 mybr0 8000.82383e8abd07 yes eth1 添加網絡名稱空間: ip netns add r1 查看網絡名稱空間列表: ip netns list 把虛擬網卡設備關聯至網絡名稱空間: ip link set dev eth2 netns r1 查看結果: [root@www19:30:21~]#ip netns exec r1 ifconfig -a eth2: flags=4098<BROADCAST,MULTICAST> mtu 1500 ether fe:46:56:2f:ee:61 txqueuelen 1000 (Ethernet) RX packets 8 bytes 648 (648.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 8 bytes 648 (648.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 網絡名稱空間配置IP: ip netns exec r1 ifconfig eth0 172.20.23.2/16 具體執行: ip netns exec r1 ifconfig eth2 192.168.23.2/24 和r1空間鏈接測試: [root@www19:37:07~]#ping 192.168.23.2 PING 192.168.23.2 (192.168.23.2) 56(84) bytes of data. 64 bytes from 192.168.23.2: icmp_seq=1 ttl=64 time=0.461 ms 64 bytes from 192.168.23.2: icmp_seq=2 ttl=64 time=0.036 ms 如何從虛擬網橋中拆除接口: brctl delif mybr0 eth1 更改網絡名稱空間中的虛擬網卡設備名稱: ip netns exec r1 ip link set dev veth1.2 name eth0
虛擬化網絡技術