跳至主要内容

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

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

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

CAD 天正与 AI 工作流

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

进入双拼的世界

──小鹤双拼官方记忆口诀诗一首 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/ 

世界需要什么样的智能系统

原文: - By 道哥 - Link:https://archive.ph/h0nNj  笔记: - 人工智能,不应该是一个产业,应该是各个产业,都要有智能; - 智能:感知+行动 (目前很多视觉、语音的识别,停留在感知层面) - 智能技术角度看, 自动驾驶与智能音箱是两个完整的从“感知”到“行动”的闭环     - 对话机器人被成为人工智能界的圣杯 - 构建智能时代:     - 飞行员:各个企业中,智能部门的员工     - 航道:基础设施提供商,比如运营商、云计算厂商     - 机场:最后真正的商业模式,类似苹果的App Store,给机器智能系统提供服务 - 机器与机器的协同交互,价值巨大(以往很看重的是:机器与人的交互) - 数据、训练在内部;一旦进行外部的机器交流,默认为“不信任”模式 - 云计算厂商可能会被智能厂商管道化,就跟运营商被互联网内容提供商管道化一样(因为:云计算和大数据都不是智能)

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

BG投资十问(Baillie Gifford)

  1,公司是否能正面推动经济、社会或者文化发 展? 如果做不到,BG可能就不会再往下看了。比如军火、赌博类公司再便宜,BG不会去看。 2,公司销售额在5年之内能否翻倍? 为什么要讨论销售额?因为BG关注公司成长,销售额是比较简单直观的指标,而利润可有一些方法调节。所以,BG主要先关注销售额,再看现金流。 3,公司5年之后会怎么样? 这是未来5到10年或者5到15年的中间维度,一是看公司的成长空间究竟还有多大,二是考虑5年之后,公司的短期估值会不会下降,会不会变得成熟。 4,公司的竞争优势到底是什么?随着时间会变 强还是变弱? BG认为,如果公司的竞争优势是不断变弱的,将来在更远期挣回现金流的可能性就更低了。 5,公司是否有非常独特的文化?文化是否能够进化? 毕竟要投资这么长时间,对创始人和公司管理文化是非常关注的。特别喜欢创始人领导的公司,而不是说创始人什么都不干,创始人在做房地产,找了一些人在做新公司,要尽量避免这样的公司。 谈到进化在BG看来,大部分公司都会有大公司病,需要看它怎么能维持比较灵活的管理,变大之后还能够保持非常快速的成长,比如亚马逊的day one文化(注:就是始终处在 创业启动状态,充满迷茫和压力,但是充满创造力和颠覆思想 )。 6,公司过去的回报率怎么样? 一方面是考虑到公司的ROE(净资产收益率),二是考虑公司的Margins(利润),看它的过去是不是值得投资,如果每年ROE都不到10个点,可能长期来看也没什么意思。 7,ROE能不能随着时间增长? 有些公司一开始没有盈利,一直在烧钱,5年之后说不定ROE会到20%或者更高,它是一个动态过程。这样的公司BG也会投资,包括一些早期项目,很多公司都是没有盈利的。 8,公司怎么分配资本? 资本现金流无非就是5种方法:再投资、收购、还债、分红、回购股份,要看公司在某个阶段的资本分配是不是最优的。 如果公司明明可以发展更多,结果乱分红了;或者是明明到了特别成熟的时候,还不愿意分红,都是错误的分配资本。 9,公司怎样才能长成5倍? BG关注的是怎样,而不是能不能。这会强迫BG每个人去设想一些未来的可能性,包括公司现在的底层架构能不能够延伸到更多的业务。 比如,早期的亚马逊或者是阿里,连一个概念都没有,BG会考虑这个公司有没有这种机遇,以后去扩展到可触及的市场。 10,市场对公司有哪些误解,哪些事...