LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 07-12-2006, 02:02 PM   #1
Kvetch
Member
 
Registered: Mar 2004
Posts: 35

Rep: Reputation: 15
Iptables routing question


Hello, my Linksys router is running OpenWRT and I am trying to tweak the iptables rules and had a question about how to do some forwarding and routing. I want to open SSH on the router but I want WAN ssh access to be forwarded to a box behind the router/firewall but I want boxes behind the router/firewall to be able to SSH into the router. So this way outside SSH access gets forwarded to a box behind my router and all systems behind the router have the ability to ssh directly into the router. Would this be the correct iptables rules for this or would this forward any ssh traffic from inside to 192.168.1.1 and not go outside if I was trying to ssh to a box outside my network?

Code:
  iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 22-j DNAT --to 192.168.1.4
  iptables -A forwarding_rule -i $WAN -p tcp --dport 22-d 192.168.1.4 -j ACCEPT

  iptables -t nat -A prerouting_rule -i $LAN -p tcp --dport 22-j DNAT --to 192.168.1.1
  iptables -A forwarding_rule -i $LAN -p tcp --dport 22-d 192.168.1.1 -j ACCEPT

Thanks,
Nick
 
Old 07-12-2006, 07:20 PM   #2
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Rep: Reputation: 69
The first 2 rules looks pretty much alright, except for a few typos (looks like you are missing some spaces in front of the -d and -j options, so they would look like:
Code:
iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 22 -j DNAT --to 192.168.1.4
  iptables -A forwarding_rule -i $WAN -p tcp --dport 22 -d 192.168.1.4 -j ACCEPT
I believe that the second set of rules are going to be unnecessary and will definitely cause problems. First, if you DNAT all SSH traffic coming in the LAN interface, then the replies to your clients outside the LAN are going to get DNATed to the router instead (so reply packets would never be able to get back out of the LAN). Second, when SSHing from the LAN directly into the router, you will not need to DNAT that traffic to the IP of the WAN interface. As long as SSHd is listening on all interfaces (which is the default config and netstat will show ::, then you would not need to forward it from the LAN interface to the WAN interface. It will simply accept the connection on the LAN interface. Also, iptables has the ability to un-DNAT the connection using it's state/connection tracking mechanism so the outbound DNAT is unnecessary.

However, you will need to do some kind of SNAT, otherwise traffic from inside then LAN to remote clients will have IANA-reserved source IPs (192.168.) when they leave the router and likely won't reach the client (even if it did, the client won't know where to send the reply).

If you need more help, make sure to post the entire firewall script (after scrubbing any identifiable IPs).
 
  


Reply


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
iptables multiple subnets routing question azdruid Linux - Networking 1 06-28-2006 09:05 AM
routing by iptables ali_dd15 Linux - Networking 14 10-14-2005 05:38 AM
iptables routing CJ_Grobler Linux - Security 1 06-14-2005 02:13 AM
Routing with iptables logo Linux - Networking 4 11-01-2004 06:21 AM
More Help routing with iptables LAR12345 Linux - Networking 2 02-02-2003 10:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 03:16 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