All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Newkirk <netfilter@newkirk.us>
To: "Mcminn, Matt 8869" <melfinadev@chartermi.net>,
	netfilter@lists.netfilter.org
Subject: Re: iptables and port mapping
Date: Mon, 10 Mar 2003 02:57:44 -0500	[thread overview]
Message-ID: <200303100257.44740.netfilter@newkirk.us> (raw)
In-Reply-To: <web-117748330@back2.chartermi.net>

On Monday 10 March 2003 01:05 am, Mcminn, Matt 8869 wrote:

> What I want to do is map port 80 on the external interface
> (eth0) to port 80 on my internal (eth1) 192.168.0.2 ip
> address.  So what I thought would do this is:
>
> iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j
> DNAT --to 192.168.0.2
> iptables -I INPUT -d 192.168.0.0/32 -j ACCEPT

First part is right, second is wrong.  Once you DNAT it, it is no longer 
destined for the machine running iptables, so it goes to FORWARD chain, 
not INPUT chain.  (also you have problems with that rule's construction: 
using "-I" you should specify a rule number to insert before, like "-I 
INPUT 4" to make it the 4th rule, plus your /32 mask will only match 
that single IP...)  Just change your second rule to:

iptables -A FORWARD -d 192.168.0.2 -p tcp --dport 80 -j ACCEPT

and the request will reach the local server.  Getting the reply traffic 
back out is a separate issue in FORWARD.  If you don't already have 
outbound traffic ACCEPTed, you'd need something like one of these:

iptables -A FORWARD -s 192.168.0.2 -p tcp --sport 80 -j ACCEPT
or
iptables -A FORWARD -s 192.168.0.2 -m state --state    \
ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -d 192.168.0.2 -m state --state    \
ESTABLISHED,RELATED -j ACCEPT

The second pair (using the state match) is preferable, since they will 
also allow ICMP traffic related to the HTTP connection.  If you already 
have connectivity from the local machines through this box to the 
internet then you probably don't need anything for outbound replies.  
Also, the state pair is subsumed in the more general rule:

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

which is commonly used to allow those two states to pass the FORWARD 
chain in any direction.

j



      reply	other threads:[~2003-03-10  7:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-10  6:05 iptables and port mapping Mcminn, Matt 8869
2003-03-10  7:57 ` Joel Newkirk [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200303100257.44740.netfilter@newkirk.us \
    --to=netfilter@newkirk.us \
    --cc=melfinadev@chartermi.net \
    --cc=netfilter@lists.netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.