I am working on a router between an external radio/modem and my device, where the router makes a dial-up connection using the ppp protocol to the radio and sets an iptables rules between the received radio IP and my device's IP.
I have the following routes:
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1000.101 0.0.0.0 UG 0 0 0 ppp0
192.168.100.101 * 255.255.255.255 UH 0 0 0 ppp0
192.168.164.0 * 255.255.255.0 U 0 0 0 eth0
And here are my following iptables rules:
iptables -A INPUT -j ACCEPT
iptables -A OUTPUT -j ACCEPT
iptables -A FORWARD -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -t nat -A PREROUTING -i ppp0 -p tcp -j DNAT --to 192.168.0.110
iptables -t nat -A PREROUTING -i ppp0 -p udp -j DNAT --to 192.168.0.110
iptables -t nat -A POSTROUTING --source 0/0 -o ppp0 -j MASQUERADE
With these rules I can access everything on my device like telnet, web server and some other communications using high ports.
My problem is that I need to connect to my device using a source port with a destination port, and this is not a problem, but my device needs to respond using another port it created for this communication to continue.
For example, I try to make a connection using source port 2000 with destination port 2001 and my device's response returns using source port 21550 and destination port 2000. But the response don't get back to the client connected to the other side of the radio.
By using tcpdump inside my router I saw the device response, but I couldn't figure out how to handle this port changes in the iptables rules to send it back to the client connected to the other side of the radio.
Any help will be greatly appreciated!