linux命令:编译安装iptables

简介:

如何编译安装iptables实例:

先卸载系统已经安装的iptables,卸载前需备份三个文档:iptables启动脚本,iptables-config配置文档,以及已经建立好的iptables规则文档

[root@johntest ~]# cp /etc/init.d/iptables ~/iptables  #复制iptables启动脚本

[root@johntest ~]# cp /etc/sysconfig/iptables-config  ~/  #复制iptables配置文档

[root@johntest ~]# cp /etc/sysconfig/iptables ~/iptables.rules#复制已建立的iptables规则文档


[root@johntest ~]# service iptables stop  #停止iptables服务

清除防火墙规则:                                        [确定]

把 chains 设置为 ACCEPT 策略:filter                           [确定]

正在卸载 Iiptables 模块:                                  [确定]

[root@johntest ~]# chkconfig iptables off  #关闭开机自启动iptables

[root@johntest ~]# rpm -e iptables-ipv6 iptables iptstate --nodeps  #卸载iptables相关包

至少需卸载上述三个包,--nodeps强制卸载忽略依赖关系。

warning: /etc/sysconfig/iptables-config saved as /etc/sysconfig/iptables-config.rpmsave


[root@johntest ~]#  ls  #查看下载的iptables源码包和netfilter包

dev   ip_forwarz~    mbox    utility   etc    iptables     proc 

winmail.dat   init   iptables-1.4.6.tar.bz2  readme  netfilter-layer7-v2.23.tar.gz

[root@johntest ~]# tar jxvf iptables-1.4.6.tar.bz2 -C /usr/src  #解压包到指定路径/usr/src

[root@johntest ~]# tar zxvf netfilter-layer7-v2.23.tar.gz -C /usr/src #解压包到指定路径/usr/src   -C指定加压缩路径

[root@johntest ~]# cd /usr/src/

[root@johntest src]# pwd

/usr/src

[root@johntest src]# ls

iptables-1.4.6  kernels  linux-2.6.38  netfilter-layer7-v2.23  redhat

[root@johntest src]# cp netfilter-layer7-v2.23/iptables-1.4.3forward-for-kernel-2.6.20forward/libxt_layer7.* iptables-1.4.6/extensions/ #把netfilt目录中libxt_1ayer7.*所有文件复制到iptables中的extensions目录中

[root@johntest src]# ln -s linux-2.6.38 linux #生成软链接为linux

[root@johntest src]# ls

iptables-1.4.6  kernels  linux  linux-2.6.38  netfilter-layer7-v2.23  redhat

[root@johntest src]# cd iptables-1.4.6/

[root@johntest iptables-1.4.6]# pwd

/usr/src/iptables-1.4.6

[root@johntest iptables-1.4.6]# ./configure --prefix=/usr --with-ksource=/usr/src/linux  #编译--prefix指定安装路径 --with-ksource指定关联的源路径

.......

config.status: executing depfiles commands

config.status: executing libtool commands

[root@johntest iptables-1.4.6]# make

[root@johntest iptables-1.4.6]# make install

[root@johntest iptables-1.4.6]# which iptables #查看刚安装的iptables路径

/usr/sbin/iptables

[root@johntest iptables-1.4.6]# cd 

[root@johntest ~]# vim iptables  #需修改2个路径跟刚才安装的iptables一致

wKiom1jM6LazFwdSAAGP6ISRY38779.jpg

[root@johntest ~]# cp iptables /etc/init.d/

[root@johntest ~]# chkconfig --add iptables  #加入到开机启动列表中

[root@johntest ~]# chkconfig iptables on   #设置开机启动

[root@johntest ~]# cp iptables-config /etc/sysconfig/

[root@johntest ~]# service iptables start


下载l7-protocols-2009-05-28.tar.gz:

[root@johntest ~]# ls

l7-protocols-2009-05-28.tar.gz utility iptables-1.4.6.tar.bz2  readme  

 etc    iptables    netfilter-layer7-v2.23.tar.gz

[root@johntest ~]# tar xvf l7-protocols-2009-05-28.tar.gz

[root@johntest ~]# cd l7-protocols-2009-05-28

[root@johntest l7-protocols-2009-05-28]# make install  #直接编译安装

mkdir -p /etc/l7-protocols

cp -R * /etc/l7-protocols

[root@johntest l7-protocols-2009-05-28]# service iptables restart

[root@johntest l7-protocols-2009-05-28]# cd 

[root@johntest ~]# iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -j SNAT --to-source 172.16.100.7  #原地址转换成172.16.100.7

[root@johntest ~]# iptables -A FORWARD -s 192.168.10.0/24 -m layer7 --l7proto qq -j REJECT

#禁止原地址为192.168.10.0/24的主机,登录qq服务







iptables-1.4.6.tar.bz2 下载地址:

http://www.filewatcher.com/d/Gentoo/distfiles/Other/iptables-1.4.6.tar.bz2.463758.html

l7-protocols-2009-05-28.tar.gz 下载地址:

http://download.chinaunix.net/download.php?id=25732&ResourceID=5525



















本文转自wang650108151CTO博客,原文链接:http://blog.51cto.com/woyaoxuelinux/1907904 ,如需转载请自行联系原作者


相关文章
|
26天前
|
Unix Linux 程序员
Linux文本搜索工具grep命令使用指南
以上就是对Linux环境下强大工具 `grep` 的基础到进阶功能介绍。它不仅能够执行简单文字查询任务还能够处理复杂文字处理任务,并且支持强大而灵活地正则表达规范来增加查询精度与效率。无论您是程序员、数据分析师还是系统管理员,在日常工作中熟练运用该命令都将极大提升您处理和分析数据效率。
103 16
|
18天前
|
Linux
linux命令—stat
`stat` 是 Linux 系统中用于查看文件或文件系统详细状态信息的命令。相比 `ls -l`,它提供更全面的信息,包括文件大小、权限、所有者、时间戳(最后访问、修改、状态变更时间)、inode 号、设备信息等。其常用选项包括 `-f` 查看文件系统状态、`-t` 以简洁格式输出、`-L` 跟踪符号链接,以及 `-c` 或 `--format` 自定义输出格式。通过这些选项,用户可以灵活获取所需信息,适用于系统调试、权限检查、磁盘管理等场景。
|
3月前
|
监控 Linux 网络安全
Linux命令大全:从入门到精通
日常使用的linux命令整理
668 13
|
4月前
|
Linux 网络安全 数据安全/隐私保护
使用Linux系统的mount命令挂载远程服务器的文件夹。
如此一来,你就完成了一次从你的Linux发车站到远程服务器文件夹的有趣旅行。在这个技术之旅中,你既探索了新地方,也学到了如何桥接不同系统之间的距离。
555 21
|
2月前
|
Linux 网络安全 开发工具
技术栈:这50条最常用的 Linux 命令你一定要会!
建议多在终端中实践,遇到不懂的命令就用 man 或 --help 了解详情!
394 0
|
4月前
|
监控 Linux
Linux系统中使用df命令详解磁盘使用情况。
`df`命令是Linux系统管理员和用户监控和管理磁盘空间使用的重要工具。掌握它的基本使用方法和选项可以帮助在必要时分析和解决空间相关问题。简洁但功能丰富,`df`命令确保了用户可以快速有效地识别和管理文件系统的空间使用情况。
265 13
|
2月前
|
安全 Linux Shell
Linux系统中sudo命令的高效运用技巧。
用户可以通过sudo -l来列出自己目前可执行的命令列表,这有助于用户了解自己的权限范围。
119 0
|
2月前
|
监控 Linux Shell
linux命令
常用 Linux 命令汇总
|
4月前
|
Linux
Linux命令拓展:为cp和mv添加进度显示
好了,就这样,让你的Linux复制体验充满乐趣吧!记住,每一个冷冰冰的命令背后,都有方法让它变得热情起来。
299 8
|
3月前
|
Linux C++
每天一个linux命令(8):cp 命令
cp 命令是 Linux 中用于复制文件或目录的命令。它的名字来源于英文单词 copy。这个命令非常常用,特别是在需要备份文件或创建文件副本时。
119 0