ns1–(veth)–host71----(物理网络)----host72–(veth)–ns1
配置host71:
//新建ovs 交换机br-tun
ovs-vsctl add-br br-tun
ip link set br-tun up
ovs-vsctl add-port br-tun vxlan0 – set interface vxlan0 type=vxlan options:remote_ip=192.168.181.72 options:key=100
//新建一对veth
ip link add veth1-0 type veth peer name veth1-1
//新建一个namespace ns1,并绑veth1-1
ip netns add ns1
ip link set veth1-1 netns ns1
ip netns exec ns1 ip link set veth1-1 up
ip netns exec ns1 ip add add 192.168.100.71/24 dev veth1-1
//veth1-0绑到br-tun交换机
ip link set veth1-0 up
ovs-vsctl add-port br-tun veth1-0
同样配置host72:
ovs-vsctl add-br br-tun
ip link set br-tun up
ovs-vsctl add-port br-tun vxlan0 – set interface vxlan0 type=vxlan options:remote_ip=192.168.181.71 options:key=100
ip link add veth1-0 type veth peer name veth1-1
ip netns add ns1
ip link set veth1-1 netns ns1
ip netns exec ns1 ip link set veth1-1 up
ip netns exec ns1 ip add add 192.168.100.72/24 dev veth1-1
ip link set veth1-0 up
ovs-vsctl add-port br-tun veth1-0
测试并抓包
host71-ns1 ping host72-ns2:
ip netns exec ns1 ping 192.168.100.72
PING 192.168.100.72 (192.168.100.72) 56(84) bytes of data.
64 bytes from 192.168.100.72: icmp_seq=1 ttl=64 time=2.09 ms