0

I've got the follwing working iptables commands:

iptables -t nat -i ppp0 -A PREROUTING -p tcp --dport 81 -j DNAT --to-destination 192.168.16.8:80
iptables -t nat -A POSTROUTING -p tcp --dport 80 -j MASQUERADE

iptables -t nat -i ppp0 -A PREROUTING -p tcp --dport 5000 -j DNAT --to-destination 192.168.16.8:5000
iptables -t nat -A POSTROUTING -p tcp --dport 5000 -j MASQUERADE

I tried to add the following code to /etc/ufw/before.rules at the top and then at the bottom of the file, and did not work:

# NAT table rules
*nat
:PREROUTING ACCEPT [0:0]

-A PREROUTING -i ppp0  -p tcp --dport 81 -j DNAT --to-destination 192.168.16.8:80
-A PREROUTING -i ppp0  -p tcp --dport 5000 -j DNAT --to-destination 192.168.16.8:5000

:POSTROUTING ACCEPT [0:0]

-A POSTROUTING -p tcp --dport 80 -j MASQUERADE
-A POSTROUTING -p tcp --dport 5000 -j MASQUERADE

COMMIT

Any idea? Thanks!

1

Did you try to write it like this?

# NAT table rules
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]

-A PREROUTING -i ppp0  -p tcp --dport 81 -j DNAT --to-destination 192.168.16.8:80
-A PREROUTING -i ppp0  -p tcp --dport 5000 -j DNAT --to-destination 192.168.16.8:5000

-A POSTROUTING -p tcp --dport 80 -j MASQUERADE
-A POSTROUTING -p tcp --dport 5000 -j MASQUERADE

COMMIT

The :PREROUTING and :POSTROUTING policies seems to need to be declared just after the *nat line. At least it is how it looks like in my personal iptables rules file.

3
  • Did not work, here is the iptables-save -c log: pastebin.com/sn3hBFuT
    – Liam
    Sep 12 '14 at 17:54
  • Hi, when you say "did not work", what kind of error do you get in return?
    – Zertrin
    Sep 13 '14 at 19:44
  • The port was unreachable from outside.
    – Liam
    Sep 13 '14 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.