Linux 防火墙的基本认识
Linux 防火墻的基本認(rèn)識
2.1 Netfilter
Linux防火墻是由Netfilter組件提供的,Netfilter工作在內(nèi)核空間,集成在linux內(nèi)核中
Netfilter 是Linux2.4.x之后新一代的Linux防火墻機(jī)制,是linux內(nèi)核的一個子系統(tǒng)。Netfilter采用模塊化設(shè)計,具有良好的可擴(kuò)充性,提供擴(kuò)展各種網(wǎng)絡(luò)服務(wù)的結(jié)構(gòu)化底層框架。Netfilter與IP協(xié)議棧是無縫契合,并允許對數(shù)據(jù)報進(jìn)行過濾、地址轉(zhuǎn)換、處理等操作
Netfilter官網(wǎng)文檔:https://netfilter.org/documentation/
2.2 防火墻工具介紹
2.2.1 iptables
由軟件包iptables提供的命令行工具,工作在用戶空間,用來編寫規(guī)則,寫好的規(guī)則被送往netfilter,告訴內(nèi)核如何去處理信息包
[root@centos8 ~]#rpm -qi iptables Name : iptables Version : 1.8.2 Release : 9.el8 Architecture: x86_64 Install Date: Wed 25 Sep 2019 09:29:06 PM CST Group : Unspecified Size : 2050086 License : GPLv2 and Artistic 2.0 and ISC Signature : RSA/SHA256, Tue 02 Jul 2019 06:50:00 AM CST, Key ID 05b555b38483c65d Source RPM : iptables-1.8.2-9.el8.src.rpm Build Date : Sat 11 May 2019 10:21:57 PM CST Build Host : x86-01.mbox.centos.org Relocations : (not relocatable) Packager : CentOS Buildsys <bugs@centos.org> Vendor : CentOS URL : http://www.netfilter.org/ Summary : Tools for managing Linux kernel packet filtering capabilities Description : The iptables utility controls the network packet filtering code in the Linux kernel. If you need to set up firewalls and/or IP masquerading, you should either install nftables or this package.Note: This package contains the nftables-based variants of iptables and ip6tables, which are drop-in replacements of the legacy tools.[root@centos8 ~]# iptables --version iptables v1.8.2 (nf_tables) [root@centos8 ~]#ll /usr/sbin/iptables lrwxrwxrwx. 1 root root 17 May 11 2019 /usr/sbin/iptables -> xtables-nft-multi[root@centos7 ~]#ll /usr/sbin/iptables lrwxrwxrwx. 1 root root 13 Dec 9 2018 /usr/sbin/iptables -> xtables-multi [root@centos7 ~]# iptables --version iptables v1.4.21[root@centos6 ~]#iptables --version iptables v1.4.7 [root@centos6 ~]#ll /sbin/iptables lrwxrwxrwx. 1 root root 33 Dec 12 2018 /sbin/iptables -> /etc/alternatives/iptables.x86_64 [root@centos6 ~]#ll /etc/alternatives/iptables.x86_64 lrwxrwxrwx. 1 root root 20 Dec 12 2018 /etc/alternatives/iptables.x86_64 -> /sbin/iptables-1.4.7 [root@centos6 ~]#ll /sbin/iptables lrwxrwxrwx. 1 root root 33 Dec 12 2018 /sbin/iptables -> /etc/alternatives/iptables.x86_64范例:安裝iptables的service包
[root@centos8 ~]#dnf -y install iptables-services [root@centos8 ~]#rpm -ql iptables-services /etc/sysconfig/ip6tables /etc/sysconfig/iptables /usr/lib/systemd/system/ip6tables.service /usr/lib/systemd/system/iptables.service /usr/libexec/initscripts/legacy-actions/ip6tables /usr/libexec/initscripts/legacy-actions/ip6tables/panic /usr/libexec/initscripts/legacy-actions/ip6tables/save /usr/libexec/initscripts/legacy-actions/iptables /usr/libexec/initscripts/legacy-actions/iptables/panic /usr/libexec/initscripts/legacy-actions/iptables/save /usr/libexec/iptables /usr/libexec/iptables/ip6tables.init /usr/libexec/iptables/iptables.init2.2.2 firewalld
從CentOS 7 版開始引入了新的前端管理工具
軟件包:
- firewalld
- firewalld-config
管理工具:
- firewall-cmd 命令行工具
- firewall-config 圖形工作
2.2.3 nftables
此軟件是CentOS 8 新特性,Nftables最初在法國巴黎的Netfilter Workshop 2008上發(fā)表,然后由長期的netfilter核心團(tuán)隊成員和項目負(fù)責(zé)人Patrick McHardy于2009年3月發(fā)布。它在2013年末合并到Linux內(nèi)核中,自2014年以來已在內(nèi)核3.13中可用。
它重用了netfilter框架的許多部分,例如連接跟蹤和NAT功能。它還保留了命名法和基本iptables設(shè)計的幾個部分,例如表,鏈和規(guī)則。就像iptables一樣,表充當(dāng)鏈的容器,并且鏈包含單獨的規(guī)則,這些規(guī)則可以執(zhí)行操作,例如丟棄數(shù)據(jù)包,移至下一個規(guī)則或跳至新鏈。
從用戶的角度來看,nftables添加了一個名為nft的新工具,該工具替代了iptables,arptables和ebtables中的所有其他工具。從體系結(jié)構(gòu)的角度來看,它還替換了內(nèi)核中處理數(shù)據(jù)包過濾規(guī)則集運行時評估的那些部分。
范例:查看軟件包
[root@centos8 ~]#rpm -qi nftables Name : nftables Epoch : 1 Version : 0.9.0 Release : 8.el8 Architecture: x86_64 Install Date: Wed 25 Sep 2019 09:29:06 PM CST Group : Unspecified Size : 758622 License : GPLv2 Signature : RSA/SHA256, Tue 02 Jul 2019 08:19:09 AM CST, Key ID 05b555b38483c65d Source RPM : nftables-0.9.0-8.el8.src.rpm Build Date : Sat 11 May 2019 11:06:46 PM CST Build Host : x86-01.mbox.centos.org Relocations : (not relocatable) Packager : CentOS Buildsys <bugs@centos.org> Vendor : CentOS URL : http://netfilter.org/projects/nftables/ Summary : Netfilter Tables userspace utillites Description : Netfilter Tables userspace utilities.范例:CentOS 8 支持三種防火墻工具
[root@centos8 ~]#systemctl status iptables.service ● iptables.service - IPv4 firewall with iptablesLoaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)Active: inactive (dead) [root@centos8 ~]#systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)Active: inactive (dead)Docs: man:firewalld(1) [root@centos8 ~]#systemctl status nftables.service ● nftables.service - Netfilter TablesLoaded: loaded (/usr/lib/systemd/system/nftables.service; disabled; vendor preset: disabled)Active: inactive (dead)Docs: man:nft(8)2.3 netfilter 中五個勾子函數(shù)和報文流向
Netfilter在內(nèi)核中選取五個位置放了五個hook(勾子) function(INPUT、OUTPUT、FORWARD、PREROUTING、POSTROUTING),而這五個hook function向用戶開放,用戶可以通過一個命令工具(iptables)向其寫入規(guī)則
由信息過濾表(table)組成,包含控制IP包處理的規(guī)則集(rules),規(guī)則被分組放在鏈(chain)上
提示:從 Linux kernel 4.2 版以后,Netfilter 在prerouting 前加了一個 ingress 勾子函數(shù)。可以使用這個新的入口掛鉤來過濾來自第2層的流量,這個新掛鉤比預(yù)路由要早,基本上是 tc 命令(流量控制工具)的替代品
本文鏈接:http://www.yunweipai.com/35043.html
總結(jié)
以上是生活随笔為你收集整理的Linux 防火墙的基本认识的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: containerd设置上网代理
- 下一篇: spark on yarn参数: 任务优