netfilter/iptables系统的安装

运维 系统运维
netfilter/iptables系统的安装:在Linux中,提供了一个非常优秀的防火墙工具netfilter/iptables。netfilter/iptables是完全免费的,而且功能强大,使用灵活。netfilter/iptables可以对流入和流出的信息进行细化控制,且可以在一台低配置机器上很好地运行。本文讲述的是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. 用户空间工具安装的示例

  1.   First, unpack the tool package into a directory:  
  2.  
  3.   # bzip2 -d iptables-1.2.6a.tar.bz2  
  4.  
  5.   # tar -xvf iptables-1.2.6a.tar  
  6.  
  7.   This will unpack the tool source into a directory named iptables-1.2.6a.  
  8.  
  9.   Now change to the iptables-1.2.6a directory:  
  10.  
  11.   # cd iptables-1.2.6a  
  12.  
  13.   The INSTALL file in this directory contains a lot of useful information  
  14.  
  15.   on compiling and installing this tool.  
  16.  
  17.   Now compile the userspace tool using the following command:  
  18.  
  19.   # make KERNEL_DIR=/usr/src/linux/  
  20.  
  21.   Here the KERNEL_DIR=/usr/src/linux/ specifies the path to the kernel's  
  22.  
  23.   directory. If the directory of kernel happens to be different on some  
  24.  
  25.   systems, the appropriate directory path should be substituted for  
  26.  
  27.   /usr/src/linux.  
  28.  
  29.   Now install the source binaries using the following command:  
  30.  
  31.   # make install KERNEL_DIR=/usr/src/linux/  
  32.  
  33.   Now the installation is complete.  
  34.  

  注:如果您有 RedHat Linux 版本 7.1 或更高版本,就不需要执行这里说明的前两个步骤。正如我们所知道的,该 Linux 分发版(distribution)的标准安装中包含了 iptables 用户空间工具。但在缺省情况下,这个工具是关闭的。为了使该工具运行,需要执行以下步骤( 清单 2):

  清单 2. 在 RedHat 7.1 系统上设置用户空间工具的示例

  1.   First you'll have to turn off the old ipchains module (predecessor of  
  2.  
  3.   iptables) available in this OS package.  
  4.  
  5.   This can be done using the following command:  
  6.  
  7.   # chkconfig --level 0123456 ipchains off  
  8.  
  9.   Next, to completely stop the ipchains module from running, so that it  
  10.  
  11.   doesn't conflict with the iptables tool, you will have to stop the ipchains  
  12.  
  13.   service using the following command:  
  14.  
  15.   # service ipchains stop  
  16.  
  17.   Now if you don't want to keep this old ipchains module on your system,  
  18.  
  19.   uninstall it using the following command:  
  20.  
  21.   # rpm -e ipchains  
  22.  
  23.   Now you can turn on the iptables userspace tool with the following command:  
  24.  
  25.   # chkconfig --level 235 iptables on  
  26.  
  27.   Finally, you'll have to activate the iptables service to make the userspace  
  28.  
  29.   tool work by using this command:  
  30.  
  31.   # service iptables start  
  32.  
  33.   Now the userspace tool is ready to work on a RedHat 7.1 or higher system.  
  34.  

  现在,一切都已妥当,并且 netfilter/iptables 系统应该正在运行,接下来(下一节讲述),需要建立规则和链来过滤信息包

【编辑推荐】

Linux下Iptables防火墙的使用

iptables简介与安装命令

Squid+iptables代理配置

责任编辑:zhaolei 来源: IBM
相关推荐

2011-03-15 15:47:34

netfilteriptables

2011-03-15 12:47:11

netfilteriptables

2011-03-15 15:51:12

netfilteriptables

2011-03-15 15:47:26

netfilteriptables

2011-03-15 10:00:01

NetfilterIPTables

2021-04-14 20:10:50

Netfileter Iptables 源码

2011-03-15 09:10:43

iptables防火墙

2010-12-07 09:51:43

Linux安全性netfilteriptables

2011-03-15 10:48:47

2011-03-15 09:59:54

2011-03-15 09:59:54

2011-07-05 14:34:23

2011-07-13 10:30:09

2022-10-27 20:31:19

iptablesnetfilter

2011-03-14 15:12:27

iptables安装

2011-03-15 15:47:25

iptables安装命令

2011-03-15 16:12:45

iptablesRed Hat

2011-03-18 09:26:13

Iptables规则

2018-10-10 10:37:03

2011-03-16 11:17:56

IptablesICMP
点赞
收藏

51CTO技术栈公众号