TL;DR. You first create a network namesmace (netns
), and a veth
device
(you also create a peer). Then you assign one end to another netns.
You can talk to another netns via the veth.
TODO: How to use a different device instead of veth for communication across netns?
ip netns add ns1
ip netns exec ns1 ...
ip netns exec ns1 ip link add veth1 type veth peer name veth2
ip link set veth2 netns ns2
You can also create veth in the default (or global) netns.
ip addr add 192.168.1.1/24 dev veth1
ip netns exec ns2 ip addr add 192.168.1.100/24 dev veth2
ping 192.168.1.100 # or
ip netns exec ns2 ping add 192.168.1.1
Send ping to the IP address of the peer (that is assigned within another netns).