CentOS操作系统防火墙添加例外端口

CentOS6与CentOS7添加防火墙例外端口的命令不用,需单独来说:

(1)CentOS6下添加防火墙例外端口

#vim/ets/sysconfig/iptables

在 -A INPUT -m state--state NEW -m tcp -p tcp --dport 22 -j ACCEPT

一行的后台添加类似的一行命令即可,如

# 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 -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

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

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

然后重启防火墙服务:

#service iptables restart/start/stop

(2)CentOS7下添加防火墙例外端口

# firewall-cmd --zone=public --add-port=8180/tcp --permanent        #添加8180端口

# firewall-cmd --reload                      #重新加载策略配置,以使新配置生效

注:禁止firewall开机启动为:systemctldisable firewalld.service

 

posted @ 2017-11-28 13:28  Histring  阅读(1977)  评论(0编辑  收藏  举报