virsh console vm1 ifconfig lo up ifconfig ens3 192.168.1.2/24 up ifconfig ens3
ns1 - eth0 网络配置
1 2 3
ip netns exec ns1 ifconfig lo up ip netns exec ns1 ifconfig eth0 192.168.1.1/24 up ip netns exec ns1 ifconfig eth0
vm2 –> br1 –> ns1
vm2 - ens3 网络配置
1 2 3 4
virsh console vm2 ifconfig lo up ifconfig ens3 172.168.10.2/24 up ifconfig ens3
ns1 - eth1 网络配置
1 2
ip netns exec ns1 ifconfig eth1 172.168.10.1/24 up ip netns exec ns1 ifconfig eth1
为虚拟机指定路由
1 2 3 4 5 6 7 8 9
# vm1: virsh console vm1 ping 192.168.1.1 -c 1 ip route add default via 192.168.1.1
# vm2: virsh console vm2 ping 172.168.10.1 -c 1 ip route add default via 172.168.10.1
连通性测试
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
ping 192.168.1.2 -c5 -R PING 192.168.1.2 (192.168.1.2) 56(124) bytes of data. 64 bytes from 192.168.1.2: icmp_seq=1 ttl=63 time=0.609 ms RR: 172.168.10.2 192.168.1.1 192.168.1.2 192.168.1.2 172.168.10.1 172.168.10.2
64 bytes from 192.168.1.2: icmp_seq=2 ttl=63 time=0.715 ms (same route) 64 bytes from 192.168.1.2: icmp_seq=3 ttl=63 time=0.925 ms (same route) 64 bytes from 192.168.1.2: icmp_seq=4 ttl=63 time=0.880 ms (same route) 64 bytes from 192.168.1.2: icmp_seq=5 ttl=63 time=0.826 ms (same route)
--- 192.168.1.2 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4008ms rtt min/avg/max/mdev = 0.609/0.791/0.925/0.114 ms