1 / 42

Chinaunix 技术沙龙

Chinaunix.net 技术沙龙. 2004 年 3 月 27 日. Linux 防火墙的原理和实现. netloafer Email:netloafer@anti-spam.org.cn. 提纲. 防火墙的基本概念 Linux 防火墙的原理 构建 Linux 防火墙 Netfilter 配置工具 iptables 防火墙的常见策略 Linux 防火墙的应用 FAQ. 防火墙的基本概念. 什么是防火墙. 防火墙是一种保护网络安全的方法 防火墙是在两个网络间实现访问控制的一个或一组软件或硬件系统。

yates
Télécharger la présentation

Chinaunix 技术沙龙

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chinaunix.net 技术沙龙 2004年3月27日

  2. Linux防火墙的原理和实现 netloafer Email:netloafer@anti-spam.org.cn

  3. 提纲 • 防火墙的基本概念 • Linux防火墙的原理 • 构建Linux防火墙 • Netfilter配置工具iptables • 防火墙的常见策略 • Linux防火墙的应用 • FAQ www.chinaunix.net

  4. 防火墙的基本概念

  5. 什么是防火墙 • 防火墙是一种保护网络安全的方法 • 防火墙是在两个网络间实现访问控制的一个或一组软件或硬件系统。 • 防火墙的主要功能就是依照所定义的访问控制策略对数据通讯进行屏蔽和允许通信。 www.chinaunix.net

  6. 防火墙的类型 • 包过滤防火墙 • 基于状态检测的包过滤防火墙 • 应用代理(网关)防火墙 • 侧重包过滤的混合式防火墙 • 侧重应用代理的混合式防火墙 www.chinaunix.net

  7. 包过滤防火墙 • 一般工作在OSI的三层和三层以下 • 主要控制报文的源地址、报文的目标地址、服务类型、以及第二层数据链路层可控的MAC地址等。 • 有些也包括部分OSI第四层的内容,如报文的源端口和目的端口 • 常见设备:路由器,可以通过访问控制列表(ACL)来对路由器端口的数据包进行控制 www.chinaunix.net

  8. 包过滤防火墙 • 优点 速度快、对于客户端透明 • 缺点 不能进行内容检查、所工作的层次较低、端口必须静态开放、ACL的配置在复杂网络下容易出错 www.chinaunix.net

  9. 带状态检测的包过滤防火墙 • 工作在IP层 • 动态开放端口 • 动态的状态列表 • 可以对应用层过滤 • 速度和效率都不错 www.chinaunix.net

  10. 应用代理(网关)防火墙 • 包含了网络中的第七层应用 • 可以提供复杂的访问控制 • 认证机制 • 内容过滤 • 详细日志 • 速度慢,系统开销大 • 网络协议和应用都需要代理 www.chinaunix.net

  11. 防火墙的其它功能 • DMZ • IP地址转换和伪装 • VPN • IDS联动 • 病毒过滤 • 流量和计费控制 • 自我保护 • GUI管理 www.chinaunix.net

  12. Linux防火墙的原理

  13. Linux防火墙的历史 • 内核防火墙的发展 • 2.0.X 内核 ipfwadm • 2.2.X 内核 ipchains • 2.4.X 内核 netfilter/iptables www.chinaunix.net

  14. ipchains • ipchains访问控制规则被称为“链” • ipchains共有三条链 • INPUT • OUTPUT • FORWARD • 可实现的功能:包过滤,伪装,路由,TOS • 扩展性不好 www.chinaunix.net

  15. ipchains的处理流程图 www.chinaunix.net

  16. netfilter/iptables • 全新的netfilter框架 • 优秀的包过滤子系统 • 支持IPv4、IPv6、IPX等协议 • 支持MAC过滤 • 功能模块化 www.chinaunix.net

  17. netfilter/iptables处理流程图 www.chinaunix.net

  18. 构建Linux防火墙

  19. 知识准备 • 编译和升级Linux内核 • Linux下软件的安装 • Linux网络的配置 (我们这里的安装以netfilter/iptables为例) www.chinaunix.net

  20. Linux内核的编译 • 使用wget从网站获取最新的内核源码包 • cp linux-2.4.18.tar.gz /usr/src • cd /usr/src • tar zxvf linux-2.4.18.tar.gz • cd /usr/src/linux • make menuconfig • make dep • make clean • make bzImage • make modules • make modules_install www.chinaunix.net

  21. Linux内核netfilter的配置 • [*] Network packet filtering (replaces ipchains) • <M> Connection tracking (required for masq/NAT) • <M> FTP protocol support • <M> IRC protocol support • <M> Userspace queueing via NETLINK (EXPERIMENTAL) • <M> IP tables support (required for filtering/masq/NAT) • <M> limit match support • <M> MAC address match support • <M> netfilter MARK match support • <M> Multiple port match support • <M> TOS match support • <M> tcpmss match support www.chinaunix.net

  22. Linux内核netfilter的配置 • <M> Connection state match support • <M> Packet filtering • <M> REJECT target support • <M> Full NAT • <M> MASQUERADE target support • <M> REDIRECT target support • <M> Packet mangling • <M> TOS target support • <M> MARK target support • <M> LOG target support • <M> TCPMSS target support • <M> ARP tables support • <M> ARP packet filtering www.chinaunix.net

  23. 安装netfilter • 下载netfilter (http://www.netfilter.org) • RPM方式: • rpm –ivh netfiter.0.1.18.i386.rpm • 源码安装: • tar zxvf netfilter-0.1.18.tar.gz • cd netfilter • ./configure • make • make install www.chinaunix.net

  24. 安装iptables • 下载iptables (http://www.netfilter.org) • RPM方式: • rpm –ivh iptables-1.2.7a-1.i386.rpm • 源码安装: • tar zcvf iptables-1.2.7a.tar.gz • cd iptables-1.2.7a • ./configure • make • make install www.chinaunix.net

  25. Linux防火墙管理工具 ipchains iptables

  26. ipchains

  27. ipchains的动作 • ACCEPT • DENY • REJECT • MASQ • REDIRECT • RETURN www.chinaunix.net

  28. -A :--append 在所选择的链上加一条规则到末尾 -D :--delete 从所选链上删除一条或多条规则 -R :--replace 在所选链上替换一条规则 -I :--insert 以给出的规则号在所选链上插入一条或多条规则 -L :--list 列出指定链的规则 -F :--flush 清除一个链的所有规则 -Z :--zero 计数器清零 -N :--new 创建一个新的用户链 -X chain: --delete-chain删除一个用户自定义的链 –P chain target :--policy把一个规链上策略(规则的动作)改变为目标 –M :--masquerade 列出当前伪装包的所有链接 -M -S tcp/tcpfin/udp : --set 设置伪装的超时 ipchains指令 www.chinaunix.net

  29. ipchains使用方法 • ipchains -[ADC] chain rule-specification [options] • ipchains -[RI] chain rulenum rule-specification [options] • ipchains -D chain rulenum [options] • ipchains -[LFZNX] [chain] [options] • ipchains -P chain target [options] • ipchains -M [ -L | -S ] [options] • ipchains -h [icmp] www.chinaunix.net

  30. netfilter配置工具iptables

  31. iptables动作 • ACCEPT • DROP • REJECT • MASQUERADE • REDIRECT • RETURN • SNAT • DNAT www.chinaunix.net

  32. –A chain--append 添加到规则链中 –D chain --delete 从规则链中删除匹配的规则 –D chain rulenum --delete 从规则中删除对应的规则号 –I chain[rulenum] --insert 将规则插入对应的规则号 –R chain rulenum --replace 在规则链中取代指定的规则号 –L[chain] --list 列出在一条链或所有链上的规则 –F [chain] --flush 清除一条链或所有链上的规则 –Z [chain] --zero 计数器清零 –C chain--check 测试规则链 –N chain--new 创建一个用户自定义的新链 -X chain --delete –chain 删除用户定义的新链 -P chain target --policy 把一个规则链上的策略改变为目标 -E old-chain-name new-chain-name --rename chain 改变规则链名 iptables内置有三个表filter、nat、mangle,缺省为filter表,可使用-t参数来选择操作的表,用户可自定义表 iptables指令 www.chinaunix.net

  33. iptables使用方法 • iptables -[ADC] chain rule-specification [options] • iptables -[RI] chain rulenum rule-specification [options] • iptables -D chain rulenum [options] • iptables -[LFZ] [chain] [options] • iptables -[NX] chain • iptables -E old-chain-name new-chain-name • iptables -P chain target [options] • iptables -h www.chinaunix.net

  34. 防火墙的常见策略

  35. 防火墙的常见策略 • 设置默认拒绝规则 • iptables -P INPUT -j DROP • iptables -P OUTPUT -j DROP • iptables -P FORWARD -j DROP • 禁止所有分片包 • iptables -A INPUT -f -i eth0 -j DROP www.chinaunix.net

  36. 防火墙的常见策略 • 允许对外的FTP访问 • iptables -A OUTPUT -i eth0 -p tcp -s 192.168.0.0/24 --sport 1024:65535 -d any/0 --dport 21 -j ACCEPT • iptables -A INPUT -i eth0 -p tcp -s any/0 --sport 21 -d 192.168.0.0/24 --dport 1024:65535 -j ACCEPT www.chinaunix.net

  37. 防火墙的常见策略 • SNAT • iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4 • 伪装 • iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE • DNAT • iptables -t nat -A PREROUTING -i eth0 -j DNAT --to 1.2.4.4 www.chinaunix.net

  38. 防火墙的常见策略 • 端口映像 • iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128 • DNAT的重定向 • iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 1.2.4.4:8080 www.chinaunix.net

  39. Linux防火墙的应用

  40. Linux防火墙的应用 • 各类安全产品的低层模块 • netfilter+iprouter2+squid的透明代理 • netfilter+iprouter2+tc的QoS管理 • 网络的接入 • 网络的安全管理 www.chinaunix.net

  41. FAQ

  42. 谢谢 欢迎大家继续参加chinaunix.net技术沙龙

More Related