Linux: Network Namespaces

sudo ip netns add blue
sudo ip netns add red
 
sudo ifconfig ens2f0 up
sudo ifconfig ens2f1 up
 
sudo ip link set dev ens2f0 netns blue
sudo ip link set dev ens2f1 netns red
 
sudo ip netns exec blue ifconfig ens2f0 10.1.1.1/24 up
sudo ip netns exec blue ifconfig lo up # bring up Loopback
sudo ip netns exec red ifconfig ens2f1 10.1.1.2/24 up
sudo ip netns exec red ifconfig lo up # bring up Loopback
 
# showing the current config (needs to be executed in the relevant namespace)
 
sudo ip netns exec blue ifconfig
sudo ip netns exec red ifconfig
 
sudo ip netns exec red ping 10.1.1.1
sudo ip netns exec red ping 10.1.1.2
sudo ip netns exec blue ping 10.1.1.2
 
sudo ip netns exec blue iperf -s -p 8001
sudo ip netns exec red iperf -c 10.1.1.1 -p 8001 -t 10 -i 2

Simulation