D
D
Deleted Deleted2015-08-07 14:36:45
linux
Deleted Deleted, 2015-08-07 14:36:45

Iptables: port forwarding what am I doing wrong?

I want to forward the port 192.168.1.2:80 to 127.0.0.1:8080
I will do this:

echo "1" > /proc/sys/net/ipv4/ip_forward # включаю форвардинг в ядро
iptables -t nat -A PREROUTING -p tcp -d 192.168.1.2 --dport 80 -j DNAT --to-destination 127.0.0.1:8080
iptables -t nat -A POSTROUTING -p tcp -s 127.0.0.1 --sport 8080 -j SNAT --to-source 192.168.1.2:80

iptables -L -t nat output
cold :: ~cold # iptables -L -t nat                                                          
Chain PREROUTING (policy ACCEPT)  
target     prot opt source               destination         
DNAT       tcp  --  anywhere             192.168.1.2          tcp dpt:http to:127.0.0.1:8080

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
SNAT       tcp  --  localhost            anywhere             tcp spt:http-alt to:192.168.1.2:80

Chain DOCKER (0 references)
target     prot opt source               destination

Does not work. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2015-08-07
@Azimov

iptables -t nat -A POSTROUTING -p tcp -s 127.0.0.1 -j SNAT --to-source 192.168.1.2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question