在 Redhat / CentOS Linux 中安装 iptables 防火墙

如何在 Redhat (RHEL) 或者 CentOS 或者 Fedora Linux 发行版中安装 iptables 呢?多数 Linux 发行版包括 Redhat / CentOS / Fedora 都默认安装了 iptables。这基本上是所有发行版本的标准做法了。

很有可能服务器,或者个人电脑,或者 VPS 中已经有了 iptables。如果不确定的话可以通过下面的方法来检查 iptables 是否已经安装。

打开一个终端窗口(类似 Windows 中所谓的命令行窗口),或者使用 SSH 客户端登录到远程服务器或 VPS。确保使用的用户具有 root 权限。输入以下命令:

iptables

或者针对 IPv6 来说,输入:

ip6tables

得到的输入类似于:

ip6tables v1.4.7: no command specified
Try `ip6tables -h' or 'ip6tables --help' for more information.

如果 iptables 已经正确安装,应该就可以得到上面的输出信息。其中 v1.4.7 是当前 iptables 的版本号。还可以通过下面的命令查看 iptables 命令的详细信息:

yum info iptables

输出类似于:

Loaded plugins: fastestmirror, presto
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * epel: mirrors.ustc.edu.cn
 * extras: mirror.bit.edu.cn
 * remi: rpms.famillecollet.com
 * updates: mirror.bit.edu.cn
Installed Packages
Name        : iptables
Arch        : i686
Version     : 1.4.7
Release     : 5.1.el6_2
Size        : 702 k
Repo        : installed
From repo   : updates
Summary     : Tools for managing Linux kernel packet filtering capabilities
URL         : http://www.netfilter.org/
License     : GPLv2
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 install this package.

如果没有出现上面的信息,那就需要安装了。输入下面的命令来安装 iptables:

yum install iptables

现在 iptables 安装包中已经包含有针对 IPv6 的 ip6tables 了,所以这样就可以了。安装完之后可以通过下面的命令来将 iptables 加入开机自动运行的服务中:

/sbin/chkconfig --levels 23456 iptables on

不过这只是自动启动针对 IPv4 的 iptables 了。要启动针对 IPv6 的 ip6tables,还需要再运行命令:

/sbin/chkconfig --levels 23456 ip6tables on

如果要禁止它们开机自动启动,只需要将上面命令中的 on 改为 off 即可。

当然仅仅安装了还不行,还需要进行配置。这个就见仁见智了。如果是自家用的 VPS,我的 VPS 安全策略中的 iptables 配置可以供参考一二。©

本文发表于水景一页。永久链接:<http://cnzhx.net/blog/iptable-installation-redhat-centos-rhel-fedora/>。转载请保留此信息及相应链接。

4 条关于 “在 Redhat / CentOS Linux 中安装 iptables 防火墙” 的评论

  1. 引用通告: CentOS / Redhat 上的 Iptables 防火墙配置简介 | 水景一页

时间过去太久,评论已关闭。
如果您有话要说,请到讨论区留言并给出此文章链接。
谢谢您的理解 :-)