一、centos6使用的防火墙命令
1.1 查看状态 service iptables status
1.2启动 service iptables start;
1.3关闭 service iptables stop;
1.4重启 service iptables restart;
添加端口:找到防火墙位置
/etc/sysconfig/iptables配置文件如下:
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6006 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6007 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
二、centos7使用的防火墙命令
2.1 查看防火墙状态命令:firewall-cmd --state
2.2开启防火墙 systemctl start firewalld
2.3关闭防火墙 systemctl stop firewalld
2.4查看已经开启的端口
firewall-cmd --zone=public --list-ports
2.5防火墙添加端口
firewall-cmd --permanent --zone=public --add-port=8080/tcp
2.6重新加载防火墙,添加端口才能生效
firewall-cmd --reload