/etc/init.d/iptables status 查看当前的防火墙状态
如果返回,iptables: Firewall is not running
需要开启防火墙 service iptables start (service iptables stop 关闭防火墙)
添加8080端口的开放:iptables -A INPUT -p tcp --dport 8080 -j ACCEPT (注意空格)
8080可以修改为任意想要放行的端口 然后就可以访问了
小知识:
添加防火墙规则
-A默认是插入到尾部的,可以-I来插入到指定位置
[root@linux ~]# iptables -I INPUT 3 -p tcp -m tcp --dport 20 -j ACCEPT // 插入到INPUT 第3号
[root@linux ~]# iptables -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT //开放21端口
[root@linux ~]# iptables -R INPUT 3 -j DROP //将规则3修改成DROP
[root@linux ~]# iptables -D INPUT 3 //删除input的第3条规则
参考了https://blog.csdn.net/ssergsw/article/details/14168069 大神的文章