1.centos7版本对防火墙进行 加强,不再使用原来的iptables,启用firewall
1.查看已开放的端口(默认不开放任何端口)
firewall-cmd --list-ports
2.开启80端口
firewall-cmd --zone=public(作用域) --add-port=80/tcp(端口和访问类型) --permanent(永久生效)
3.重启防火墙
firewall-cmd --reload
4.停止防火墙
systemctl stop firewalld.service
5.禁止防火墙开机启动
systemctl disable firewalld.service
6.删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent
2.centos7以下版本
1.开放80,22,8080 端口
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
2.保存
/etc/rc.d/init.d/iptables save
3.查看打开的端口
/etc/init.d/iptables status
4.关闭防火墙
1) 永久性生效,重启后不会复原
开启: chkconfig iptables on
关闭: chkconfig iptables off
2) 即时生效,重启后复原
开启: service iptables start
关闭: service iptables stop
本文介绍了如何在CentOS 7及其以下版本中配置防火墙。对于CentOS 7,文章详细说明了如何使用firewall命令来开启端口、重启及停止防火墙服务等操作。而对于CentOS 7以下版本,则提供了通过iptables进行端口开放的方法。
9320

被折叠的 条评论
为什么被折叠?



