Skip to content

Instantly share code, notes, and snippets.

@niksmac
Last active April 25, 2022 05:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niksmac/e6d83c243deb92f02b01b236a97a1f8f to your computer and use it in GitHub Desktop.
Save niksmac/e6d83c243deb92f02b01b236a97a1f8f to your computer and use it in GitHub Desktop.
Persist iptables even after reboot Ubuntu

Set the rules

sudo iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

On Ubuntu: sudo apt-get install iptables-persistent

After that, run next commands every time you want save iptables changes permanently:

sudo netfilter-persistent save
sudo netfilter-persistent reload
@niksmac
Copy link
Author

niksmac commented Oct 14, 2021

If you have pm2, run pm2 startup and pm2 save

@niksmac
Copy link
Author

niksmac commented Apr 25, 2022

If the network interface is different

sudo iptables -t nat -A PREROUTING -i ens5 -p tcp --dport 80 -j REDIRECT --to-port 3000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment