Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->Linux技术 ->Linux安全 ->正文

Netfilter/Iptables的防火墙功能介绍

来源:Linux时代 作者:Linux时代  时间:2007-04-22 点击: [收藏] [投稿]

  防火墙介绍

  Disclaimer: 下面描述的有些内容可能不完全正确.但希望对你理解iptables有帮助,如果你发现了错误,请通知我。

  注意,此说明是非拷贝的(例如在GPL).如果你想做任何修改、发布、拷贝、引用,请先联系我。(哈哈,不管了)

  什么是防火墙?

  简单说,防火墙就是用来保护你的网络的一台主机,它对来自internet和你的内网(受保护)之间的通讯进行限制,反过来亦可。

  非防火墙功能

  误区 - 防火墙并不能保证你的网络绝对安全

  堡垒主机(A bastion host)- In an ideal world, this would be true. However, a firewall is only as secure as the work you put into securing it.

  主机安全替换(A replacement for host security) - 每一项防火墙允许的服务都是潜在的风险。

  使用类型

  本地 - 对于在实际的物理连接而言,没有安全可言。很明显,防火墙对此无能为力。

  Local privilege escalation - The trojan horse attack. The attacker alreay has a local account on your box (inside the gates) and obtains root by some means (vulnerability or misconfiguration). A firewall cannot protect again this type of attacks.

  Remote - Your host is listening on a port that the attacker is able to connect to remotely over a network and exploit a vunerability somehow. This is the only type of attack a firewall can (hopefully) protect you against. There is another important point here that most firewall howtos neglect. In order for someone to exploit your box remotely, it has to be listening on some ports (i.e. providing a way for an attacker to connect). Therefore, if your host isn't listening on any ports, you are safe from remote exploits (unless the attacker manages to attack the network stack itself).

  为何需要防火墙?

  提高网络安全 - 某些服务有着固有的风险,不可能作到安全性。防火墙可以帮助你提高网段或部分网络的安全性。

  网络访问控制 - 防火墙可以强制性的在网络中应用安全规则。

  日志记录 - 由于防火墙检测所有入站/出站的网络通讯,它可以记录网络中的活动。

  防火墙的类型

  代理防火墙 - 代理服务器.

  包过滤防火墙 - 检测IP包 (Netfilter).

  什么是 Netfilter/Iptables?

  Linux 2.4内核中Netfilter是新的用来实现防火墙的. Iptables 是用来指定Netfilter规则的用户工具。

  为什么Ipchains被改为Netfilter/Iptables

  状态匹配 - 连接跟踪(can you trust the remote host to determine whether your firewall will accept a packet?).

  自动碎片重装- Connection tracking automatically reassembles fragmented packets for examination.

  改良的匹配规则 - 高级包匹配,例如速率限制、字符串匹配.

  增强的日志功能 - 允许自定义日志级别和实体.

  允许包撕裂(?mangle) - 允许撕裂包中的任何信息

  用户队列Userspace queuing -允许userspace可以对包进行编程.

  支持内置包转发 - 舍弃了IPMASQADM.

  主要功能

  状态包过滤(连接跟踪)

  各种网络地址翻译

  灵活、易扩展的急智机制

  大量的增强型补丁包

  Netfilter/iptables可以做什么?

  建立Internet防火墙和基于状态的包过滤

  用NAT和伪装(masquerading)共享上网

  用NAT实现透明代理

  和tc+iproute2配合使用可以实现QoS路由

  用(mangling)修改IP包头的TOS字段来实现更复杂的功能

  安装Iptables

  下载

  Iptables v1.2.2 (netfilter.samba.org/iptables-1.2.2.tar.bz2) md5sum 7d065a5d1e7003a061bece79a88d903

  Linux kernel v2.4.5 (http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.5.tar.bz2)

  安装提示

  注意,在编译、安装iptables之前,不需要编译内核。并且某些内核选项不可用,除非用"make patch-o-matic".

  在/usr/src/linux目录中, 'make oldconfig' (在没有.config文件时,'make menuconfig')。

  在iptables包的解报目录中, 'make && make install'

  打补丁,'make patch-o-matic',推荐只打你需要的补丁。

  返回 /usr/src/linux目录, 'make menuconfig' ,选择新的、可用的选项

  完成正常的内核编译过程(make dep; make clean; make bzImage)

  编译 - Iptales编译一般比较简单

  'make && make install' 将在缺省路径/usr/local中做一个最小安装.

  'make pending-patches' 将给标准内核打上一些著名的漏洞补丁.

  'make patch-o-matic' 将给标准内核打上一些增强功能的补丁.

  'make experimental && make install-experimental' 将创建 iptables-save和 iptables-restore 二进制代码.

  如果你想修改安装路径,可以带参数'BINDIR=/usr/sbin LIBDIR=/usr/lib MANDIR=/usr/man' 进行编译。 (e.g. 'make BINDIR=/usr/sbin LIBDIR=/usr/lib MANDIR=/usr/man install')

  补丁包 - 每个补丁都有新的功能,但几乎每个都有漏洞,因此最好不要全部都安装。

  注意: 下面列出的是v1.2.1a版本的,不是最新版本. 你可以用 'make patch-o-matic'命令列出补丁列表来.

  CONFIG_IP_NF_TARGET_BALANCE 选项, 类似DNAT:把负载均分到一段地址上。(`--to-dest 1.2.3.4-1.2.3.7')

  CONFIG_IP_NF_TARGET_NETLINK, 替代ipchains中的 -o 选项,通过增加一个NETLINK目标,把丢弃的包发往用户空间

  CONFIG_IP_NF_TARGET_SAME ,类似SNAT,利用一段地址(`--to-source 1.2.3.4-1.2.3.7'),对客户端的每个连接给相同的地址.

 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:使用 Perl 自动化 UNIX 系统管理   下一篇:Unix/BSD/Linux的口令机制初探

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号