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
:
1 2 |
|
Ensure that the service is enabled to start on boot:
1
|
|
Creating Iptables Rules
In this case I will allow port 80 on TCP from all sources:
1
|
|
To persist our current rules, we need to save them to /etc/iptables/rules.v4
with iptables-save
:
1
|
|
Now when we restart, our rules will be loaded and our previous defined rules will be active.
Thank You
Thanks for reading, feel free to check out my website, feel free to subscribe to my newsletter or follow me at @ruanbekker on Twitter.