Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have software which needs to run as a non-root user, but needs to listen on port 80 and 443.

With iptables, this isn't all that difficult:

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8080

Though this is simple, how should I persist it to take effect on boot? I tried iptables-save, but this didn't seem to work.

share|improve this question
Depends on OS/distro. They all have their own way of initializing iptables. iptables-save just dumps the rules. – jordanm Apr 18 '13 at 23:07
My bad, it's Ubuntu 12.04. – Naftuli Tzvi Kay Apr 18 '13 at 23:07
up vote 2 down vote accepted

The standard method for restoring iptables rules on boot for Debian-based systems is using a pre-up rule in /etc/network/interfaces.

First you need to save the current rules to a file:

iptables-save > /etc/iptables.rules

In the block for the relevant interface in /etc/network/interfaces add:

pre-up iptables-restore < /etc/iptables.rules

Other methods, such as loading via network-manager can be found on the ubuntu wiki.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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