最近装了Centos7,/etc/sysconfig/下没有iptables,原来是Centos7中默认将原来的防火墙iptables升级为了firewalld。
那如何在firewalld中添加服务端口呢?我这里以配置服务的方式添加端口。
先说说我的需求:我安装了一个WEB端的分析软件smrtlink, 它需要通过9090提供http访问和通过8243提供https访问,所以我要分别开放9090和8243端口。
cp /usr/lib/firewalld/services/http.xml /etc/firewalld/services/smrt-http.xml
cp /usr/lib/firewalld/services/https.xml /etc/firewalld/services/smrt-https.xml
然后分别把 :
smrt-http.xml 文件中 <port protocol=”tcp” port=”80″/> 行改为 <port protocol=”tcp” port=”9090″/>
smrt-https.xml 文件中 <port protocol=”tcp” port=”443″/> 行改为 <port protocol=”tcp” port=”8243″/>
然后分别把这两个服务放入 public zone中 smrt-http 和 smrt-https 服务 (因为我用的网卡默认激活的的是public zone规则[查看当前激活zone的命令:firewall-cmd —get-active-zones])
vi /etc/firewalld/zones/public.xml
<?xml version=”1.0″ encoding=”utf-8″?>
<zone>
<short>Public</short>
<description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name=”ssh”/>
<service name=”smrt-http”/> #加入smrt-http服务,开放9090端口
<service name=”smrt-https”/> #加入smrt-https服务,开放8243端口
<service name=”dhcpv6-client”/>
</zone>
重启防火墙:
systemctl stop firewalld.service
systemctl start firewalld.service
此时,网站就可以通过 9090和8243端口访问了!
参考:
http://www.excelib.com/article/287/show/
http://blog.csdn.net/u012486840/article/details/52635263
http://blog.csdn.net/achang21/article/details/52538049
https://www.cnblogs.com/hubing/p/6058932.html
https://www.zhaokeli.com/Article/6321.html
http://blog.csdn.net/u011846257/article/details/54707864
http://blog.csdn.net/csdn_lqr/article/details/53885808
尊重他人劳动成果,转载请注明出处:Bluesky's blog » CentOS 7 为firewalld添加开放端口