LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-10-2023, 10:02 PM   #1
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,612

Rep: Reputation: 180Reputation: 180
iptables redirect port connection to different host:port


Our organization has a Sonicwall firewall which forwards certain ports to a LAN Linux host which does routing/port forwarding tasks via uptables. For several years the Sonicwall has forwarded e.g. port 1912 to this Linux host, named MAIL. The iptables config to accomplish that is:
Code:
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 1912 -j DNAT --to-destination 192.168.0.62:3389
iptables -A FORWARD -i eth1 -d 192.168.0.62 -p tcp --dport 3389 -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -d 192.168.0.62 -p tcp --dport 3389 -j SNAT --to-source 192.168.0.2
iptables -t nat -A POSTROUTING -o eth1 -d 192.168.0.62 -p tcp --dport 3389 -j SNAT --to-source 192.168.0.2
This config was worked out with help from LQ experts years ago and I don't pretend to understand it all.

Now, I want to restrict forwarding from port 1912 to be enabled only from within the LAN. This does work from a LAN workstation:
Code:
$ telnet mail 1912
Trying 192.168.0.2...
Connected to mail.
Escape character is '^]'.
I deleted the port forwarding rules from the Sonicwall, but unfortunately, the following also still works from a remote computer:
Code:
$ telnet mail.mydom.org 1912
Trying 1.2.3.4 ...
Connected to mail.mydom.org.
Escape character is '^]'.
which tells me that the Sonicwall had nothing to do with it and 1912 requests were routing directly to the MAIL host all along!

Oh well, my question is, how to I modify these iptables rules to only allow this host: port to be accessed from within the LAN and disallow WAN connects?

Last edited by mfoley; 09-10-2023 at 10:05 PM.
 
Old 09-11-2023, 08:37 AM   #2
dc.901
Senior Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 1,005

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Something was obviously routing the traffic; do you have another network device attached to WAN?

Or is it like:
Internet / ISP -> Sonicwall -> your network switch

Personally it helps me tremendously to draw things out on paper...
 
Old 09-11-2023, 01:37 PM   #3
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,612

Original Poster
Rep: Reputation: 180Reputation: 180
Quote:
Originally Posted by dc.901 View Post
Something was obviously routing the traffic; do you have another network device attached to WAN?

Or is it like:
Internet / ISP -> Sonicwall -> your network switch

Personally it helps me tremendously to draw things out on paper...
Yes, as you've shown: Internet / ISP -> Sonicwall -> MAIL host, where MAIL is running iptables with the shown rules.

I'm sure the Sonicwall is out of the loop in this case. Its public IP is ...110 and MAIL's public IP is ...107. I supposed if I had been accessing ...110:1912 it would have routed through the Sonicwall, but as I am accessing ...107:1912 it is certainly bypassing the Sonicwall. All the more reason that the redirect on MAIL should only permit LAN hosts (192.168.0.0/24).

So, the actual "diagram" would be Internet -> MAIL host (...107)

On MAIL I've tried:
Code:
iptables -t nat -A PREROUTING -s 192.168.0.0/24 --protocol tcp --dport 1912 -j DNAT --to-destination 198.162.0.99:3389

$ telnet mail 1912                  # from an0ther LAN host
Trying 192.168.0.2...
telnet: connect to address 192.168.0.2: Connection timed out
This times out after 8 minutes. What am I missing?

Last edited by mfoley; 09-11-2023 at 01:42 PM.
 
Old 09-14-2023, 09:50 AM   #4
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,612

Original Poster
Rep: Reputation: 180Reputation: 180
No ideas on this? LQ experts usually know all about iptables.
 
Old 09-15-2023, 04:08 PM   #5
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,612

Original Poster
Rep: Reputation: 180Reputation: 180
I'm closing this question as I think the initial posts make a relatively simple question too complicated. I've replaced this question by a simpler version: https://www.linuxquestions.org/quest...30#post6453930
 
  


Reply

Tags
iptables, port forwarding



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
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
ssh: connection to host port: 22: Connection timed out lost connection cucolin@ Linux - Server 4 11-22-2011 06:15 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 04:22 PM.

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