firewall-cmd命令详解

近期新上一个项目,环境是Centos7,以前的iptables的经验没用了。把firewalld研究了下,粗略记录一下把。

常用命令:

firewall-cmd --reload

firewall-cmd --complete-reload 和上面的意思差不多,但是不会维持当前连接信息。比如,用ssh22登陆,如果不小心把ssh 22关掉了,用reload不会把当前的连接杀死。但是用 --complete-reload,那么恭喜,成功的把自己关在外面了^_^。

firewall-cmd --runtime-to-permanent 保存当前配置到配置文件。

firewall-cmd --set-default-zone

 firewall-cmd   --get-active-zones

 firewall-cmd   --zone=<public,dmz...>  --list-all  [--permanent ]  查看当前加载的/配置文件中的zone的配置

 firewall-cmd   --zone=<public,dmz...>  --add-service=serviename

 firewall-cmd   --zone=<public,dmz...>  --add-port=port/protocol

 firewall-cmd   --zone=<public,dmz...>  --add-source 

firewall-cmd [--permanent] [--zone=zone] --add-masquerade 启用ipv4伪装(启动端口转发的前提,具体转发配置请参考man firewalld.richlanguage)

 

关于FIREWALLD 的IPSET:

firewalld 自带了一个ipset,通过把特定的地址加入到ipset,再配置这个ipset为前文中的特定的源或者用于rich_rule以方便管理。

ipset的相关配置子命令必须加入--permanent才能生效,不然会报错。

firewall-cmd  --permanent --new-ipset=ipset --type=type [--family=inet|inet6] [--option=key[=value]]

其中type可通过firewall-cmd   --get-ipset-types查询,option部分可设置timeout,hashsize,maxelem等等,详见man.ipset。

firewall-cmd  --permanent --delete-ipset

firewall-cmd  [--permanent] --info-ipset

firewall-cmd  [--permanent] --ipset=ipset --add-entry

firewall-cmd   [--permanent] --ipset=ipset --add-entries-from-file=filename :将特定IP保存于一个文本中,通过此命令读取,然后作为ipset的条目。原文:

 Add a new entries to the ipset from the file. For all entries that are listed in the file but already in the ipset, a warning will be printed.The file should contain an entry per line. Lines starting with an hash or semicolon are ignored. Also empty lines.

firewall-cmd   [--permanent] --ipset=ipset --remove-entries-from-file=filename 从文件中读取并移除条目,文件格式同上

 

关于FIREWALLD 的service:

这里需要关注的是,并不是开启一个服务就行了,还要观察这个服务的端口是否被配置。[--permanent] --info-service=service命令可以观察一个服务,其显示的格式为:

 service
                 ports: port1 ..
                 protocols: protocol1 ..
                 source-ports: source-port1 ..
                 modules: module1 ..
                 destination: ipv1:address1 ..

即在firewall中创建服务的时候,可以制定这些选项,通常前两个就够了。通过--permanent --new-service=newservicename。

--permanent --service=service --add-port=portid[-portid]/protocol  添加端口

--permanent --service=service --get-ports  列出某个服务的端口

 --permanent --service=service --add-protocol=protocol  给服务添加协议

 --permanent --service=service --add-source-port=portid[-portid]/protocol 添加源端口

 

更多请见man page &  参考https://fedoraproject.org/wiki/Firewalld?rd=FirewallD#ICMP_blocks

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值