- Published on
How to persist iptables rules after reboots
- Authors
- Name
- Ruan Bekker
- @ruanbekker
In this tutorial we will demonstrate how to persist iptables rules across reboots.
Rules Peristence
By default, when you create iptables rules its active, but as soon as you restart your server, the rules will be gone. Therefore we need to persist these rules across reboots.
Dependencies
We require the package iptables-persistent
and I will install it on a debian system so I will be using apt
:
sudo apt update
sudo apt install iptables-persistent -y
Ensure that the service is enabled to start on boot:
sudo systemctl enable netfilter-persistent
Creating Iptables Rules
In this case I will allow port 80 on TCP from all sources:
sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT
To persist our current rules, we need to save them to /etc/iptables/rules.v4
with iptables-save
:
sudo iptables-save > /etc/iptables/rules.v4
Now when we restart, our rules will be loaded and our previous defined rules will be active.
Thank You
Thanks for reading, if you like my content, feel free to check out my website, and subscribe to my newsletter or follow me at @ruanbekker on Twitter.
- Linktree: https://go.ruan.dev/links
- Patreon: https://go.ruan.dev/patreon