Centos5.8 iptables管理

使用第三方提供的Centos5.8 vmx安装的虚拟机实例, 在安装Tomcat时发现启动后8080端口无法访问, 先检查是否selinux作了限制

# 查看selinux状态
sestatus
getenforce
# 查看selinux对端口的限制情况
semanage port -l
# 其中8080端口是否打开:
semanage port -l|grep 8080

排除了selinux的问题后, 发现是iptables引起. 查询发现, centos5.x里, 使用了一个 RH-Firewall-1-INPUT 的target, 所有INPUT和FORWARD都会target过去,

-A INPUT -j RH-Firewall-1-INPUT -A FORWARD -j RH-Firewall-1-INPUT

就是这个RH-Firewall-1-INPUT导致了8080端口无法访问.

据说在Centos6.x 里面 RH-Firewall-1-INPUT 已经被废除. 因为是测试环境, 所以直接清空保存了:

iptables -F iptables -X iptables -Z
# 查看, -n参数将IP数字化,-v输出更多信息,包括in out网口
iptables -L -n -v
# 保存
service iptables save
# 重启
service iptables start

后查看是否生效

RH官网上有详细解释: https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_MRG/1.3/html/Messaging_Installation_Guide/sect-Messaging_Installation_Guide-Authentication_and_Authorization-FirewallConfiguration.html

Update 20150711

在Centos6.3里, 默认只打开了22端口, 其他的端口都需要到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 -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

在22端口的规则下面, 照抄即可, 例如开放8080端口的通信

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

posted on 2014-06-15 01:21  Milton  阅读(762)  评论(0编辑  收藏  举报

导航