LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-25-2019, 07:23 PM   #16
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,536

Rep: Reputation: Disabled

Quote:
Originally Posted by mfoley View Post
Then I run tcpdump for port 1912 on the 192.168.0.2 host and attempt to telnet from the outside computer. On 192.168.0.2 I get:
Code:
> tcpdump -tttt -l port 1912
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes
2019-03-25 11:57:20.683569 IP cpe-184-57-114-221.columbus.res.rr.com.45850 > mail.hprs.local.1912: Flags [S], seq 258769081, win 29200, options [mss 1460,sackOK,TS val 2524738611 ecr 0,nop,wscale 7], length 0
:
repeated
:
Change the tcpdump command to:
Code:
tcpdump -tttt -l -i eth1 tcp port 1912 or tcp port 3389
You need to ascertain whether or not 192.168.0.2 is actually NATing and forwarding the packet, and if so, what the transmitted packet looks like.
 
Old 03-26-2019, 03:21 AM   #17
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 1,591

Original Poster
Rep: Reputation: 128Reputation: 128
Did as you suggested:
Code:
> tcpdump -tttt -ln -i eth1 tcp port 1912 or tcp port 3389
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes
2019-03-26 04:17:38.242129 IP 184.57.114.221.62961 > 192.168.0.2.1912: Flags [S], seq 3350291930, win 8192, options [mss 1460,nop,wscale 2,nop,nop,sackOK], length 0
2019-03-26 04:17:38.242153 IP 184.57.114.221.62961 > 192.168.0.58.3389: Flags [S], seq 3350291930, win 8192, options [mss 1460,nop,wscale 2,nop,nop,sackOK], length 0
2019-03-26 04:17:41.247176 IP 184.57.114.221.62961 > 192.168.0.2.1912: Flags [S], seq 3350291930, win 8192, options [mss 1460,nop,wscale 2,nop,nop,sackOK], length 0
2019-03-26 04:17:41.247187 IP 184.57.114.221.62961 > 192.168.0.58.3389: Flags [S], seq 3350291930, win 8192, options [mss 1460,nop,wscale 2,nop,nop,sackOK], length 0
2019-03-26 04:17:47.246120 IP 184.57.114.221.62961 > 192.168.0.2.1912: Flags [S], seq 3350291930, win 8192, options [mss 1460,nop,nop,sackOK], length 0
2019-03-26 04:17:47.246147 IP 184.57.114.221.62961 > 192.168.0.58.3389: Flags [S], seq 3350291930, win 8192, options [mss 1460,nop,nop,sackOK], length 0
At that point, connection fails on the remote. It appears that the remote (184.57.114.221) is being routed to port 3389 on the Windows computer (2nd output line, above), but still no connection. I've turned off the firewall on the Windows computer.
 
Old 03-26-2019, 05:52 AM   #18
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,536

Rep: Reputation: Disabled
Quote:
Originally Posted by mfoley View Post
Did as you suggested:
Code:
> tcpdump -tttt -ln -i eth1 tcp port 1912 or tcp port 3389
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes
2019-03-26 04:17:38.242129 IP 184.57.114.221.62961 > 192.168.0.2.1912: Flags [S], seq 3350291930, win 8192, options [mss 1460,nop,wscale 2,nop,nop,sackOK], length 0
2019-03-26 04:17:38.242153 IP 184.57.114.221.62961 > 192.168.0.58.3389: Flags [S], seq 3350291930, win 8192, options [mss 1460,nop,wscale 2,nop,nop,sackOK], length 0
As you can see, the outgoing packet to 192.168.0.58:3389 still has the original source address (187.57.114.221). That means the Windows computer won't be routing its relpies through 192.168.0.2, but rather use the default gateway (the SonicWall) which, since it's not expecting replies from 192.168.0.58, will just drop the packets.

The POSTROUTING rule isn't catching packets from external hosts going to the Windows system, since it was only designed to handle the 2nd hairpin scenario (local PCs connecting to the Windows host via 192.168.0.2). Try adding this rule:
Code:
iptables -t nat -A POSTROUTING -o eth1 -d 192.168.0.58 -p tcp --dport 3389 -j SNAT --to-source 192.168.0.2
tcpdump should then show packets exiting eth1 with a source address of 192.168.0.2. The connection from the external host might even work.
 
1 members found this post helpful.
Old 03-26-2019, 09:31 PM   #19
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 1,591

Original Poster
Rep: Reputation: 128Reputation: 128
Holy Firewall, Batman! That worked! You're a genius! I'll have to study this some more and incorporate it with my existing firewall, and route the other workstations in the same way.

To recap for the benefit of others: I want to do this because the new Sonicwall firewall/router/gateway apparently does not alert or counter-measure on brute-force attempts on RDP and VNC ports. I'm not certain they do so for their VPN either. I'm discussing this on the Sonicall forum. My 192.168.0.2 server has a counter-measure script to detect and block such attacks. Hence this thread.

As a stripped-down iptables script, I've ended up with the following:
Code:
# Flush existing ruleset:
iptables -F
iptables -t nat -F

# Set reasonable policy defaults (that is, these are "reasonable" for an exposed firewall; you
# may decide that an input policy of ACCEPT is, well, acceptable in this particular scenario):

# iptables -P INPUT DROP
# iptables -P FORWARD DROP
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

# You really don't want to stop loopback traffic with a DROP policy:

iptables -A INPUT -i lo -j ACCEPT

# Allow existing sessions for both local and routed traffic:

iptables -A INPUT   -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT

# If the INPUT policy is indeed DROP, add rules for relevant local services here; the example below handles SSH:

# iptables -A INPUT -p tcp --dport 22 -m state --STATE NEW -j ACCEPT

# Forward TCP port 1912 to 192.168.0.58:3389

iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 1912 -j DNAT --to-destination 192.168.0.58:3389

# Allow the forwarded packet through; remember to reference the translated IP address and portnumber, not the NATed ones:

iptables -A FORWARD -i eth1 -d 192.168.0.58 -p tcp --dport 3389 -j ACCEPT

# Preserve return path by NATing behind 192.168.0.2 (eth1):
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -d 192.168.0.58 -p tcp --dport 3389 -j SNAT --to-source 192.168.0.2

# Catch packets from external hosts going to the Windows system
iptables -t nat -A POSTROUTING -o eth1 -d 192.168.0.58 -p tcp --dport 3389 -j SNAT --to-source 192.168.0.2

Last edited by mfoley; 03-26-2019 at 09:33 PM.
 
Old 03-27-2019, 12:10 PM   #20
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 1,591

Original Poster
Rep: Reputation: 128Reputation: 128
Possibly last question. I've configured several of the workstations, Windows, Linux and Mac. All work! This entails 4 iptables lines per workstation:
Code:
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 1912 -j DNAT --to-destination 192.168.0.58:3389
iptables -A FORWARD -i eth1 -d 192.168.0.58 -p tcp --dport 3389 -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -d 192.168.0.58 -p tcp --dport 3389 -j SNAT --to-source 192.168.0.2
iptables -t nat -A POSTROUTING -o eth1 -d 192.168.0.58 -p tcp --dport 3389 -j SNAT --to-source 192.168.0.2
No big deal, but can I consolidate some of these lines? For example, could I:
Code:
iptables -A FORWARD -i eth1 -d 192.168.0.4 -p tcp --dport 3389 -j ACCEPT
iptables -A FORWARD -i eth1 --dst-range 192.168.0.50-192.168.0.53 -p tcp --dport 3389 -j ACCEPT
iptables -A FORWARD -i eth1 --dst-range 192.168.0.55-192.168.0.60 -p tcp --dport 3389 -j ACCEPT
iptables -A FORWARD -i eth1 --dst-range 192.168.0.61-192.168.0.63 -p tcp --dport 5900 -j ACCEPT

# and likewise:
iptables -t nat -A POSTROUTING -o eth1 --dst-range 192.168.0.50-192.168.0.53 -p tcp --dport 3389 -j SNAT --to-source 192.168.0.2
:
Not sure about trying this "live" as I am remote. Feedback appreciated.

Unfortunately, my 5900 redirects and 3389 redirects are interspersed, so I don't have clean ip ranges, but that's a task for another day.
 
  


Reply

Tags
iptables, port forwarding


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 : ssh port forwarding one port to another port issue routers Linux - Networking 7 08-07-2018 08:41 AM
[SOLVED] iptables port forward not working for port range mapping to anohter Port range in Linux 2.6.39 kinghong66 Linux - Networking 2 06-17-2015 07:17 PM
Shorewall: port forwarding problem, port is closed even after forwarding Synt4x_3rr0r Linux - Networking 2 12-13-2009 04:36 PM
IPCHAINS port forwarding and IPTABLES port forwarding ediestajr Linux - Networking 26 01-14-2007 07:35 PM
Port forwarding with iptables is not working?!! philipina Linux - Networking 1 04-03-2004 03:18 PM

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

All times are GMT -5. The time now is 05:24 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration