CentOS 7.5 設置防火牆 firewall

1、查看防火牆狀態

方法一:service firewalld status

[root@host-192-168-37-24 ~]# service firewalld status
Redirecting to /bin/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 Sun 2019-10-27 17:15:13 CST; 1min 51s ago
     Docs: man:firewalld(1)
 Main PID: 92586 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─92586 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

Oct 27 17:15:13 host-192-168-37-24 systemd[1]: Starting firewalld - dynamic firewall daemon...
Oct 27 17:15:13 host-192-168-37-24 systemd[1]: Started firewalld - dynamic firewall daemon.
[root@host-192-168-37-24 ~]# 

方法二:systemctl status firewalld.service

[root@host-192-168-37-24 ~]# 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 Sun 2019-10-27 17:15:13 CST; 12s ago
     Docs: man:firewalld(1)
 Main PID: 92586 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─92586 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

Oct 27 17:15:13 host-192-168-37-24 systemd[1]: Starting firewalld - dynamic firewall daemon...
Oct 27 17:15:13 host-192-168-37-24 systemd[1]: Started firewalld - dynamic firewall daemon.
[root@host-192-168-37-24 ~]# 

方法三:firewall-cmd --state

[root@host-192-168-37-24 ~]# firewall-cmd --state
not running
[root@host-192-168-37-24 ~]# firewall-cmd --state
running

2、啓動、停止、重啓 firewalld.service

方法一:systemctl

[root@host-192-168-37-24 ~]# systemctl stop firewalld.service
[root@host-192-168-37-24 ~]# systemctl start firewalld.service
[root@host-192-168-37-24 ~]# systemctl restart firewalld.service

方法二:service

[root@host-192-168-37-24 ~]# service firewalld stop
[root@host-192-168-37-24 ~]# service firewalld start
[root@host-192-168-37-24 ~]# service firewalld restart

3、查看防火牆規則

[root@host-192-168-37-24 ~]# firewall-cmd --list-all 
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources: 
  services: ssh dhcpv6-client
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
	
[root@host-192-168-37-24 ~]# 

4、查詢規則、開放端口、關閉端口

[root@host-192-168-37-24 ~]# firewall-cmd --query-port=80/tcp
no
[root@host-192-168-37-24 ~]# firewall-cmd --add-port=80/tcp
success
[root@host-192-168-37-24 ~]# firewall-cmd --remove-port=8080/tcp
success

# 修改防火牆規則後,需要重啓防火牆
[root@host-192-168-37-24 ~]# firewall-cmd --reload 
success
[root@host-192-168-37-24 ~]# 
參數含義:
firwall-cmd:	# 是Linux提供的操作firewall的命令工具;
--permanent:	# 表示設置爲持久;
--add-port:	# 表示添加的端口;
--remove-port:	# 表示刪除端口

5、END

愉快的玩耍吧

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章