版权声明:技术分享,转载附上笔者链接即可 https://blog.csdn.net/lwqBrell/article/details/89067327
打开/关闭/重启防火墙
chkconfig iptables on #开启防火墙(永久生效): service iptables start #开启防火墙(本次生效): chkconfig iptables off #关闭防火墙(永久生效): service iptables stop #关闭防火墙(本次生效): service iptables restartd #重启防火墙
查看端口开放状况
/etc/init.d/iptables status
开启端口
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
保存并重启防火墙
/etc/rc.d/init.d/iptables save /etc/init.d/iptables restart
打开40000~50000之间的端口
iptables -A INPUT -p tcp --dport 40000:50000 -j ACCEPT
查看某一端口是否开放
lsof -i:8080
通过修改/etc/sysconfig/iptables文件的方式开启端口
vi /etc/sysconfig/iptables
然后在文件中增加一行
# Generated by iptables-save v1.4.7 on Sat Apr 6 09:47:20 2019
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [40:5904]
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 39000:40000 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8888 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
接着重启防火墙即可