I have problem with iptables on Ubuntu 18.04 before that I used to use with Centos 7 and Red Hat and I can simply restart with
systemctl restart iptables
but on Ubuntu it does not work. I could not find iptable under init.d
neither.
Can anybody help me out how can I restart or reload it on Ubuntu 18.04?
If you would like your Ubuntu firewall to function in a similar way to RedHat/Fedora, in Ubuntu 18.04 20.04 22.04, you probably want these:
Then edit the rules in
/etc/iptables/rules.v[46]
Other commands that might be useful:
If you ever find that your rules aren't correctly applied at boot, you can run these commands to test that there are not errors in your config files:
The two packages are similar, but provide slightly different functionality. If you only install
iptables-persistent
, you won't get the service definition file for correct handling in systemd, eg/lib/systemd/system/netfilter-persistent.service
If you only install
netfilter-persistent
, you will find that rules are not correctly applied at boot, as per the READMEIn newer distributions you normally have a frontend to configure and manage the firewall. The most popular these days are
ufw
andfirewalld
and maybeshorewall
. Those frontends also take care to add the rules iniptables
and theiptables
script can be skipped or better to say should be skipped, as the frontends will not pick up your changes you have done withiptables
command directly.For Ubuntu 18.04, it seems
firewalld
has become the default whereufw
is installed but inactive.So rather than creating own
iptables
conform rules you should use these frontends to create your firewall configuration.I am not familiar with
ufw
but sure you will find information here with askubuntu or somewhere else on the internet.firewalld
comes with a GUI (firewall-config
) and a command line toolfirewall-cmd
.With
firewalld
you have the option to add rules without applying it right now (permanent) and apply it only after a firewall reload. Or you can add them to your runtime configuration, test it and add it then to your permanent configuration.To reload e.g. a newly added permanent configuration to your running rules you would have to enter the command as follows or do the corresponding clicks in the GUI.
It might look a bit more complicated on the first glance, since
firewalld
is following zones and an chains concept. But it nicely integrates with NetworkManager, ships a GUI...A good starting point to get familiar with it is here.
You can check content of the package with :
And then you will find that following command is correct:
In Ubuntu 1804 to achieve persistence, use the command: iptables-save > /etc/iptables/rules.v4
or just add the iptables line by hand to the file: /etc/iptables/rules.v4
Debian / Ubuntu does not have an init script for iptables (unlike any fedora / RHEL / Centos)
You either have e to write a script or see iptables resets when server reboots
Alternately use UFW https://help.ubuntu.com/community/UFW
Or firewalld
How can we replace iptables with firewalld in ubuntu 16.04?