I'm using a fresh minimal Ubuntu server 24.04.1 LTS install. I run these commands as root to set up networking and do some experiments:
If you have seen this post, it's the same setup but with the ip address
2.3.4.5assigned tomy_veth2and the routing table entry1.2.3.0/24to make sure data can be sent and received from each network namespace.
# Terminal 1
apt install -y netcat-traditional tcpdump
ip netns add ns1
ip netns add ns2
ip link add my_veth1 type veth peer name my_veth2
ip link set my_veth1 up netns ns1
ip link set my_veth2 up netns ns2
ip -n ns1 address add 1.2.3.4 dev my_veth1
ip -n ns1 route add 2.3.4.0/24 dev my_veth1
ip -n ns2 address add 2.3.4.5 dev my_veth2
ip -n ns2 route add 1.2.3.0/24 dev my_veth2
ip netns exec ns2 nc -l -p 8080
then I open 2 more terminals to run tcpdump in each network namespace:
# Terminal 2
ip netns exec ns1 tcpdump -i my_veth1
# Terminal 3
ip netns exec ns2 tcpdump -i my_veth2
then I open one more last terminal to send data to the netcat server in ns2 from ns1:
# Terminal 4
ip netns exec ns1 nc 2.3.4.5 8080 <<< 'Hello world from network namespace ns1'
Results:
- The message sent from Terminal 4 is printed in Terminal 1, as expected.
- No packets are being shown in either tcpdump. WHY?