#StackBounty: #linux #networking #socat socat sending from the wrong IP address

Bounty: 50

I am using socat to forward UDP traffic from one port to another with the following command:

socat -T5 UDP4-LISTEN:12345,reuseaddr,fork UDP4:,bind=,so-bindtodevice=lo

Using netcat to test this, I ran nc -u -l -p 23456 -vv and echo test | nc -u 12345. This gave me the following unexpected output:

listening on [any] 23456 ...
connect to [<myPublicIp>] from <hostname> [<myPublicIp>] 53995

Instead of seeing <myPublicIp> as the source address, I would have expected to see Am I misunderstanding something about networking, or am I using socat incorrectly?

The affected server is running Debian 10, Linux kernel version is 4.19.0-13-amd64, socat version is

When using TCP, the output is slightly different:

listening on [any] 23456 ...
connect to [] from <hostname> [<myPublicIp>] 48520

As requested, the relevant output of netstat -aun

Proto Recv-Q Send-Q Local Address           Foreign Address         State  
udp        0      0 *
udp        0      0 <myPublicIp>:23456      <myPublicIp>:54299      ESTABLISHED
udp        0      0         ESTABLISHED

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.