On a Linux box, I have a program that, among other things, sends UDP packets to a "private" IP address. I want to rewrite these packets to have a different destination IP address, without affecting the source/destination UDP ports, and without modifying the program itself.
Client sends:
192.168.1:138→234.56.138(with192.168.1inside UDP data)Server receives:
12.3.45:138→234.5.6:138(with192.168.1inside UDP data)Server sends reply:
234.5.6:138→192.168.1:138I want it to be:
234.5.6:138→12.3.45:138
The only thing that comes to mind is iptables -t nat -I OUTPUT --dest 192.168.1.0/24 -j DNAT --to-dest <real-address>, but while it does adjust the destination IP address, it also changes the UDP source port, so the packets get rejected by the receiver.
- After DNAT:
234.5.6:1→12.3.45:138– source port changed, router rejects
Background: Said program is Samba 4, which receives NetBIOS datagrams from a client running behind a NAT. The incoming datagrams have the client's "private" IP address in their NetBIOS header, and Samba always replies to that "private" address", instead of using the source address:port of the UDP packet.
- (client
192.168.1) ⇆ (192.168.254router12.3.45) ⇆ internet ⇆ (234.5.6server)
Any ideas? (If it's impossible, I'll just fire up a VPN, but it would be interesting to make this work.)