This is an old revision of the document!
Overview
How to use network namespaces and ip netns to tie two ports together in order to ping out one port and to the other.
Links:
man ip-netns
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
Basics
List current ns (none)
$ ip netns [list] $
Check for /var/run/netns/.
Add and delete
$ 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 $
Assigning an interface to a namespace
ip link set <device> netns <namespace>
So:
$ sudo ip link set enp0s20f0u5u1 netns ns1
netdev mailing list
Andrew Lunn
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.
Willy Tarreau
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.