Linux Netfilter discussions
 help / color / mirror / Atom feed
* Masquerading on local ports
@ 2003-03-20 14:03 Henry Ritzlmayr
  2003-03-20 15:29 ` Rob Sterenborg
  2003-03-21  7:22 ` Joel Newkirk
  0 siblings, 2 replies; 7+ messages in thread
From: Henry Ritzlmayr @ 2003-03-20 14:03 UTC (permalink / raw)
  To: netfilter

Hi everyone - this is my first post to this list - so if anything is
wrong with my way of posting please tell.

And here is the question. How is it possible to nat a lokal port?

IPTABLES -t nat -A PREROUTING -p tcp -d 127.0.0.1 --destination-port 81
-j DNAT --to-destination 127.0.0.1:80

telnet localhost 80  <<< works
telnet localhost 81  <<< Connection refused

Henry







^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Masquerading on local ports
  2003-03-20 14:03 Masquerading on local ports Henry Ritzlmayr
@ 2003-03-20 15:29 ` Rob Sterenborg
  2003-03-20 16:14   ` henry ritzlmayr
  2003-03-20 16:26   ` Henry Ritzlmayr
  2003-03-21  7:22 ` Joel Newkirk
  1 sibling, 2 replies; 7+ messages in thread
From: Rob Sterenborg @ 2003-03-20 15:29 UTC (permalink / raw)
  To: netfilter

> And here is the question. How is it possible to nat a lokal port?
> 
> IPTABLES -t nat -A PREROUTING -p tcp -d 127.0.0.1 
> --destination-port 81 -j DNAT --to-destination 127.0.0.1:80
> 
> telnet localhost 80  <<< works
> telnet localhost 81  <<< Connection refused

iptables -t nat -A PREROUTING -d 127.0.0.1 -p tcp --dport 80 -j REDIRECT
--to-ports 81


Rob



^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Masquerading on local ports
  2003-03-20 15:29 ` Rob Sterenborg
@ 2003-03-20 16:14   ` henry ritzlmayr
  2003-03-20 16:26   ` Henry Ritzlmayr
  1 sibling, 0 replies; 7+ messages in thread
From: henry ritzlmayr @ 2003-03-20 16:14 UTC (permalink / raw)
  To: Netfilter Mailing List

Am Don, 2003-03-20 um 16.29 schrieb Rob Sterenborg:
> > And here is the question. How is it possible to nat a lokal port?
> > 
> > IPTABLES -t nat -A PREROUTING -p tcp -d 127.0.0.1 
> > --destination-port 81 -j DNAT --to-destination 127.0.0.1:80
> > 
> > telnet localhost 80  <<< works
> > telnet localhost 81  <<< Connection refused
> 
> iptables -t nat -A PREROUTING -d 127.0.0.1 -p tcp --dport 80 -j REDIRECT
> --to-ports 81
> 
> 
> Rob

Tanks for the answer,
I tried that one already but it behaves the same.
I also tried 

IPTABLES -t nat -A PREROUTING -p tcp -d 172.16.172.12 --destination-port
81 -j REDIRECT --to-ports 80

wich works perfect for both port 80 and 81 from a foreign host.

Henry



^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Masquerading on local ports
  2003-03-20 15:29 ` Rob Sterenborg
  2003-03-20 16:14   ` henry ritzlmayr
@ 2003-03-20 16:26   ` Henry Ritzlmayr
  2003-03-20 18:34     ` alexb
  1 sibling, 1 reply; 7+ messages in thread
From: Henry Ritzlmayr @ 2003-03-20 16:26 UTC (permalink / raw)
  To: Netfilter Mailing List

Am Don, 2003-03-20 um 16.29 schrieb Rob Sterenborg:
> > And here is the question. How is it possible to nat a lokal port?
> > 
> > IPTABLES -t nat -A PREROUTING -p tcp -d 127.0.0.1 
> > --destination-port 81 -j DNAT --to-destination 127.0.0.1:80
> > 
> > telnet localhost 80  <<< works
> > telnet localhost 81  <<< Connection refused
> 
> iptables -t nat -A PREROUTING -d 127.0.0.1 -p tcp --dport 80 -j REDIRECT
> --to-ports 81
> 
> 
> Rob

Tanks for the answer,
I tried that one already but it behaves the same.
I also tried 

IPTABLES -t nat -A PREROUTING -p tcp -d 172.16.172.12 --destination-port
81 -j REDIRECT --to-ports 80

wich works perfect for both port 80 and 81 from a foreign host.

Henry



^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Masquerading on local ports
  2003-03-20 16:26   ` Henry Ritzlmayr
@ 2003-03-20 18:34     ` alexb
  0 siblings, 0 replies; 7+ messages in thread
From: alexb @ 2003-03-20 18:34 UTC (permalink / raw)
  To: Henry Ritzlmayr; +Cc: Netfilter Mailing List

This one works for me:

iptables -t nat -A OUTPUT -p tcp -d 127.0.0.1 --dport 81 \
         -j REDIRECT --to-ports 80

Alex

Cópia Henry Ritzlmayr <h.ritzlmayr@gmx.at>:

> Am Don, 2003-03-20 um 16.29 schrieb Rob Sterenborg:
> > > And here is the question. How is it possible to nat a lokal port?
> > > 
> > > IPTABLES -t nat -A PREROUTING -p tcp -d 127.0.0.1 
> > > --destination-port 81 -j DNAT --to-destination 127.0.0.1:80
> > > 
> > > telnet localhost 80  <<< works
> > > telnet localhost 81  <<< Connection refused
> > 
> > iptables -t nat -A PREROUTING -d 127.0.0.1 -p tcp --dport 80 -j
> REDIRECT
> > --to-ports 81
> > 
> > 
> > Rob
> 
> Tanks for the answer,
> I tried that one already but it behaves the same.
> I also tried 
> 
> IPTABLES -t nat -A PREROUTING -p tcp -d 172.16.172.12
> --destination-port
> 81 -j REDIRECT --to-ports 80
> 
> wich works perfect for both port 80 and 81 from a foreign host.
> 
> Henry
> 
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Masquerading on local ports
  2003-03-20 14:03 Masquerading on local ports Henry Ritzlmayr
  2003-03-20 15:29 ` Rob Sterenborg
@ 2003-03-21  7:22 ` Joel Newkirk
  2003-03-21 17:17   ` Henry Ritzlmayr
  1 sibling, 1 reply; 7+ messages in thread
From: Joel Newkirk @ 2003-03-21  7:22 UTC (permalink / raw)
  To: Henry Ritzlmayr, netfilter

On Thursday 20 March 2003 09:03 am, Henry Ritzlmayr wrote:
> Hi everyone - this is my first post to this list - so if anything is
> wrong with my way of posting please tell.
>
> And here is the question. How is it possible to nat a lokal port?
>
> IPTABLES -t nat -A PREROUTING -p tcp -d 127.0.0.1 --destination-port
> 81 -j DNAT --to-destination 127.0.0.1:80
>
> telnet localhost 80  <<< works
> telnet localhost 81  <<< Connection refused
>
> Henry

Packets originating on the local box never go through the PREROUTING 
chains.  This is why there is an OUTPUT chain in the nat table.  (and 
the mangle table)

iptables -t nat -A OUTPUT -o lo -p tcp --dport 81 -j DNAT --to 
127.0.0.1:80

should do it.  I'm not sure if the REDIRECT target would work properly 
for this use (localhost->localhost), but you can try easily enough.

j


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Masquerading on local ports
  2003-03-21  7:22 ` Joel Newkirk
@ 2003-03-21 17:17   ` Henry Ritzlmayr
  0 siblings, 0 replies; 7+ messages in thread
From: Henry Ritzlmayr @ 2003-03-21 17:17 UTC (permalink / raw)
  To: netfilter, Netfilter Mailing List

Am Fre, 2003-03-21 um 08.22 schrieb Joel Newkirk:
> On Thursday 20 March 2003 09:03 am, Henry Ritzlmayr wrote:
> > Hi everyone - this is my first post to this list - so if anything is
> > wrong with my way of posting please tell.
> >
> > And here is the question. How is it possible to nat a lokal port?
> >
> > IPTABLES -t nat -A PREROUTING -p tcp -d 127.0.0.1 --destination-port
> > 81 -j DNAT --to-destination 127.0.0.1:80
> >
> > telnet localhost 80  <<< works
> > telnet localhost 81  <<< Connection refused
> >
> > Henry
> 
> Packets originating on the local box never go through the PREROUTING 
> chains.  This is why there is an OUTPUT chain in the nat table.  (and 
> the mangle table)
> 
> iptables -t nat -A OUTPUT -o lo -p tcp --dport 81 -j DNAT --to 
> 127.0.0.1:80
> 
> should do it.  I'm not sure if the REDIRECT target would work properly 
> for this use (localhost->localhost), but you can try easily enough.
> 
> j

That was it. I overlooked that local packets do not go trough the
PREROUTING.

thanks for the help
Henry



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-03-21 17:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-20 14:03 Masquerading on local ports Henry Ritzlmayr
2003-03-20 15:29 ` Rob Sterenborg
2003-03-20 16:14   ` henry ritzlmayr
2003-03-20 16:26   ` Henry Ritzlmayr
2003-03-20 18:34     ` alexb
2003-03-21  7:22 ` Joel Newkirk
2003-03-21 17:17   ` Henry Ritzlmayr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox