netfilter/iptables系統的安裝
安裝netfilter/iptables 系統:
因為 netfilter/iptables 的 netfilter 組件是與內核 2.4.x 集成在一起的,所以只需要下載并安裝 iptables 用戶空間工具。
需求
下面是安裝 netfilter/iptables 系統的需求:
硬件:要使用 netfilter/iptables,需要有一個運行 Linux OS 并連接到因特網、LAN 或 WAN 的系統。
軟件:帶有內核 2.4 或更高版本的任何版本的 Linux OS。可以從 http://www.kernel.org 下載最新版本的內核。還需要從 http://www.netfilter.org 下載 iptables 這個用戶空間工具,因為這個工具不是內核的一部分。但對于 RedHat Linux 版本 7.1 或更高版本,不需要下載此工具,因為在版本 7.1 或更高版本中,標準安裝中已經包含了此工具。
用戶:至少對 Linux OS 有中等水平的了解,以及具備配置 Linux 內核的經驗。
安裝前的準備
在開始安裝 iptables 用戶空間工具之前,需要對系統做某些修改。首先,需要使用 make config 命令來配置內核的選項。在配置期間,必須通過將 CONFIG_NETFILTER 和 CONFIG_IP_NF_IPTABLES 選項設置為 Y 來打開它們,因為這是使 netfilter/iptables 工作所必需的。下面是可能要打開的其它選項:
CONFIG_PACKET : 如果要使應用程序和程序直接使用某些網絡設備,那么這個選項是有用的。
CONFIG_IP_NF_MATCH_STATE : 如果要配置 有狀態的防火墻,那么這個選項非常重要而且很有用。這類防火墻會記得先前關于信息包過濾所做的決定,并根據它們做出新的決定。我將在 netfilter/iptables 系統的優點一節中進一步討論這方面的問題。
CONFIG_IP_NF_FILTER : 這個選項提供一個基本的信息包過濾框架。如果打開這個選項,則會將一個基本過濾表(帶有內置的 INPUT 、 FORWARD 和 OUTPUT 鏈)添加到內核空間。
CONFIG_IP_NF_TARGET_REJECT : 這個選項允許指定:應該發送 ICMP 錯誤消息來響應已被 DROP 掉的入站信息包,而不是簡單地殺死它們。
現在,可以準備安裝這個用戶空間工具了。
安裝用戶空間工具
在下載 iptables 用戶空間工具的源代碼(它類似于 iptables-1.2.6a.tar.bz2)之后,可以開始安裝。您需要以 root 身份登錄來執行安裝。 清單 1 給出了一個示例,它指出了安裝該工具所需的命令、其必要的次序及其說明。
清單 1. 用戶空間工具安裝的示例
- 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 或更高版本,就不需要執行這里說明的前兩個步驟。正如我們所知道的,該 Linux 分發版(distribution)的標準安裝中包含了 iptables 用戶空間工具。但在缺省情況下,這個工具是關閉的。為了使該工具運行,需要執行以下步驟( 清單 2):
清單 2. 在 RedHat 7.1 系統上設置用戶空間工具的示例
- 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.
現在,一切都已妥當,并且 netfilter/iptables 系統應該正在運行,接下來(下一節講述),需要建立規則和鏈來過濾信息包。
【編輯推薦】