开放端口的方法一:(以8080端口为例)
1. vi /etc/sysconfig/iptables
加入内容并保存:-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
2.重启服务:/etc/init.d/iptables restart
3.查看端口是否开放:/sbin/iptables -L -n
查询端口是否有进程守护:
用如下命令grep对应端口,如80为端口号
例:netstat -nalp|grep 80
开发端口方法二:适用于iptables无法正常启动,报commit错误的。
iptables无法正常启动iptables,且启动后无任何提示信息。原因是缺少iptables文件(/etc/sysconfig/iptables)
添加放行80端口并保存配置(自动生成/etc/sysconfig/iptables文件)
1、/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
2、/etc/init.d/iptables save
显示如下成功:
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
再次启动即可
3、/etc/init.d/iptables start
显示如下成功:
iptables: Applying firewall rules: [ OK ]
4、查看状态:
/etc/init.d/iptables status;
显示如下:
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT tcp – 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination