CentOS 7.0默認使用的是firewall作為防火牆,之前版本是使用iptables。
所以在CentOS 7執行下面命令是無法查看防火牆狀態的。
[root@localhost ~]# service iptables status
Redirecting to /bin/systemctl status iptables.service
Unit iptables.service could not be found.
查看防火牆是否關閉
firewall-cmd --state
[root@localhost ~]# firewall-cmd --state not running [root@localhost ~]#
開啟防火牆
[root@localhost ~]# systemctl start firewalld [root@localhost ~]# firewall-cmd --state running [root@localhost ~]#
關閉防火牆
[root@localhost ~]# systemctl stop firewalld [root@localhost ~]# firewall-cmd --state not running [root@localhost ~]#
禁止firewall開機啟動
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
這樣設置的話,下次重啟開機的時候就會禁止firewall的啟動,即關閉狀態。
設置firewall開機啟動
[root@localhost ~]# systemctl enable firewalld
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
這樣設置之后,開機就會自動開啟防火牆。
顯示防火牆應用列表
[root@localhost ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: ssh dhcpv6-client
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
[root@localhost ~]# firewall-cmd --add-service=ftp
success
[root@localhost ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: ssh dhcpv6-client ftp
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
[root@localhost ~]#
使用firewall-cmd --add-service=ftp
之后,列表顯示出多了一個ftp服務。