标签归档:firewalld

CentOS 7 为firewalld添加开放端口及相关资料

1、运行、停止、禁用firewalld

启动:# systemctl start  firewalld

查看状态:# systemctl status firewalld 或者 firewall-cmd –state

停止:# systemctl disable firewalld

禁用:# systemctl stop firewalld

查看firewall是否运行,下面两个命令都可以

systemctl status firewalld.service
firewall-cmd --state

查看default zone和active zone

我们还没有做任何配置,default zone和active zone都应该是public

firewall-cmd --get-default-zone
firewall-cmd --get-active-zones

查看当前开了哪些端口

其实一个服务对应一个端口,每个服务对应/usr/lib/firewalld/services下面一个xml文件。

firewall-cmd --list-services

查看还有哪些服务可以打开

firewall-cmd --get-services

查看所有打开的端口: 

firewall-cmd --zone=public --list-ports

更新防火墙规则: 

firewall-cmd --reload

添加一个服务到firewalld

firewall-cmd --add-service=http //http换成想要开放的service

这样添加的service当前立刻生效,但系统下次启动就失效,可以测试使用。要永久开发一个service,加上 –permanent

firewall-cmd --permanent --add-service=http

如果要添加的端口并没有服务对应

就要新建一个服务,在/usr/lib/firewalld/services,随便拷贝一个xml文件到一个新名字,比如myservice.xml,把里面的

<?xml version="1.0" encoding="utf-8"?>

<service>
<short>Transmission-client</short>
<description>Transmission is a lightweight GTK+ BitTorrent client.</description>
<port protocol="tcp" port="51413"/>
</service>

short改为想要名字(这个名字只是为了人来阅读,没有实际影响。重要的是修改 protocol和port。修改完保存。我的经验是这是要重启firewalld服务,systemctl restart firewalld.service,否则可能提示找不到刚才新建的service。然后把新建的service添加到 firewalld

firewall-cmd --permanent --add-service=myservice

重启firewalld 生效

5分钟理解Centos7防火墙firewalld    http://www.cnblogs.com/stevenzeng/p/5152324.html  

————————————————————————————————————-

1、firewalld的基本使用

启动: systemctl start firewalld

查看状态: systemctl status firewalld 

停止: systemctl disable firewalld

禁用: systemctl stop firewalld 

2.systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。

启动一个服务:systemctl start firewalld.service

关闭一个服务:systemctl stop firewalld.service

重启一个服务:systemctl restart firewalld.service

显示一个服务的状态:systemctl status firewalld.service

在开机时启用一个服务:systemctl enable firewalld.service

在开机时禁用一个服务:systemctl disable firewalld.service

查看服务是否开机启动:systemctl is-enabled firewalld.service

查看已启动的服务列表:systemctl list-unit-files|grep enabled

查看启动失败的服务列表:systemctl –failed

3.配置firewalld-cmd

查看版本: firewall-cmd –version

查看帮助: firewall-cmd –help

显示状态: firewall-cmd –state

查看所有打开的端口: firewall-cmd –zone=public –list-ports

更新防火墙规则: firewall-cmd –reload

查看区域信息:  firewall-cmd –get-active-zones

查看指定接口所属区域: firewall-cmd –get-zone-of-interface=eth0

拒绝所有包:firewall-cmd –panic-on

取消拒绝状态: firewall-cmd –panic-off

查看是否拒绝: firewall-cmd –query-panic 

那怎么开启一个端口呢添加

firewall-cmd –zone=public –add-port=80/tcp –permanent    

(–permanent永久生效,没有此参数重启后失效)

重新载入

firewall-cmd –reload

查看

firewall-cmd –zone= public –query-port=80/tcp

删除

firewall-cmd –zone= public –remove-port=80/tcp –permanent

linux7-firewalld防火墙禁止IP或端口访问

安装firewall后(LINUX7系统一般情况下默认已安装),防火墙默认配置是只打开SSH端口的,也就是22端口,如果SSH的端口已更改成别的端口了,请切记一定在启动firewall前先修改对应服务策略中SSH的端口为你的SSH端口,文件路径:/usr/lib/firewalld/services/ssh.xml 把22改成你的远程端口号,然后再启动firewall防火墙,如果防火墙已经启动,你再想更改自己的SSH端口号,那么请先把自己要修改SSH端口号,先添加进防火墙放行端口中,否则修改SSH端口后就会导致你的SSH远程登录不上,另外启动防火墙后如果更改配置文件,请一定运行重新加载配置文件(firewall-cmd –reload)命令,重新加载配置文件;

查看firewall状态,LINUX7默认是安装并开启的;
 firewall-cmd --state
 安装
 yum install firewalld
 启动,
 systemctl start firewalld 
 设置开机启动
 systemctl enable firewalld
 关闭
 systemctl stop firewalld
 取消开机启动
 systemctl disable firewalld
 禁止IP(123.44.55.66)访问机器
 firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="123.44.55.66" drop'
 禁止一个IP段,比如禁止116.255..
 firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="116.255.0.0/16" drop'
 禁止一个IP段,比如禁止116.255.196.*
 firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address="116.255.196.0/24" drop'
 禁止机器IP(123.44.55.66)从防火墙中删除
 firewall-cmd --permanent --remove-rich-rule='rule family=ipv4 source address="123.44.55.66" drop'
 允许http服务(对应服务策略目录:/usr/lib/firewalld/services/)
 firewall-cmd --permanent --add-service=http
 关闭http服务(对应服务策略目录:/usr/lib/firewalld/services/)
 firewall-cmd --permanent --remove-service=http
 允许端口:3389
 firewall-cmd --permanent --add-port=3389/tcp
 允许端口:1-3389
 firewall-cmd --permanent --add-port=1-3389/tcp
 关闭放行中端口:3389
 firewall-cmd --permanent --remove-port=3389/tcp
 查看firewall的状态
 firewall-cmd --state        
 查看防火墙规则(只显示/etc/firewalld/zones/public.xml中防火墙策略,在配置策略前,我一般喜欢先CP,以后方便直接还原)
 firewall-cmd --list-all 
 查看所有的防火墙策略(即显示/etc/firewalld/zones/下的所有策略)
 firewall-cmd --list-all-zones 
 重新加载配置文件
 firewall-cmd --reload
 更改配置后一定要重新加载配置文件:
 firewall-cmd --reload