1、iptables防火墙
1、基本操作
# 查看防火墙状态
[root@bogon tmp]#service iptables status
# 停止防火墙
[root@bogon tmp]#service iptables stop
# 启动防火墙
[root@bogon tmp]#service iptables start
# 重启防火墙
[root@bogon tmp]#service iptables restart
# 永久关闭防火墙
[root@bogon tmp]#chkconfig iptables off
# 永久关闭后重启
[root@bogon tmp]#chkconfig iptables on
2、开启80端口
[root@bogon tmp]#vim /etc/sysconfig/iptables
# 加入如下代码
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
保存退出后重启防火墙
[root@bogon tmp]#service iptables restart
2、firewalld防火墙
1、查看firewall服务状态
[root@bogon tmp]#systemctl status firewalld
2、查看firewall的状态
[root@bogon tmp]#firewall-cmd --state
3、开启、重启、关闭、firewalld.service服务
# 开启
[root@bogon tmp]#systemctl start firewalld
# 重启
[root@bogon tmp]#systemctl restart firewalld
# 关闭
[root@bogon tmp]#systemctl stop firewalld
4、查看防火墙规则
[root@bogon tmp]#firewall-cmd --list-all
#查看所有开放端口
[root@bogon tmp]#firewall-cmd --list-ports
5、查询、开放、关闭端口
# 查询端口是否开放
[root@bogon tmp]#firewall-cmd --query-port=8080/tcp
# 开放80端口
[root@bogon tmp]#firewall-cmd --permanent --add-port=80/tcp
# 移除端口
[root@bogon tmp]#firewall-cmd --permanent --remove-port=8080/tcp
#重启防火墙(修改配置后要重启防火墙)
[root@bogon tmp]#firewall-cmd --reload
# 参数解释
1、firwall-cmd:是Linux提供的操作firewall的一个工具;
2、--permanent:表示设置为持久;
3、--add-port:标识添加的端口;