Skip to content

Instantly share code, notes, and snippets.

@flashvoid
Last active October 14, 2015 17:27
Show Gist options
  • Save flashvoid/7bcc7c7813114e1bd238 to your computer and use it in GitHub Desktop.
Save flashvoid/7bcc7c7813114e1bd238 to your computer and use it in GitHub Desktop.
linux network namespace routing
ip netns add space-a
ip netns add space-b
ip link add veth0 type veth peer name veth1
ip link set veth1 netns space-a
ip link add veth2 type veth peer name veth3
ip link set veth3 netns space-b
ifconfig veth0 0.0.0.0 up
ifconfig veth2 0.0.0.0 up
ip netns exec space-a ifconfig veth1 192.168.1.130/32 up
ip netns exec space-a route add -host 192.168.7.141 dev veth1
ip netns exec space-a route add -net 192.168.1.0/24 gw 192.168.7.141
ip netns exec space-b ifconfig veth3 192.168.1.131/32 up
ip netns exec space-b route add -host 192.168.7.141 dev veth3
ip netns exec space-b route add -net 192.168.1.0/24 gw 192.168.7.141
route add -host 192.168.1.130 dev veth0
route add -host 192.168.1.131 dev veth2
ping 192.168.1.130
PING 192.168.1.130 (192.168.1.130) 56(84) bytes of data.
64 bytes from 192.168.1.130: icmp_seq=1 ttl=64 time=0.154 ms
^C
--- 192.168.1.130 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.154/0.154/0.154/0.000 ms
root@tahr:/home/void# ping 192.168.1.131
PING 192.168.1.131 (192.168.1.131) 56(84) bytes of data.
64 bytes from 192.168.1.131: icmp_seq=1 ttl=64 time=0.143 ms
^C
--- 192.168.1.131 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.143/0.143/0.143/0.000 ms
root@tahr:/home/void# ip netns exec space-a ping 192.168.1.131
PING 192.168.1.131 (192.168.1.131) 56(84) bytes of data.
64 bytes from 192.168.1.131: icmp_seq=1 ttl=63 time=0.103 ms
^C
--- 192.168.1.131 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.103/0.103/0.103/0.000 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment