Skip to contentSkip to conversation

Masquerading on local ports

DISCUSSION Henry Ritzlmayr 5 participants 7 messages Mar 20, 2003 – Mar 21, 2003

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 7 lines

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

#2 lore raw

Am Don, 2003-03-20 um 16.29 schrieb Rob Sterenborg:

Quoted 5 lines
Quoted 5 lines

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

Quoted 8 lines
Quoted 2 lines

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

#3 lore raw
In reply to Rob Sterenborg

Am Don, 2003-03-20 um 16.29 schrieb Rob Sterenborg:

Quoted 5 lines
Quoted 5 lines

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

Quoted 8 lines
Quoted 2 lines

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

#4 lore raw

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 <[email protected]>:

Quoted 29 lines

Am Don, 2003-03-20 um 16.29 schrieb Rob Sterenborg:

Quoted 9 lines
Quoted 7 lines

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

Quoted 4 lines

--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

#5 lore raw
In reply to Henry Ritzlmayr
Quoted 5 lines · Henry Ritzlmayr

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?

Quoted 7 lines

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

#6 lore raw

Am Fre, 2003-03-21 um 08.22 schrieb Joel Newkirk:

Quoted 18 lines · Henry Ritzlmayr
Quoted 5 lines

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?

Quoted 7 lines

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)

Quoted 7 lines

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