CentOS7使用firewall命令設置防火牆,若是是CentOS7如下的版本,使用的是iptables命令設置防火牆。bash
查看已經開放的端口號和協議tcp
firewall-cmd --list-ports
開放端口code
firewall-cmd --zone=public --add-port=80/tcp --permanent
--zone是做用域,設置爲public。ip
--add-port是添加開放的端口與協議,設置爲80/tcp。作用域
--permanent是設置爲永久生效,不然重啓後就無效了。cmd
設置後須要重啓防火牆table
firewall-cmd --reload
若是要關閉防火牆,而且開機不在自動啓動防火牆,須要輸入下面的兩個命令class
systemctl stop firewalld.service #中止 systemctl disable firewalld.service #開機不在啓動