跳至主要内容

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 产品随想的博客

产品随想 | 陪读《乔布斯传》:1-17章

乔布斯经典照片集 坐在麗莎電腦旁。他說:「毕加索曾說:「好的藝術家懂得模仿,佛大的藝術家善於偷取。」因此,窃取偉大的點子沒有什麼好羞耻的。 與蓋茲在電話中達成協議:「比爾,謝謝你支持蘋果。因為你的支持,世界將變得更美好。」 1997年蘋果在波士頓舉行的麥金塔世界大會,蓋茲透過衛星連線在巨大的螢幕上出現。質伯斯說:「我真是笨死了,竟然讓蓋兹以這種方式現身。他讓我看起來好沙小。」 ──时刻自省 前言 The people who are crazy enough to think they can change the world are the ones who do. 只有那些瘋狂到以為自己可以改變世界的人, 才能改變這個世界。 這麼些年來,賈伯斯說起話來的認真與專注態度,著實打動不少人。我們一直保持連絡,即使在他被逐出蘋果之後,我們還有來往。每次他有新產品要推出時,像 NeXT 電腦或皮克斯 (Pixar)的電影,他就會來找我。他常帶我去曼哈頓下城一家壽司店用餐,講起他的產品,渾身散發出光和熱,眉飛色舞的說這是他登峰造極之作。我喜歡這個人。 ──对自己产品深深的爱 他的堅持教我疑惑。人人都知道賈伯斯不道餘力捍衛隱私, 而且我不知道他是否看過我寫的任何一本傳記。我還是不敢立刻答應,只說或許再等等。然而到了 2009年,我接到他太太蘿琳. 鮑威爾打來的電話。她直截了當說:「如果你還想為史帝夫寫傳,最好趕快動筆。」這是他第二次因病向公司請長假。我坦言他早在2004 年得知自己罹患胰臟癌的時候就曾主動邀我寫傳,但我當時對他罹癌的事一無所知。蘿琳解釋說,他們盡量保密,因此當時根本沒幾個人知道。他是在動手術的前夕打電話給我的。 ──和Make Something Wonderful对照起来看 他還說,自從他回到蘋果重新掌權,這十二年來是他創造新產品的高峰期,但他還有更重要的目標,也就是效法惠普的惠立和普克(David Packard),締造一家創新動力無限的公司,進而超越惠普。 ──苹果公司才是乔布斯最得意的产品 他說:「我一直認為,自己是個偏向人文的孩子,但我也喜歡電子的東西。後來,我讀到寶麗來(Polaroid)創辦人蘭德 (Edwin Land)曾說過,一個人能站在人文和科學的交會口,兼容贯通,才是真正的人才。在那當下,我决定要當這樣的人。」他似乎在暗示我,這可以做為傳...

产品随想 | 周刊 第63期:中国城市化的历史思考

Products 李志 · BB   https://github.com/turkyden/lizhi-app 开箱即用,一个珍藏了李志音乐作品集的在线播放器 作者的描述很有意思:我们不能失去信仰~ Watt Toolkit 🧰 (原名 Steam++)   https://github.com/BeyondDimension/SteamTools 「Watt Toolkit」是一个开源跨平台的多功能游戏工具箱,此工具的大部分功能都是需要您下载安装 Steam 才能使用。 语雀为什么没被钉钉吃掉,跟支付宝又是什么关系?   https://www.xiaoyuzhoufm.com/episode/62ed2b1d226f5c1fa0d58357 乱翻书播客推荐 Behind the Curtain   https://www.quiverquant.com/sources/behind-the-curtain/ 我们正在结合我们一直在收集的关于公司游说、国会股票交易和拟议立法的数据,以便让您跟踪华盛顿特区幕后发生的事情您可以使用此工具查看哪些法案正在被国会审议了哪些上市公司正在就这些法案进行游说,以及哪些国会议员交易了这些公司的股票。 民主非常需要这样的信息透明 脑洞大开,给自行车装上倒车雷达和行车记录仪   https://sspai.com/post/73521 佳明-骑行雷达尾灯 Varia RCT 715,非常喜欢,但真的好贵.....3K+ RMB Health 体检报告出现高尿酸,你该如何在饮食方面控制风险?   https://sspai.com/post/73031 Citizenship Consciousness & Privacy 张鸣:中国城市化的历史思考 2019 09 04   https://www.youtube.com/watch?v=rRcPssCkXeI 内核论点是:城市化最重要的有私有产权的商人 这个创作者也值得关注 Run 日本移居指南   https://guoyu.mirror.xyz/bPaDKAcrhJGUbaXu9BWDcdD-F46gBFATTvf_qwZ9Bso 添加加Run模块,润 A Programmer's Guid...

Steve Jobs at 44, By Michael Krantz, 1999

Differences and Similarities Between Apple and Pixar Apple turns out many products--a dozen a year; if you count all the minor ones, probably a hundred. Pixar is striving to turn out one a year. But the converse of that is that Pixar's products will still be used fifty years from now, whereas I don't think you'll be using any product Apple brings to market this year fifty years from now. Pixar is making art for the ages. Kids will be watching Toy Story in the future. And Apple is much more of a constant race to continually improve things and stay ahead of the competition.  His Role At Pixar At Pixar my job is to help build the studio and recruit people and help create a situation where they can do the best work of their lives. And to some degree it's the same at Apple. But at Pixar, I don't direct the movies, whereas at Apple probably, if I had to pick a role out of a film production, I'd be the director. So it...

零碎思考 | 關於LLM的閱讀筆記

  通向AGI之路:大型语言模型(LLM)技术精要   https://zhuanlan.zhihu.com/p/597586623 拆解追溯 GPT-3.5 各项能力的起源   https://yaofu.notion.site/GPT-3-5-360081d91ec245f29029d37b54573756 清晰明瞭 A Closer Look at Large Language Models Emergent Abilities   https://yaofu.notion.site/A-Closer-Look-at-Large-Language-Models-Emergent-Abilities-493876b55df5479d80686f68a1abd72f 試圖說明LLM的涌現能力] 如何利用GPT-4打造高效智能信息收集神器   https://lpcv.org/fwc/a/MzU0MDk3NTUxMA==/2247483868/1 學習思路 GPT-4编码教程,如何用AI构建和宣传我的Midjourney网站增强插件   https://op7418.zhubai.love/posts/2254193381183922176 AUTOMATIC1111 GUI: A Beginner’s Guide   https://stable-diffusion-art.com/automatic1111/ 其實就是AI界的雲渲染,挺有意思的 Midjourney还是Stable Diffusion: 你应该选哪个?   https://zhuanlan.zhihu.com/p/617157677 看到作者下方的“註冊會計師”,中國太卷了 树莓派4B刷OpenWrt做路由器的经验+踩坑   https://zhuanlan.zhihu.com/p/451788328 關注其中的坑點 doc.openwrt.cc   https://doc.openwrt.cc/

关于建筑实习的经验贴

慢慢整理实习的帖子,如果近期太阳能竞赛不占用太多时间的话,可以开始准备实习了 一.  给自己的问题   1. 你的设计风格是什么   2. 实习的目的 二. 事务所推荐   1. 墨臣,住宅(商业地产)做的很棒,项目管理做的比较好,但是相对来说公建项目比较少       如果希望接触多种类型项目的话考虑一下,多多了解这个事务所,赖军   2. 标准营造,张珂,重视方案设计的惊喜把控,重视图解,还有手工模型   3. 大舍,不浮夸,有自己的设计理念,效率高,唯一不加班公司 三. 学院派建筑师   1. 何镜堂事务所,缺点是周期长,待遇不高,风格单一,设计类型单一   2.  直向(新史家小学,方法上典型霍尔的风格,董功是霍尔弟子)       TAO迹(腾冲的那个博物馆不错)       山水秀(祝晓峰的风格很小清新,朱家角的房子)       业余       家琨(在符合本时代的建筑材料的运用上很有造诣,再生砖,鹿野苑....)       非常(张永和,作品说不出来有多好,但是又总觉得很精妙,二分宅) 四. 设计院   1. 商业建筑设计公司实习推荐  CCDI,DC,UA   2.  大连院,东北院,华东院,中建北京院   3. 不推荐同济院,因为挂靠的小公司很多,鱼龙混杂 五. 先锋派建筑师   1. UNStudio,项目比扎哈的脚踏实地而且思考深度高很多   2. BIG,设计的起源都是一个平淡朴实但是又很精妙的理由   3. 蓝天组   4. 国内事务所推荐  李虎(霍尔的合伙人)的open,侯梁(貌似的是玛雅,不知道用rhino和       GH),徐东昕,徐甜甜的DNA,徐卫国(感觉这老爷子在国内参数化设计界可以呼风唤       雨了)   5. 不推...

一些建筑类书刊

这是我在知乎上的一个回答,之前看到一个说法,就是越厉害的人不仅仅是吸收知识,即输入,同时也会最大化的输出,输出的方式我认为有很多,写书,写博客等等,我选择的输出方式是在知乎,豆瓣留下自己的足迹,博客是我的大本营,在这里mark一下我在知乎一个关于建筑书籍的回答

产品随想 | 周刊 第115期:2024.5.16 Great libraries build communities

Loop   https://github.com/MrKai77/Loop Loop is a macOS app that simplifies window management for you! 我的电视 my-tv   https://github.com/lizongying/my-tv 我的电视 电视直播软件,安装即可使用 When we think about this technology, we need to put human dignity, human well-being—human jobs—in the center of consideration. ————Fei-Fei Li Author Talks: Dr. Fei-Fei Li sees ‘worlds’ of possibilities in a multidisciplinary approach to AI   https://www.mckinsey.com/featured-insights/mckinsey-on-books/author-talks-dr-fei-fei-li-sees-worlds-of-possibilities-in-a-multidisciplinary-approach-to-ai Randy Ubillos   https://apple.fandom.com/wiki/Randy_Ubillos Randall Hayes "Randy" Ubillos is the original software engineer behind Adobe Premiere and Final Cut Pro. 影响全球视频制作的男人, Reminders MenuBar   https://github.com/DamascenoRafael/reminders-menubar Simple macOS menu bar application to view and interact with reminders. Developed with SwiftUI and using Apple Reminders as a source. Bad libraries build colle...

《Becoming Steve Jobs》Chapter 13 Stanford

Steve was a natural performer who elevated business presentations to something close to high art. But what made him fidgety this day was the prospect of addressing the Stanford University graduating class of 2005. University president John Hennessy had broached the idea several months earlier, and after taking just a little time to think it over, Steve had said yes. He was offered speaking engagements constantly, and he always said no. In fact, he was asked to do so many commencement addresses that it became a running joke with Laurene and other friends who had college or graduate degrees: Steve said he’d accept one just to make an end run around them and get his PhD in a day, versus the years and years it had taken them. But in the end, saying no was simply a question of return on investment—conferences and public speaking seemed to offer a meager payoff compared to other things, like a dazzling MacWorld presentation, working on a great product, or being around his family. “If you loo...

产品随想 | 周刊 第99期:Organize the world's information and make it universally accessible and useful.

MIST   https://github.com/ninxsoft/Mist A Mac utility that automatically downloads macOS Firmwares / Installers. Google's mission is to organize the world's information and make it universally accessible and useful. Google策略是搜索来驱动世界信息 而字节是推荐来驱动世界信息,某个意义上来说,字节是Google的继承者 Reflecting on 18 years at Google   https://ln.hixie.ch/?start=1700627373&count=1 Google的吐槽,哈哈哈 The Little Kernel Embedded Operating System   https://github.com/littlekernel/lk The LK kernel is an SMP-aware kernel designed for small systems ported to a variety of platforms and cpu architectures. 在软件行业越久,就越对操作系统这颗皇冠,感到着迷 ArchiveOS   https://archiveos.org/ 致敬那些存在过的操作系统们 Travis Geiselbrecht   https://tkgeisel.com/ 世界级的操作系统工程师 每一个项目都赫赫有名 一生都在做操作系统 Hiddify-Next   https://github.com/hiddify/hiddify-next A multi-platform auto-client based on Sing-box that serves as a universal proxy tool-chain. This app offers a wide range of capabilities, which are listed below. It also supports a large number ...

Markdown学习笔记

学习帖来自简书,这是我的笔记, 献给作者的Markdown新手指南 # 一级标题    #数量决定标题层级 - 文本    列表格式