This is an old revision of the document!


NAME
       ip-netns - process network namespace management

SYNOPSIS
       ip [ OPTIONS ] netns  { COMMAND | help }
       ip netns [ list ]
       ip netns add NETNSNAME
       ip [-all] netns del [ NETNSNAME ]
       ip netns set NETNSNAME NETNSID
       ip netns identify [ PID ]
       ip netns pids NETNSNAME
       ip [-all] netns exec [ NETNSNAME ] command...
       ip netns monitor
       ip netns list-id

List current ns (none)

$ ip netns [list]
$

Check for /var/run/netns/.

$ sudo ip netns add ns1
$ sudo ip netns add ns1
$ ip netns list
ns2
ns1
$

Also:

$ tree /var/run/netns
/var/run/netns
├── ns1
└── ns2

0 directories, 2 files
$
ip link set <device> netns <namespace>

So:

$ sudo ip link set enp0s20f0u5u1 netns ns1
Namespaces is a good solution. Something like this should work:

ip netns add ns1
ip netns add ns2

ip link set eth1 netns ns1
ip link set eth2 netns ns2

ip netns exec ns1 \
        ip addr add 10.42.42.42/24 dev eth1

ip netns exec ns1 \
        ip link set eth1 up

ip netns exec ns2 \
        ip addr add 10.42.42.24/24 dev eth2

ip netns exec ns2 \
        ip link set eth2 up

ip netns exec ns1 \
        ping 10.42.42.24

You might also want to consider iperf3 for stress testing, depending
on the sort of stress you need.
FWIW I have a setup somewhere involving ip rule + ip route which achieves
the same without involving namespaces. It's a bit hackish but sometimes
convenient. I can dig if someone is interested.
  • network_namespaces.1534683234.txt.gz
  • Last modified: 2018/08/19 12:53
  • by rpjday