68
Linux中iptables(防火墙)中如何打开指定的端口(CentOS6.x)

例:当修改了ssh远程连接端口,如何在iptables上放行新的端口(这里将默认22端口号修改为33端口号)。

输入命令放行33端口。

[root@niaoyun ~]# iptables -I INPUT -p tcp --dport 33 -j ACCEPT

查看防火墙规则,发现33端口号已经放行了。

[root@niaoyun ~]# iptables -nvLChain INPUT (policy ACCEPT 0 packets, 0 bytes)pkts bytes target prot opt in out source destination0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:33295 23186 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED34 2310 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/00 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/02342 200K REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibitedChain FORWARD (policy ACCEPT 0 packets, 0 bytes)pkts bytes target prot opt in out source destination0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibitedChain OUTPUT (policy ACCEPT 15 packets, 1412 bytes)pkts bytes target prot opt in out source destination

iptables规则已经更改,我们需要对规则进行保存。

[root@niaoyun ~]# service iptables saveiptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]

保存完毕,重启iptables服务。

[root@niaoyun ~]# service iptables restartiptables: Setting chains to policy ACCEPT: filter [ OK ]iptables: Flushing firewall rules: [ OK ]iptables: Unloading modules: [ OK ]iptables: Applying firewall rules: [ OK ]

同样,用此方法也可以放行web的默认端口80。

iptables -I INPUT -p tcp --dport 80 -j ACCEPT && service iptables save && service iptables restart


这条帮助是否解决了您的问题? 已解决 未解决

提交成功!非常感谢您的反馈,我们会继续努力做到更好! 很抱歉未能解决您的疑问。我们已收到您的反馈意见,同时会及时作出反馈处理!