vi /etc/sysconfig/iptables
进入编辑页面,在指定位置新增以下配置
-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 22 -j ACCEPT 后面
修改后的整体为下面所示
# Generated by iptables-save v1.4.7 on Wed Mar 22 17:51:24 2017
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -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 -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Wed Mar 22 17:51:24 2017
2.修改完保存退出,重启网卡服务
service iptables restart
3.查看端口开放信息
service iptables status
一般服务器能看到开放信息就算成功开放了。