内容目录
网络拓扑
添加 ns
ip netns add ns1
ip netns add ns2
添加 tunnel
ip netns exec ns1 ip tunnel add tun1 mode ipip remote 10.10.20.2 local 10.10.10.2
ip netns exec ns1 ip l s tun1 up
ip netns exec ns1 ip a a 10.10.100.10 peer 10.10.200.10 dev tun1
ip netns exec ns2 ip tunnel add tun2 mode ipip remote 10.10.10.2 local 10.10.20.2
ip netns exec ns2 ip l s tun2 up
ip netns exec ns2 ip a a 10.10.200.10 peer 10.10.100.10 dev tun2
开启 ip_forward
echo 1 > /proc/sys/net/ipv4/ip_forward
设置veth pair
ip link add v1 type veth peer name v1_p
ip link add v2 type veth peer name v2_p
ip link set v1 netns ns1
ip link set v2 netns ns2
ip addr add 10.10.10.1/24 dev v1_p
ip l s v1_p up
ip addr add 10.10.20.1/24 dev v2_p
ip l s v2_p up
ip netns exec ns1 ip addr add 10.10.10.2/24 dev v1
ip netns exec ns1 ip link set v1 up
ip netns exec ns2 ip addr add 10.10.20.2/24 dev v2
ip netns exec ns2 ip link set v2 up
添加路由
ip netns exec ns1 route -n
ip netns exec ns1 route add -net 10.10.20.0 netmask 255.255.255.0 gw 10.10.10.1
ip netns exec ns1 route -n
ip netns exec ns2 route add -net 10.10.10.0 netmask 255.255.255.0 gw 10.10.20.1
报文封装
测试
ip netns exec ns1 ping 10.10.200.10 -c 1
tcpdump -i v1_p -w ipip