跳至主要内容

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...

ASC代理中国的拉菲+奔富

1)ASC是之前拉菲、奔富的中国独家代理商 2)2019年,拉菲不再由ASC独家代理,分拆成四家 3)奔富:澳洲品牌红酒──奔富酒庄最好的酒是澳洲酒王 4)奔富的包装、取名、型号代称、代理分销方式(高级到低级) 是一个很好的营销案例; 5)奔富的口感,因为酒精浓度高,偏向于白酒的口味,收到商务人士、土豪老板的追捧,因此有爆发的潜能 To Do: 1) ASC旗舰店,观察销量情况 Update: 1)越来越有趣了,依云水的代理商也是ASC

产品随想 | 周刊 第104期:Exceptional people are built in solitude

HIDDEN HEROES   https://hiddenheroes.netguru.com/ 那些不为人知的网络名人 Richard Saul Wurman   https://en.wikipedia.org/wiki/Richard_Saul_Wurman?useskin=vector TED的创始人,也是一位建筑师!!! The Magic Cookie: How Lou Montulli cured the Web’s amnesia   https://hiddenheroes.netguru.com/lou-montulli Truth is incontrovertible. Panic may resent it. Ignorance may deride it. Malice may distort it. But there it is. - Winston Churchill The man who finds his homeland sweet is still a tender beginner; he to whom every soil is as his native one is already strong; but he is perfect to whom the entire world is as a foreign land. - Hugo of Saint Victor Heal the boy, and the man will appear. The only thing we can truly control is where we place our attention and where we place our effort. Choose wisely. - Dr. Andrew Huberman It’s becoming easier and easier to be social, but exceptional people are built in solitude. - Naval 看到这句话,我第一个想到的就是乔布斯 Listening to Taylor Swift in Prison,Her music makes me feel that I’m ...

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  嵌面

罗伯特·艾格 创始人肖像计划 <​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中的实时上色功能去了解