2

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.5 assigned to my_veth2 and the routing table entry 1.2.3.0/24 to 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?
2
  • You don't specify any interface for tcpdump to capture. Note sure if the default interface chosen by tcpdump is the one where you expect the data. Also, I'm confused of the results you describe: you say that the message sent from the last terminal is printed in the first terminal. But then you say that no tcpdump shows anything. Isn't "Terminal 1" (with the tcpdump) the same as "first terminal"? Maybe be more clear in the naming of the terminals. Commented Nov 24, 2024 at 20:43
  • @SteffenUllrich I just updated the post to be more explicit with the terminals. Also, the problem seems to persist even when specifying the interface to capture. Commented Nov 24, 2024 at 20:55

1 Answer 1

6

ip netns exec does not open a pseudo-terminal for the executed command. In this situation tcpdump will default to buffered output. To observe the transferred data immediately you need to explicitly enable line buffered output with tcpdump -l.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.