netfilter/iptables系統(tǒng)的安裝
安裝netfilter/iptables 系統(tǒng):
因?yàn)?netfilter/iptables 的 netfilter 組件是與內(nèi)核 2.4.x 集成在一起的,所以只需要下載并安裝 iptables 用戶(hù)空間工具。
需求
下面是安裝 netfilter/iptables 系統(tǒng)的需求:
硬件:要使用 netfilter/iptables,需要有一個(gè)運(yùn)行 Linux OS 并連接到因特網(wǎng)、LAN 或 WAN 的系統(tǒng)。
軟件:帶有內(nèi)核 2.4 或更高版本的任何版本的 Linux OS??梢詮?http://www.kernel.org 下載最新版本的內(nèi)核。還需要從 http://www.netfilter.org 下載 iptables 這個(gè)用戶(hù)空間工具,因?yàn)檫@個(gè)工具不是內(nèi)核的一部分。但對(duì)于 RedHat Linux 版本 7.1 或更高版本,不需要下載此工具,因?yàn)樵诎姹?7.1 或更高版本中,標(biāo)準(zhǔn)安裝中已經(jīng)包含了此工具。
用戶(hù):至少對(duì) Linux OS 有中等水平的了解,以及具備配置 Linux 內(nèi)核的經(jīng)驗(yàn)。
安裝前的準(zhǔn)備
在開(kāi)始安裝 iptables 用戶(hù)空間工具之前,需要對(duì)系統(tǒng)做某些修改。首先,需要使用 make config 命令來(lái)配置內(nèi)核的選項(xiàng)。在配置期間,必須通過(guò)將 CONFIG_NETFILTER 和 CONFIG_IP_NF_IPTABLES 選項(xiàng)設(shè)置為 Y 來(lái)打開(kāi)它們,因?yàn)檫@是使 netfilter/iptables 工作所必需的。下面是可能要打開(kāi)的其它選項(xiàng):
CONFIG_PACKET : 如果要使應(yīng)用程序和程序直接使用某些網(wǎng)絡(luò)設(shè)備,那么這個(gè)選項(xiàng)是有用的。
CONFIG_IP_NF_MATCH_STATE : 如果要配置 有狀態(tài)的防火墻,那么這個(gè)選項(xiàng)非常重要而且很有用。這類(lèi)防火墻會(huì)記得先前關(guān)于信息包過(guò)濾所做的決定,并根據(jù)它們做出新的決定。我將在 netfilter/iptables 系統(tǒng)的優(yōu)點(diǎn)一節(jié)中進(jìn)一步討論這方面的問(wèn)題。
CONFIG_IP_NF_FILTER : 這個(gè)選項(xiàng)提供一個(gè)基本的信息包過(guò)濾框架。如果打開(kāi)這個(gè)選項(xiàng),則會(huì)將一個(gè)基本過(guò)濾表(帶有內(nèi)置的 INPUT 、 FORWARD 和 OUTPUT 鏈)添加到內(nèi)核空間。
CONFIG_IP_NF_TARGET_REJECT : 這個(gè)選項(xiàng)允許指定:應(yīng)該發(fā)送 ICMP 錯(cuò)誤消息來(lái)響應(yīng)已被 DROP 掉的入站信息包,而不是簡(jiǎn)單地殺死它們。
現(xiàn)在,可以準(zhǔn)備安裝這個(gè)用戶(hù)空間工具了。
安裝用戶(hù)空間工具
在下載 iptables 用戶(hù)空間工具的源代碼(它類(lèi)似于 iptables-1.2.6a.tar.bz2)之后,可以開(kāi)始安裝。您需要以 root 身份登錄來(lái)執(zhí)行安裝。 清單 1 給出了一個(gè)示例,它指出了安裝該工具所需的命令、其必要的次序及其說(shuō)明。
清單 1. 用戶(hù)空間工具安裝的示例
- First, unpack the tool package into a directory:
- # bzip2 -d iptables-1.2.6a.tar.bz2
- # tar -xvf iptables-1.2.6a.tar
- This will unpack the tool source into a directory named iptables-1.2.6a.
- Now change to the iptables-1.2.6a directory:
- # cd iptables-1.2.6a
- The INSTALL file in this directory contains a lot of useful information
- on compiling and installing this tool.
- Now compile the userspace tool using the following command:
- # make KERNEL_DIR=/usr/src/linux/
- Here the KERNEL_DIR=/usr/src/linux/ specifies the path to the kernel's
- directory. If the directory of kernel happens to be different on some
- systems, the appropriate directory path should be substituted for
- /usr/src/linux.
- Now install the source binaries using the following command:
- # make install KERNEL_DIR=/usr/src/linux/
- Now the installation is complete.
注:如果您有 RedHat Linux 版本 7.1 或更高版本,就不需要執(zhí)行這里說(shuō)明的前兩個(gè)步驟。正如我們所知道的,該 Linux 分發(fā)版(distribution)的標(biāo)準(zhǔn)安裝中包含了 iptables 用戶(hù)空間工具。但在缺省情況下,這個(gè)工具是關(guān)閉的。為了使該工具運(yùn)行,需要執(zhí)行以下步驟( 清單 2):
清單 2. 在 RedHat 7.1 系統(tǒng)上設(shè)置用戶(hù)空間工具的示例
- First you'll have to turn off the old ipchains module (predecessor of
- iptables) available in this OS package.
- This can be done using the following command:
- # chkconfig --level 0123456 ipchains off
- Next, to completely stop the ipchains module from running, so that it
- doesn't conflict with the iptables tool, you will have to stop the ipchains
- service using the following command:
- # service ipchains stop
- Now if you don't want to keep this old ipchains module on your system,
- uninstall it using the following command:
- # rpm -e ipchains
- Now you can turn on the iptables userspace tool with the following command:
- # chkconfig --level 235 iptables on
- Finally, you'll have to activate the iptables service to make the userspace
- tool work by using this command:
- # service iptables start
- Now the userspace tool is ready to work on a RedHat 7.1 or higher system.
現(xiàn)在,一切都已妥當(dāng),并且 netfilter/iptables 系統(tǒng)應(yīng)該正在運(yùn)行,接下來(lái)(下一節(jié)講述),需要建立規(guī)則和鏈來(lái)過(guò)濾信息包。
【編輯推薦】