当前位置: 移动技术网 > 科技>操作系统>Linux > Centos7防火墙快速开放端口配置方法

Centos7防火墙快速开放端口配置方法

2019年06月20日  | 移动技术网科技  | 我要评论
▲这篇文章主要为大家详细介绍了Centos7防火墙开放端口的快速方法,感兴趣的小伙伴们可以参考一下! 一、CentOS 7快速开放端口: CentOS升级到7之后,发现无法使用iptables控制Linuxs的端口,baidu之后发现Centos 7使用firewalld代替了原来的iptables ...

这篇文章主要为大家详细介绍了centos7防火墙开放端口的快速方法,感兴趣的小伙伴们可以参考一下!

一、centos 7快速开放端口:

centos升级到7之后,发现无法使用iptables控制linuxs的端口,baidu之后发现centos 7使用firewalld代替了原来的iptables。下面记录如何使用firewalld开放linux端口:

开启端口

[root@centos7 ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent

查询端口号80 是否开启:

[root@centos7 ~]# firewall-cmd --query-port=80/tcp

重启防火墙:

[root@centos7 ~]# firewall-cmd --reload

 

查询有哪些端口是开启的:

[root@centos7 ~]# firewall-cmd --list-port

 

命令含义:

--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效

 

关闭firewall:

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall开机启动

 

 

二、centos6防火墙开放端口:

在我们使用centos系统的时候,centos防火墙有时是需要改变设置的。centos防火墙默认是打开的,设置centos防火墙开放端口方法如下:

打开iptables的配置文件:vi /etc/sysconfig/iptables

修改centos防火墙时注意:一定要给自己留好后路,留vnc一个管理端口和ssh的管理端口

下面是一个iptables的示例:

# firewall configuration written by system-config-securitylevel
# manual customization of this file is not recommended.
*filter
:input accept [0:0]
:forward accept [0:0]
:output accept [0:0]
:rh-firewall-1-input - [0:0]
-a input -j rh-firewall-1-input
-a forward -j rh-firewall-1-input
-a rh-firewall-1-input -i lo -j accept
-a rh-firewall-1-input -p icmp –icmp-type any -j accept
-a rh-firewall-1-input -p 50 -j accept
-a rh-firewall-1-input -p 51 -j accept
-a rh-firewall-1-input -m state –state established,related -j accept
-a rh-firewall-1-input -m state –state new -m tcp -p tcp –dport 53 -j accept
-a rh-firewall-1-input -m state –state new -m udp -p udp –dport 53 -j accept
-a rh-firewall-1-input -m state –state new -m tcp -p tcp –dport 22 -j accept
-a rh-firewall-1-input -m state –state new -m tcp -p tcp –dport 25 -j accept
-a rh-firewall-1-input -m state –state new -m tcp -p tcp –dport 80 -j accept
-a rh-firewall-1-input -m state –state new -m tcp -p tcp –dport 443 -j accept
-a rh-firewall-1-input -j reject –reject-with icmp-host-prohibited
commit

修改centos防火墙需要注意的是,你必须根据自己服务器的情况来修改这个文件。

举例来说,如果你不希望开放80端口提供web服务,那么应该相应的删除这一行:
-a rh-firewall-1-input -m state –state new -m tcp -p tcp –dport 80 -j accept

全部修改完之后重启iptables:service iptables restart

你可以验证一下是否规则都已经生效:iptables -l

这样,我们就完成了centos防火墙的设置修改。

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网