Sample Header Ad - 728x90

Why doesn't netcat print anything when listening in UDP mode when it can't reach the client even when the client can reach the server?

3 votes
2 answers
212 views
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:
apt install netcat-traditional

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 netns exec ns2 nc -u -l -p 8080
then I run this from another terminal:
ip netns exec ns1 nc -u 2.3.4.5 8080  ns2 my_veth2 gives the same output

So I tried creating the ARP table entry manually...
sh ip -n ns1 neighbour add 2.3.4.5 dev my_veth1 lladdr $(ip netns exec ns2 cat /sys/class/net/my_veth2/address)
And now apparently the UDP packet is being sent
$ ip netns exec ns1 tcpdump -l -i my_veth1 00:24:15.164245 IP 1.2.3.4.36170 > 2.3.4.5.8080: UDP, length 39
> ns2 my_veth2 gives the same output

However, the first terminal that has the UDP netcat server running still doesn't output anything. Why?

---

**EDIT 3:** After doing all of the above, I tried assigning an IP address to my_veth2:
sh ip -n ns2 address add 2.3.4.5 dev my_veth2
And now, when I send the UDP packet, I get this error in the terminal that is running netcat in listen mode:
sh no connection : Network is unreachable ``` Why? I mean, of course the network is unreachable, but that shouldn't stop the server from receiving and displaying UDP packets. In fact, that error is only displayed when it receives the UDP packet. So even if it knows that it can't answer, it should be able to receive and display the message, right?
Asked by Adrian (249 rep)
Nov 22, 2024, 11:26 PM
Last activity: Nov 26, 2024, 11:33 PM