导语
今天说下防火墙的操作。CentOS 6
的防火墙是 iptables
,CentOS 7
默认的是 firewall
,以前的操作不再适用。
查看、开启
服务器刚刚重启完毕,先来看下防火墙的状态,输入 systemctl status firewalld
进行查看

这里是关闭的,然后把它打开,使用 systemctl start firewalld

设置为开机自动启动
输入 systemctl is-enabled firewalld
,可以查看是否设置为开机启动

那下一步就是设置为开机自动启动,systemctl enable firewalld

好的,设置完成后,reboot
重启之后再查看

查看、开启端口
先来看下 80 端口是否开启 firewall-cmd --query-port=80/tcp

简单粗暴的一个 no
,那就来开启吧。使用 firewall-cmd --zone=public --permanent --add-port=80/tcp
来开启。zone
是作用域;--permanent
是永久生效;不然重启后就失效了;80/tcp
是按照 端口/协议
的格式

注意,修改之后要更新防火墙,firewall-cmd --reload

好了,再来查看一下是否开启

这个命令是用来查看所有开启的端口,firewall-cmd --list-ports

删除一个端口就用 firewall-cmd --remove-port=80/tcp -permanent
,需要注意的是,删除之后仍然是要更新防火墙

参考资料:systemctl 命令、centos7 firewalld(防火墙)和systemctl(开机启动服务)相关。
网友评论