本文介绍 CentOS 7.x 操作系统中防火墙状态查询、打开、关闭、启用和禁用的命令。
目录
- 查看防火墙状态
- 关闭防火墙
- 禁用防火墙
- 启用防火墙
- 打开防火墙
查看防火墙状态
[root@01 ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since 一 2019-01-14 19:16:21 CST; 1min 30s ago
Docs: man:firewalld(1)
Main PID: 743 (firewalld)
CGroup: /system.slice/firewalld.service
└─743 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
1月 14 19:16:20 01 systemd[1]: Starting firewalld - dynamic firewall daemon...
1月 14 19:16:21 01 systemd[1]: Started firewalld - dynamic firewall daemon.
关闭防火墙
[root@01 ~]# systemctl stop firewalld.service
[root@01 ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: inactive (dead) since 一 2019-01-14 19:19:22 CST; 29s ago
Docs: man:firewalld(1)
Process: 743 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 743 (code=exited, status=0/SUCCESS)
1月 14 19:16:20 01 systemd[1]: Starting firewalld - dynamic firewall daemon...
1月 14 19:16:21 01 systemd[1]: Started firewalld - dynamic firewall daemon.
1月 14 19:19:21 01 systemd[1]: Stopping firewalld - dynamic firewall daemon...
1月 14 19:19:22 01 systemd[1]: Stopped firewalld - dynamic firewall daemon.
此命令只能暂时关闭防火墙,一旦系统重启则防火墙又会再次打开。
禁用防火墙(防止系统重启后再次打开)
[root@01 ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
启用防火墙
[root@01 ~]# systemctl enable firewalld.service
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/basic.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
打开防火墙
[root@01 ~]# systemctl start firewalld.service
[root@01 ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since 一 2019-01-14 19:27:48 CST; 9s ago
Docs: man:firewalld(1)
Main PID: 2973 (firewalld)
CGroup: /system.slice/firewalld.service
└─2973 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
1月 14 19:27:49 01 firewalld[2973]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete FORWARD --destination 192.168.122.0/24 --o...PT' failed:
1月 14 19:27:49 01 firewalld[2973]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete FORWARD --source 192.168.122.0/24 --in-int...PT' failed:
1月 14 19:27:49 01 firewalld[2973]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete FORWARD --in-interface virbr0 --out-interf...PT' failed:
1月 14 19:27:49 01 firewalld[2973]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete FORWARD --out-interface virbr0 --jump REJECT' failed:
1月 14 19:27:49 01 firewalld[2973]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete FORWARD --in-interface virbr0 --jump REJECT' failed:
1月 14 19:27:49 01 firewalld[2973]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete INPUT --in-interface virbr0 --protocol udp...PT' failed:
1月 14 19:27:49 01 firewalld[2973]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete INPUT --in-interface virbr0 --protocol tcp...PT' failed:
1月 14 19:27:49 01 firewalld[2973]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete OUTPUT --out-interface virbr0 --protocol u...PT' failed:
1月 14 19:27:49 01 firewalld[2973]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete INPUT --in-interface virbr0 --protocol udp...PT' failed:
1月 14 19:27:49 01 firewalld[2973]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --delete INPUT --in-interface virbr0 --protocol tcp...PT' failed:
Hint: Some lines were ellipsized, use -l to show in full.