Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 17104  / 2 Years ago, thu, march 17, 2022, 12:31:22

I have the following listening PORT:IP set up on my UBuntu server.



12.345.67.890:3636


It receives requests perfectly, however, I would now like to forward any requests to that IP:PORT to another IP:PORT, i.e.:



09.876.54.321:3636


Essentially I want to do a request forward 12.345.67.890:3636 -> 09.876.54.321:3636.



How can I go about it in Terminal and if I wanted to change it back how can I go about that too? Is there also a way to test that the data is forwarding and it is setup properly?



Thanks!



Edit: Can I just do as follows, just wondering how I would go about testing it and how I could disable it?



sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp --dport 3636 -j DNAT --to-destination 09.876.54.321:3636
iptables -t nat -A POSTROUTING -j MASQUERADE

More From » networking

 Answers
2

The commands in your question are enough to enable routing and forward 12.345.67.890:3636 to 09.876.54.321:3636.






Use iptables' LOG target to monitor what is happening:



iptables -I FORWARD -j LOG


You should see something like this in /var/log/syslog:



Aug 19 08:43:23 hostname kernel: [190951.964227] IN=eth0 OUT=eth0 SRC=11.22.33.44 DST=09.876.54.321 LEN=40 TOS=0x00 PREC=0x00 TTL=64 ID=51600 DF PROTO=TCP SPT=41960 DPT=3636 WINDOW=246 RES=0x00 ACK URGP=0



  • SRC: Source IP address

  • DST: Destination IP address

  • SPT: Source port

  • DPT: Destination port






Flush iptables rules to clean up everything:



iptables -F

[#23579] Friday, March 18, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gigglcept

Total Points: 113
Total Questions: 105
Total Answers: 125

Location: Christmas Island
Member since Wed, Jan 13, 2021
3 Years ago
;