Search code examples
ubuntuiptables

How to permanently update iptables


I'm trying to redirect http traffic to port 8080 on the same machine and have the iptables rules below working.

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-ports 8080

I'm trying to figure out how to make this change permanent incase of a reboot of the system.

I'm using Ubuntu 11.10 server.


Solution

  • One way to do this would be:

    vim /etc/network/interfaces
    

    Append the below line along with your lo directives:

    post-up /sbin/iptables-restore < /etc/iptables-up.rules
    

    Now run the below command

    iptables-save > /etc/iptables-up.rules
    

    I hope this helps.