Bug 1531545

Summary: [RFE] Flush all the rules of firewalld using a single command.
Product: Red Hat Enterprise Linux 8 Reporter: Akhil John <ajohn>
Component: firewalldAssignee: Eric Garver <egarver>
Status: CLOSED WONTFIX QA Contact: qe-baseos-daemons
Severity: medium Docs Contact:
Priority: medium    
Version: 8.0CC: atragler, jnikolak, mstuff, pasik, redhat, rkhan, todoleza
Target Milestone: rcKeywords: FutureFeature
Target Release: 8.1   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-01-08 07:26:20 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Akhil John 2018-01-05 13:17:09 UTC
Description of problem:
Firewalld doesn't have a single command to flush all the rules like that we have with #iptables -F so that the firewalld will be back to the default state.

Version-Release number of selected component (if applicable):
All firewalld versions

How reproducible:
Always.

Comment 3 Tomas Dolezal 2018-03-21 13:50:45 UTC
Indeed there's no possibility to apply default configuration without unloading modules, that's when the default is applied by restarting the whole service.
and `--complete-reload` leaves e.g. direct rules in place

Comment 4 Eric Garver 2018-04-23 15:33:37 UTC
I think you're looking for a command line:

  $ firewalld --permanent --reset-to-defaults

Is that true?

Comment 5 Akhil John 2018-04-25 10:07:52 UTC
Yes

Comment 6 morgan read 2018-10-19 12:31:23 UTC
Copying relevant files from /usr/lib/firewalld/zones to /etc/firewalld/zones seemed to do the trick for me.  Hope I'm correct...

Comment 7 Eric Garver 2018-10-19 13:15:43 UTC
(In reply to morgan read from comment #6)
> Copying relevant files from /usr/lib/firewalld/zones to /etc/firewalld/zones
> seemed to do the trick for me.  Hope I'm correct...

If items in /etc/firewalld don't exist the defaults from /usr/lib/firewalld will be used. Copying them is okay. You could have simply removed the zones in /etc/firewalld/zones instead.

Comment 8 Eric Garver 2019-03-01 20:28:11 UTC
Bumping to RHEL-8. It can be done manually in RHEL-7 an indicated in comment 6 and comment 7.

Comment 9 jnikolak 2019-09-24 02:40:35 UTC
This solution definitely does work and I've tested it.

@localhost /]# rm -rf  /etc/firewalld/zones/
@localhost /]# cp -r /usr/lib/firewalld/zones  /etc/firewalld/zones
@localhost /]# firewall-cmd --reload
@localhost /]# firewall-cmd --zone=public --list-all

public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s25
  sources: 
  services: dhcpv6-client ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
	

@localhost /]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-09-24 12:30:08 AEST; 5min ago
     Docs: man:firewalld(1)
 Main PID: 30469 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─30469 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

Sep 24 12:30:08 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Sep 24 12:30:08 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.


RFE could perhaps attach a firewall-cmd command that would run the commands below. It could be with a backup-directory option, which is less crude.

#!/usr/bin/bash
rm -rf  /etc/firewalld/zones/
cp -r /usr/lib/firewalld/zones  /etc/firewalld/zones
firewall-cmd --reload
echo "Default Firewalld has been applied"
systemctl status firewalld

Comment 10 Eric Garver 2019-09-24 12:36:55 UTC
(In reply to jnikolak from comment #9)
> This solution definitely does work and I've tested it.
[..]
> RFE could perhaps attach a firewall-cmd command that would run the commands
> below. It could be with a backup-directory option, which is less crude.
> 
> #!/usr/bin/bash
> rm -rf  /etc/firewalld/zones/
> cp -r /usr/lib/firewalld/zones  /etc/firewalld/zones

The copy is not necessary. Firewalld will do the copy itself when the user modifies one of the built-in zones.
But the directory /etc/firewalld/zones should remain. The first line should be

  rm -rf  /etc/firewalld/zones/*

> firewall-cmd --reload
> echo "Default Firewalld has been applied"
> systemctl status firewalld

There are also other user configs for services, helpers, etc under /etc/firewalld. But those only have an effect if referenced from a zone.

Comment 11 Eric Garver 2019-09-24 13:17:18 UTC
(In reply to Eric Garver from comment #10)
> There are also other user configs for services, helpers, etc under
> /etc/firewalld. But those only have an effect if referenced from a zone.

There is also /etc/firewalld/firewalld.conf. It _should_ be possible to also delete firewalld.conf and firewalld will use the defaults. Although I've not verified this.

Comment 15 RHEL Program Management 2021-01-08 07:26:20 UTC
After evaluating this issue, there are no plans to address it further or fix it in an upcoming release.  Therefore, it is being closed.  If plans change such that this issue will be fixed in an upcoming release, then the bug can be reopened.

Comment 16 Herb Goldman 2022-07-27 20:19:26 UTC
Since it's not a built-in feature, this simple script works for me.  YMMV

# cat clear-all-fw-rules 
firewall-cmd --list-all --permanent | grep family | tr '\011' ' ' | \
 while read -r LINE
  do
    echo -n "${LINE}":
    firewall-cmd --remove-rich-rule="${LINE}" --permanent
 done


# ./clear-all-fw-rules 
rule family="ipv4" source address="221.150.141.252/24" log level="warning" drop:success
rule family="ipv4" source address="139.162.205.145/24" log level="warning" drop:success
rule family="ipv4" source address="185.162.235.162/24" log level="warning" drop:success
..



Description of problem:
Firewalld doesn't have a single command to flush all the rules like that we have with #iptables -F so that the firewalld will be back to the default state.

       -F, --flush [chain]
              Flush the selected chain (all the chains in the table if none is given).  This is equivalent to deleting all the rules one by one.