跳至主要内容

CentOS 7 Firewalld防火墙说明

理论部分

  • firewalld 以 zone 的区域分割观念来建立,并以动态设定方式执行避免中断的问题,不能同时执行 iptables 跟 firewalld ,因为会造成冲突错误

配置文件

相关路径

/etc/firewalld    设定档位置
/usr/bin/:firewall-cmd 指令所在的位置
/usr/lib/firewalld/:firewall预设的设定资料(xml格式)
defalut zone在文档中有指定

有关zone

  • public:公开场所,不信任网域内所有连线,只有被允许的连线才能进入,一般只要设定这里就可以
  • external:公开的场所,应该是IP是NAT的网络
  • dmz:非军事区,允许对外连线,内部网络只有允许的才能进来
  • work:公司、工作的环境
  • home:家庭环境
  • internal:内部网路,应用在NAT设定时的对内网络
  • trusted:接受所有的连线
  • drop:任何进入的封包都丢弃,只有出去的是允许的
  • block:任何进入的封包全部拒绝,并以ICMP回复对方,只有对外的连线是允许的
--------------------------------------
预设主机是被放在public zone区域,并有开启两个服务dhcpv6-client ssh
在这样的预设下,任何来源都可以通过ssh服务连接到本机,但其他服务的service port都关闭

一些操作

显示目前的设定

# firewall-cmd --list-all

关闭DHCP服务

# sudo firewall-cmd --zone=public --remove-service dhcpv6-client

暂时开启DNS port 53

# sudo systemctl start named
# sudo systemctl enable named
# sudo firewall-cmd --add-service=dns
# sudo firewall-cmd --reload
# firewall-cmd --list-all

永久开启DNS port 53 

# sudo firewall-cmd --add-service=dns --permanent
# sudo firewall-cmd --reload

如何修改主机的预设zone 

前面说预设是public zone,但有些服务需要建立在DMZ下,我们可以透过修改 /etc/firewalld/firewalld.conf来将预设的zone改为DNZ
 # sudo vi /etc/firewalld/firewalld.conf    修改DefaultZone=dmz
 # sudo firewall-cmd --reload

加入自行指定的连接埠 

 # sudo firewall-cmd --add-port=8080/tcp --permanent
 # sudo firewall-cmd --reload
 # sudo firewall-cmd --list-all

设定暂时的rules

 # sudo firewall-cmd --add-port=8888/tcp
 # sudo firewall-cmd --list-all
 当你下一次执行reload时候,设定会被取消

修改服务的预设连接埠

 # sudo cp /usr/lib/firewalld/services/http.xml /etc/firewalld/services    以Web为例
 # sudo vi /etc/firewalld/services/http.xml
 修改对应连接埠 port protocol="tcp" port="8080"
 # sudo firewall-cmd --reload

限制某服务只能从哪些IP进入

 # sudo firewall-cmd --add-rich-rule="rule family="ipv4" source
    address="192.168.12.9" port port="8080" protocol="tcp" accept"

直接指定rule到INPUT chain

 # sudo firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p tcp -s "192.168.12.9" --dport 22 -j ACCEPT
 这样的写法使用 # firewall-cmd --list-all是看不到的,要用 iptables -L -n

查看预设载入的rule 

所有的zone设定档会放在 /etc/firewalld/zones和 /usr/lib/firewalld/zones/ ,你所执行的--permanent参数会放在 /etc/firewalld/zones 对应的zone档案里(如:public.xml)

从 /etc/sysconfig/iptables 转为 firewalld 的 direct 

 假设原有的 /etc/sysconfig/iptables 有规则
 -A INPUT -s 140.113.12.9 -j ACCEPT
 -A INPUT -m state --state NEW -m udp -p udp -s 140.113.0.0/16 --dport 123 -j    
  ACCEPT
 -A INPUT -m state --state NEW -m tcp -p tcp -s 140.114.88.0/24 --dport 161 -j ACCEPT
 要转换到 firewalld 的 direct 规则:
 新增 /etc/firewalld/direct.xml ,如果之前有执行过 # sudo firewall-cmd --permanent --direct ...则这个档案会自动生成

新增/修改 direct.xml 增加对应上面的 rules:
 # sudo vi /etc/firewalld/direct.xml
 <?xml version="1.0" encoding="utf-8"?>
<direct>
   
<rule priority="0" table="filter" ipv="ipv4" chain="INPUT">-p tcp -s 192.168.12.9 --dport 22 -j ACCEPT</rule>
   <rule priority="0" table="filter" ipv="ipv4" chain="INPUT">-s 140.113.12.9 -j ACCEPT</rule>
   <rule priority="0" table="filter" ipv="ipv4" chain="INPUT">-p udp -s 140.113.0.0/16 --dport 123 -j ACCEPT</rule>
   <rule priority="0" table="filter" ipv="ipv4" chain="INPUT">-p tcp -s 140.114.88.0/24 --dport 161 -j ACCEPT</rule>
</direct>
 

从zone移除某项服务 

 # sudo firewall-cmd --zone=public --add-service=http --permanent
 # sudo firewall-cmd --zone=public --remove-service=http --permanent

 # sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
 # sudo firewall-cmd --zone=public --remove-port=8080/tcp --permanent

port forward 将从某个port number的封包转送给另外的port或其他主机

 将 80 port 收到的讯息转往 port 8080
 # sudo firewall-cmd --zone="public" --add-forward-port=port=80:proto=tcp:toport=8080

 将 80 port 收到的讯息转往其他主机的 
 # sudo fierwall-cmd --zone="public" -add-forward-port=port=80:proto=tcp:toport=8080:to addr=140.113.1.1
  




参考:

Popular posts from 产品随想的博客

《Elon Musk》Chapter 1 - 10

To anyone I’ve offended, I just want to say, I reinvented electric cars and I’m sending people to Mars in a rocket ship. Did you think I was also going to be a chill, normal dude? ——Elon Musk, Saturday Night Live, May 8, 2021 PROLOGUE: Muse of Fire Near the end of the first week, the boys were divided into two groups and told to attack each other. “It was so insane, mind-blowing,” Musk recalls. Every few years, one of the kids would die. The counselors would recount such stories as warnings. “Don’t be stupid like that dumb fuck who died last year,” they would say. “Don’t be the weak dumb fuck.” 这种氛围有毒 “I realized by then that if someone bullied me, I could punch them very hard in the nose, and then they wouldn’t bully me again. They might beat the shit out of me, but if I had punched them hard in the nose, they wouldn’t come after me again.” 勇于挑战,哈哈哈 In the emergency room, when they were preparing to stitch him up, he resisted being treated until he was promised that the dog would not ...

Steve Jobs: `There's Sanity Returning', 1998

Nobody can doubt the charisma of Steven P. Jobs. The interim CEO of Apple Computer Inc., who returned to the company last July after his ignominious 1985 ouster, has brought back his legendary vision, impatience, and infectious passion for the Macintosh. Jobs spoke to Business Week Correspondent Andy Reinhardt in Apple's stark, fourth-floor boardroom, just after the company rolled out its new software strategy on May 11. Note: This is an extended, online-only version of the Q&A that appears in the May 25, 1998, issue of Business Week. Q: Now that you've introduced the new, bold-looking iMac, are you going to do some radically different products? A: There's a lot of talk about such things -- about handhelds, set-top boxes. A lot of computer companies have been searching for a consumer product. My view is that the personal computer has been the most successful consumer product of the last 10 years. What we have to do, what the industry stopp...

罗伯特·艾格 创始人肖像计划 <​Ep.2>

Link 罗伯特·艾格 创始人肖像计划 <​Ep.2>   https://zhuanlan.zhihu.com/p/127042313 Note 这个男人,过去十五年时间,几乎不接受采访,只是静悄悄的,花掉了1000亿美金。 ——这个男人,太厉害了...... 艾格跳槽去了ABC,从最底层的小导播做起,一辈子46年职业生涯,再也没有跳过槽。这46年里的最后15年,他升任CEO,做出了惊天动地的大事情。 今年,艾格退休写了自传,起名字叫《The Ride of a Lifetime》,我想了半天,这书名有点拽,只能翻译成《一辈子就要干一票大的》,笔者一介俗人,但愿艾总不要介意,哈哈。 ——《一辈子的旅途》,感觉会更契合些?哈哈哈 在艾总的这本《干一票》里,我读来读去,总是找不到他是怎么升到副总裁的——升到副总裁之后的一步步到CEO倒是写的很细致,看来大佬写自传也为自己讳,不愿意提太多当年勇。 ——Interesting 地表最强二人组(Tom Murphy和Dan Burke)最牛逼的成就就是不出让股权(Equity)的资本并购。一路用自由现金流加发行债券来进行收购,85年的时候举债30亿,配合巴菲特的5亿美金,小鱼吞大鱼,一把吃掉了当时比自己体量大得多的ABC电视台。他们俩的管理特点是极端节俭,冷血砍成本(不禁让人想到贝索斯),收购完成后,直接开掉1500员工、干掉高管电梯、高管餐厅、全员改坐经济舱,甚至于把曼哈顿总部的办公室卖了,换来1.75亿美金。三年多就把当时举的债还完。 作为巴菲特一辈子最推崇的企业家组合,Tom和Dan还有一个特点:放权。他们俩极为谨慎用人,但是一旦选中,就破格提拔,尚方宝剑交出,让牛人干大事。没干多久,俩人就接二连三的退休了,艾格你年轻,你来当总裁! 艾格原话是这么写的:“我心里也有预期,感觉最后总裁的位置是我的,但是确实没想到来的那么快”。按照网友的话就是“一脸懵逼”。 艾格有个特点,他性格是标准的外柔内刚,外圆内方。他不强势,不豪夺,永远不是人群中最聒噪的那位。他能等,在大都会(CapCities)花六年时间做三把手,等到二把手退休,再等好几年到一把手退休,最终上位 ——耐得住寂寞,受得住繁华 21世纪出头即提出战略: 第一句:我们只做高质量品牌视频 第二句:全力拥抱技术而不是对抗 第三句:全球化 大佬的出手案例...

CAD 天正与 AI 工作流

基本步骤   1. 天正导出 T3 .dwg 文件,尽量在2007版本   2. AI 打开,打开时候可以选择比例,因为 AI 画布是基于真实尺度   3. AI 打开 .dwg 后,更改画布到所需要的大小   4. 之后用 PS 打开 AI 文件,可以维持想要的大小和比例   5. 而且 AI 可以读取天正的图层 课外了解   1. ETH 风格平面图   2. 日本创新性的停车方式   3. AI中的实时上色功能去了解

Rhino_GH从入门到精通听课笔记_二

一. 基础操作   1. Rhino F6精确更改相机视野   2. 中键和左菜单栏弹出时间都是可以自己设置缩短的 二. 软件技巧   1. GH搭配生成楼梯,柱子,栏杆   2. SU\3DS\OBJ 均可被Rhino识别   3. 已命名工作位置很有用,和和已命名是图标是不一样的   4. Rhino等轴测做法          显示——投影——改为平行          旋转改为0/360          视图——等角视图 三. 奇技淫巧   1. 善用微信搜索,比如“地形制作”,第三讲前半部分讲解利用高程点制作地形   2. Rhino转折剖制作方法,用面split模型,即模型被切成两个,类似于佐罗刀   3. 转折剖模型制作时间很久,工作量比较大 四. Rhino命令   1. worksession  链接文件进来,以一个图层显示,类似于SU里面的另存再载入的操作,可       以节省运算量,比ctrl+c ctrl+v快   2. ctrl+w  局部放大   3. hatch  嵌面

进入双拼的世界

──小鹤双拼官方记忆口诀诗一首 Kuai ing Liang uang Ruan Cao Zou , T ue Qiu Yun Wei Jan Mian 快 迎 两 王 软 草 走 ,特 约 秋 云 为 见 面 Xia ua Song iong ShU ChI ZhVi , Geng Dai Bin Niao Fen Pie Hang 夏 娃 怂 恿 书 痴 追,更 待 斌 鸟 分 撇 航 注释: 如上,一和三两句的前四个字为一个大写字母代表了两个字的拼音   T ue各取拼音谐音为特约,Jan取英文谐音为见,其余均是一个大写字母代表一个字的拼音   斌鸟是一种鸟,分撇一词是分离之意,故斌鸟分撇航意为鸳鸯各自飞。   译文: 一个地方官笑着说:“快欢迎两位王爷到软草原走一走,我为两位特意约了秋云姑娘来见面”,   夏娃听见了,怂恿暗恋秋云的书痴快去追,此时不追,更待何时?难道要等鸳鸯各自飞? 记住后,每按一个键,都得停顿几秒,不过熟悉了字母和声韵母之间的对应关系。 双拼练习网站推荐: https://linci.co/sp/ 

初识PAM

Pluggable Authentication Modules for Linux 可插拨认证模块 用户访问服务器,服务程序将请求发送至PAM模块

The Three Faces Of Steve Jobs, Brent Schlender, 1998 Fortune

(FORTUNE Magazine) – Well into the conversation with FORTUNE that you're about to read, Steve Jobs, the once and interim CEO of Apple Computer, professes to feel, at the wizened age of 43, no different from when he was a frisky 17-year-old. True to form, he contradicts himself a little later, confessing to be "an old man now." Those comments reveal as much about why Jobs has been able to pull off his prestidigital revival of Apple--his first and still greatest creation--as do his observations on his business strategies and actions of the past year. Here's why. Jobs is most effective as a businessman and leader when he invokes the pathos and gestalt of his generation. He is, after all, a child of the 1960s--you're still likely to find him barefoot in the office, and for breakfast he eats granola doused in apple juice. Yet Jobs is also a mature baby-boomer, with an impressive if offbeat store of business experience, plus the typical worries that go with...