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 - 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 12-13-2009, 03:45 AM   #1
zenith1
LQ Newbie
 
Registered: Sep 2005
Posts: 5

Rep: Reputation: 0
iptables: Source address, state and DNAT


I have a stateful firewall, it accepts already established and related connections in INPUT/OUTPUT/FORWARD chains in both ways. The firewall has two interfaces, eth0 - external and eth1 - internal. Next I would like to let web traffic from a certain IP address only to be forwarded (DNAT) to port 8080 on a server on the LAN. I noticed that it is possible to specify a source address in both my PREROUTING rule and in my FORWARD rule.

$SERVER: 192.168.0.2
$SOURCE: 172.16.0.1
Example of working rules:

Code:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination $SERVER:8080

iptables -A FORWARD -i eth0 -o eth1 -p tcp -s $SOURCE --dport 8080 -m state --state NEW -j ACCEPT
Now, in addition to specifying the source address in the FORWARD chain, I could also specify both the source and state in PREROUTING too:


Code:
iptables -t nat -A PREROUTING -i eth0 -p tcp -s $SOURCE --dport 80 -m state --state NEW -j DNAT --to-destination $SERVER:8080

iptables -A FORWARD -i eth0 -o eth1 -p tcp -s $SOURCE --dport 8080 -m state --state NEW -j ACCEPT
The question then boils down to this:

Does it make any sense to specify the source and/or state in the PREROUTING chain too when the filtering itself is done in the FORWARD chain?

I forgot to add that adding the source address in PREROUTING might make sense if you already have a PREROUTING rule for port 80 traffic that is forwarded to a different server or port?

Last edited by zenith1; 12-13-2009 at 04:18 AM.
 
Old 12-13-2009, 05:22 AM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by zenith1 View Post
Does it make any sense to specify the source and/or state in the PREROUTING chain too when the filtering itself is done in the FORWARD chain?
Generally speaking, no. There are of course, some exceptions.

Quote:
I forgot to add that adding the source address in PREROUTING might make sense if you already have a PREROUTING rule for port 80 traffic that is forwarded to a different server or port?
Yes, this would be one of the exceptions I was referring to. Personally, I try to abstain from any filtering in PREROUTING unless absolutely necessary (the first example you posted looks great to me).
 
1 members found this post helpful.
  


Reply



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 -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --set deadeyes Linux - Server 14 07-29-2009 04:30 AM
iptables dnat working, but server logs local source IP instead of original source IP Nothsa Linux - Server 3 02-14-2008 05:34 PM
not work: iptables -I INPUT 5 -m state --state NEW -m tcp -p tcp --dport 3306 -j DROP abefroman Linux - Security 1 07-18-2007 08:19 AM
iptables (changing source address) rickthemick Linux - Networking 12 11-05-2004 07:43 AM
How would i log the source MAC address w/ iptables? phek Linux - Security 12 12-14-2001 12:18 PM

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

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