LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-15-2023, 04:06 PM   #1
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,634

Rep: Reputation: 182Reputation: 182
iptables redirect port connection to different host:port, continued


I want to route LAN request to host 192.168.0.2:1234 to host 192.168.0.99:4567. I've tried the following iptables rule on host 192.168.0.2:
Code:
iptables -t nat -A PREROUTING -s 192.168.0.0/24 --protocol tcp --dport 1234 -j DNAT --to-destination 198.162.0.99:4567

# (from some host other than 192.168.0.2 ...)

$ telnet 192.168.0.2 1234
Trying 192.168.0.2...
telnet: connect to address 192.168.0.2: Connection timed out
I'm no iptables expert. Maybe I should use the FORWARD table instead or in addition to?

Help appreciated.
 
Old 09-15-2023, 08:24 PM   #2
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,860

Rep: Reputation: 162Reputation: 162
You need to add another rule.
iptables -t nat -A POSTROUTING -p tcp -d 192.168.0.99 --dport 4567 -j SNAT --to-source 192.168.0.2:1234
 
Old 09-25-2023, 09:48 PM   #3
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,634

Original Poster
Rep: Reputation: 182Reputation: 182
Thanks,but still not working. I'm un-obfuscating my IP and ports ... in case that helps. Maybe I'm still doing something wrong:
Code:
iptables -t nat -A PREROUTING -s 192.168.0.0/24 --protocol tcp --dport 1903 -j DNAT --to-destination 198.162.0.4:3389
iptables -t nat -A POSTROUTING -p tcp -d 192.168.0.4 --dport 3389 -j SNAT --to-source 192.168.0.2:1903
Then on LAN host 192.168.0.3:
Code:
$ telnet 192.168.0.2 1903
Trying 192.168.0.2...
telnet: connect to address 192.168.0.2: Connection timed out
If I try directly to 192.168.0.4 from 192.168.0.3 I get connected:
Code:
$ telnet 192.168.0.4 3389
Trying 192.168.0.4...
Connected to 192.168.0.4.
Escape character is '^]'.
 
Old 09-26-2023, 03:02 PM   #4
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,860

Rep: Reputation: 162Reputation: 162
Use tcpdump tool to sniffer packet on 192.168.0.3, 192.168.0.2 and 192.168.0.4 to find out where the packet is wrong. And then you can add more iptable rule.
 
  


Reply

Tags
forwarding, iptables



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] iptables redirect port connection to different host:port mfoley Linux - Networking 4 09-15-2023 04:08 PM
IPtables to map Virtual Host IP Port 22 on same physical host to alternate port edi_corey Linux - Networking 1 05-04-2012 11:08 AM
IPTables port 873 redirect to different IP address jjrowan Linux - Networking 5 11-06-2010 04:18 PM
IPTABLES PORT TRANSLATION / REDIRECT to a different address daveginorge Linux - Newbie 2 05-07-2010 01:59 PM
IPTABLES redirect to a different port on another device on the same internal network. jsurles Linux - Networking 1 04-07-2008 07:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration