I’d like to set up my OpenWRT router to transparently relay UDP packets it receives from WAN on a specified port to a remote server (also on WAN, with a fixed UDP listening port), and similarly return the packets from that remote server’s replies back to the client who initiated the session.
So the flow should be something like this:
- Client sends a UDP packet to the Router’s WAN IP address, port 12345
- Router records the client’s public IP address and port, rewrites the source IP address in the packet to its own WAN IP address and sends it to the Server, port 23456
- Server responds with a UDP packet to the Router’s WAN IP address, at the port number the Router used for sending the previous UDP packet in this session
- Router recalls which Client IP and port last sent it those UDP packets which exited from this particular outbound port, rewrites the source IP address in the packet to its own WAN IP address and sends it to the respective Client
So the router should act pretty much like a NAT gateway with masquerading, but only for a single “upstream” server and port, and the clients behind this NAT should be identified not by the network interface where their traffic shows up but by the WAN UDP port number where they sent the packets.
What is the right way to configure that, if at all possible?