Reset firewalld rules to default?
Solution 1
Following piece of Code may be helpful for you.
for srv in $(firewall-cmd --list-services);do firewall-cmd --remove-service=$srv; done
firewall-cmd --add-service={ssh,dhcpv6-client}
firewall-cmd --runtime-to-permanent
Regards,
Ahmer Mansoor
Solution 2
You may simply delete the files containing the customized zone rules from /etc/firewalld/zones
(or /usr/etc/firewalld/zones
, depending on the distribution). After that, reload firewalld
with firewall-cmd --complete-reload
, and it should start using the default settings. When you make changes to the zone rules, files will appear again in that directory.
As for iptables
, you may reset all rules with iptables -F
. Rebooting works as well, unless you implemented some sort of persistency. Beware that firewalld
may be configured to use iptables
as its backend, which means it will add or remove iptables
rules itself, according to what you specified in its zone rules.
Solution 3
If you trully want to delete everything as John Ashpool say's
rm -rf /etc/firewalld/zones
or /usr/etc/firewalld/zones depending on your distro
and
iptables -X
iptables -F
iptables -Z
plus
systemctl restart firewalld
and then you have a new set of rules and zones ;)
Solution 4
Personally I would just remove all the services and rules from all the zones you have edited. Except for SSH in case you are working on a remote server. That is easy: sudo firewall-cmd --zone=WHATEVER --remove-service=WHATEVER
And after all have been removed, just sudo firewall-cmd --runtime-to-permanent
HOWEVER: If you haven't saved the firewall rules, then just restart with systemctl restart firewalld
I don't think there is any reset function in it.
Related videos on Youtube
Daniel Shterenberg
Updated on September 18, 2022Comments
-
Daniel Shterenberg over 1 year
On CentOS 7 have I been trying out different firewalld rules and iptables commands, and now want to do it all over, but only using firewalld.
Question
How can I reset all rules to the default that CentOS 7's firewalld ships with?
-
Daniel Shterenberg about 6 yearsThis will not remove the manual iptables rules I have made.
-
Bert about 6 yearsThen you want to reset iptables, not firewall. kerneltalks.com/virtualization/…
-
Tristan CHARBONNIER about 2 yearsI had to also remove
/etc/firewalld/direct.xml
which was containing custom rules I added. -
denn0n about 2 yearsI did not knew that Tristan Thank you !