SlideShare a Scribd company logo
1 of 42
Chinaunix.net 技术沙龙


    2004 年 3 月 27 日
Linux 防火墙的原理和实现

            netloafer
Email:netloafer@anti-spam.org.cn
提纲
   防火墙的基本概念
   Linux 防火墙的原理
   构建 Linux 防火墙
   Netfilter 配置工具 iptables
   防火墙的常见策略
   Linux 防火墙的应用
   FAQ
                www.chinaunix.net
防火墙的基本概念
什么是防火墙
 防火墙是一种保护网络安全的方法
 防火墙是在两个网络间实现访问控制的一个
  或一组软件或硬件系统。
 防火墙的主要功能就是依照所定义的访问控
  制策略对数据通讯进行屏蔽和允许通信。




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



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

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


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



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

            www.chinaunix.net
防火墙的其它功能
   DMZ
   IP 地址转换和伪装
   VPN
   IDS 联动
   病毒过滤
   流量和计费控制
   自我保护
   GUI 管理
            www.chinaunix.net
Linux 防火墙的原理
Linux 防火墙的历史
 内核防火墙的发展
 2.0.X 内核 ipfwadm
 2.2.X 内核 ipchains
 2.4.X 内核 netfilter/iptables




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

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




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



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




       www.chinaunix.net
构建 Linux 防火墙
知识准备
 编译和升级 Linux 内核
 Linux 下软件的安装
 Linux 网络的配置




      ( 我们这里的安装以 netfilter/iptables 为例)


             www.chinaunix.net
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
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
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
安装 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
安装 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
Linux 防火墙管理工具

  ipchains iptables
ipchains
ipchains 的动作
   ACCEPT
   DENY
   REJECT
   MASQ
   REDIRECT
   RETURN


               www.chinaunix.net
ipchains 指令
 -A : --append 在所选择的链上
                               -X chain : --delete-chain 删除
  加一条规则到末尾
                                一个用户自定义的链
 -D : --delete 从所选链上删除
                               –P chain target : --policy 把一
  一条或多条规则
                                个规链上策略(规则的动作)改
 -R : --replace 在所选链上替换        变为目标
  一条规则                         –M : --masquerade 列出当前
 -I : --insert 以给出的规则号在        伪装包的所有链接
  所选链上插入一条或多条规则                -M -S tcp/tcpfin/udp : --set
 -L : --list 列出指定链的规则          设置伪装的超时
 -F : --flush 清除一个链的所有
  规则
 -Z : --zero 计数器清零
 -N : --new 创建一个新的用户
  链
                 www.chinaunix.net
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
netfilter 配置工具 iptables
iptables 动作
   ACCEPT
   DROP
   REJECT
   MASQUERADE
   REDIRECT
   RETURN
   SNAT
   DNAT
             www.chinaunix.net
iptables 指令
 –A chain --append 添加到规则           –C chain --check 测试规则链
  链中                                –N chain --new 创建一个用户自
 –D chain --delete 从规则链中删           定义的新链
  除匹配的规则                            -X chain --delete –chain 删除用
 –D chain rulenum --delete 从规       户定义的新链
  则中删除对应的规则号                        -P chain target --policy 把一个
 –I chain [rulenum] --insert 将规     规则链上的策略改变为目标
  则插入对应的规则号                         -E old-chain-name new-chain-
 –R chain rulenum --replace 在       name --rename chain 改变规则
  规则链中取代指定的规则号                       链名
 –L[chain] --list 列出在一条链或
  所有链上的规则                                 • iptables 内置有三个表
 –F [chain] --flush 清除一条链或                 filter 、 nat 、 mangle ,缺省为
  所有链上的规则                                   filter 表,可使用 -t 参数来选择操
                                            作的表,用户可自定义表
 –Z [chain] --zero 计数器清零

                      www.chinaunix.net
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
防火墙的常见策略
防火墙的常见策略
 设置默认拒绝规则
 • 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
防火墙的常见策略
 允许对外的 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
防火墙的常见策略
 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
防火墙的常见策略
 端口映像
 • 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
Linux 防火墙的应用
Linux 防火墙的应用
   各类安全产品的低层模块
   netfilter+iprouter2+squid 的透明代理
   netfilter+iprouter2+tc 的 QoS 管理
   网络的接入
   网络的安全管理



               www.chinaunix.net
FAQ
谢谢

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

More Related Content

What's hot

Installation and configuration 11g r2 asm using job role separation(grid & or...
Installation and configuration 11g r2 asm using job role separation(grid & or...Installation and configuration 11g r2 asm using job role separation(grid & or...
Installation and configuration 11g r2 asm using job role separation(grid & or...Zhaoyang Wang
 
九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)heima911
 
Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Yiwei Ma
 
Linux network monitoring hands-on pratice
Linux network monitoring hands-on praticeLinux network monitoring hands-on pratice
Linux network monitoring hands-on praticeKenny (netman)
 
第9讲 Eigrp
第9讲 Eigrp第9讲 Eigrp
第9讲 EigrpF.l. Yu
 
Raspberry pi 基本操作
Raspberry pi 基本操作Raspberry pi 基本操作
Raspberry pi 基本操作艾鍗科技
 
Kick start无人值守批量安装linux
Kick start无人值守批量安装linuxKick start无人值守批量安装linux
Kick start无人值守批量安装linuxYiwei Ma
 
Free rtos简介
Free rtos简介Free rtos简介
Free rtos简介Bei Li
 
Oprofile linux
Oprofile linuxOprofile linux
Oprofile linuxFeng Yu
 
20170415- 智慧空調通訊系統實務_柯大
20170415- 智慧空調通訊系統實務_柯大20170415- 智慧空調通訊系統實務_柯大
20170415- 智慧空調通訊系統實務_柯大MAKERPRO.cc
 
第18讲 Hdlc和Ppp
第18讲 Hdlc和Ppp第18讲 Hdlc和Ppp
第18讲 Hdlc和PppF.l. Yu
 
第10讲 Ospf
第10讲 Ospf第10讲 Ospf
第10讲 OspfF.l. Yu
 
DNS IPv6
DNS IPv6DNS IPv6
DNS IPv6csklho
 
Aix操作系统培训文档
Aix操作系统培训文档Aix操作系统培训文档
Aix操作系统培训文档lwj2012
 
Linux服务器服务配置说明
Linux服务器服务配置说明Linux服务器服务配置说明
Linux服务器服务配置说明Da Zhao
 

What's hot (19)

Installation and configuration 11g r2 asm using job role separation(grid & or...
Installation and configuration 11g r2 asm using job role separation(grid & or...Installation and configuration 11g r2 asm using job role separation(grid & or...
Installation and configuration 11g r2 asm using job role separation(grid & or...
 
九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)
 
Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)
 
Linux system security
Linux system securityLinux system security
Linux system security
 
Tpcc mysql
Tpcc mysqlTpcc mysql
Tpcc mysql
 
Linux network monitoring hands-on pratice
Linux network monitoring hands-on praticeLinux network monitoring hands-on pratice
Linux network monitoring hands-on pratice
 
第9讲 Eigrp
第9讲 Eigrp第9讲 Eigrp
第9讲 Eigrp
 
Raspberry pi 基本操作
Raspberry pi 基本操作Raspberry pi 基本操作
Raspberry pi 基本操作
 
Kick start无人值守批量安装linux
Kick start无人值守批量安装linuxKick start无人值守批量安装linux
Kick start无人值守批量安装linux
 
Free rtos简介
Free rtos简介Free rtos简介
Free rtos简介
 
Oprofile linux
Oprofile linuxOprofile linux
Oprofile linux
 
20170415- 智慧空調通訊系統實務_柯大
20170415- 智慧空調通訊系統實務_柯大20170415- 智慧空調通訊系統實務_柯大
20170415- 智慧空調通訊系統實務_柯大
 
pfSsense
pfSsensepfSsense
pfSsense
 
S4A
S4AS4A
S4A
 
第18讲 Hdlc和Ppp
第18讲 Hdlc和Ppp第18讲 Hdlc和Ppp
第18讲 Hdlc和Ppp
 
第10讲 Ospf
第10讲 Ospf第10讲 Ospf
第10讲 Ospf
 
DNS IPv6
DNS IPv6DNS IPv6
DNS IPv6
 
Aix操作系统培训文档
Aix操作系统培训文档Aix操作系统培训文档
Aix操作系统培训文档
 
Linux服务器服务配置说明
Linux服务器服务配置说明Linux服务器服务配置说明
Linux服务器服务配置说明
 

Viewers also liked

国内主流开放平台发展状况与盈利模式分析报告
国内主流开放平台发展状况与盈利模式分析报告国内主流开放平台发展状况与盈利模式分析报告
国内主流开放平台发展状况与盈利模式分析报告zubin Jiang
 
DATABASE DESIGN AND MANAGEMENT - By Hansa Edirisinghe
DATABASE DESIGN AND MANAGEMENT - By Hansa EdirisingheDATABASE DESIGN AND MANAGEMENT - By Hansa Edirisinghe
DATABASE DESIGN AND MANAGEMENT - By Hansa EdirisingheHansa Edirisinghe
 
DISTRIBUTED NETWORKING - By Hansa Edirisinghe
DISTRIBUTED NETWORKING - By Hansa EdirisingheDISTRIBUTED NETWORKING - By Hansa Edirisinghe
DISTRIBUTED NETWORKING - By Hansa EdirisingheHansa Edirisinghe
 
Legal Applications in Technology - Analyze the legal and professional impact ...
Legal Applications in Technology - Analyze the legal and professional impact ...Legal Applications in Technology - Analyze the legal and professional impact ...
Legal Applications in Technology - Analyze the legal and professional impact ...Hansa Edirisinghe
 
ADVANCED SYSTEMS DEVELOPMENT - By Hansa Edirisinghe
ADVANCED SYSTEMS DEVELOPMENT - By Hansa EdirisingheADVANCED SYSTEMS DEVELOPMENT - By Hansa Edirisinghe
ADVANCED SYSTEMS DEVELOPMENT - By Hansa EdirisingheHansa Edirisinghe
 
Norgren oil &-gas_technologies - shavo_norgren - complete_product_flyer_08
Norgren   oil &-gas_technologies - shavo_norgren - complete_product_flyer_08Norgren   oil &-gas_technologies - shavo_norgren - complete_product_flyer_08
Norgren oil &-gas_technologies - shavo_norgren - complete_product_flyer_08TinA_1009
 
Decatur File Clean Up Guide
Decatur File Clean Up GuideDecatur File Clean Up Guide
Decatur File Clean Up Guidestevenslena
 
поздравляем с днём рождения!!!
поздравляем с днём рождения!!!поздравляем с днём рождения!!!
поздравляем с днём рождения!!!grudsky
 
Information Security Management - Hansa Edirisinghe
Information Security Management - Hansa EdirisingheInformation Security Management - Hansa Edirisinghe
Information Security Management - Hansa EdirisingheHansa Edirisinghe
 
INFORMATION SECURITY MANAGEMENT - Critique the employment of ethical hacking ...
INFORMATION SECURITY MANAGEMENT - Critique the employment of ethical hacking ...INFORMATION SECURITY MANAGEMENT - Critique the employment of ethical hacking ...
INFORMATION SECURITY MANAGEMENT - Critique the employment of ethical hacking ...Hansa Edirisinghe
 
Legal Applications in Technology - Analyze the legal and professional impact ...
Legal Applications in Technology - Analyze the legal and professional impact ...Legal Applications in Technology - Analyze the legal and professional impact ...
Legal Applications in Technology - Analyze the legal and professional impact ...Hansa Edirisinghe
 
深入了解Memcache
深入了解Memcache深入了解Memcache
深入了解Memcachezubin Jiang
 
Guide to good dairy farming practice
Guide to good dairy farming practiceGuide to good dairy farming practice
Guide to good dairy farming practiceMohammed Sabbah
 
TECHNOLOGY ADOPTION - Analyse the diffusion of innovation of Smartphone techn...
TECHNOLOGY ADOPTION - Analyse the diffusion of innovation of Smartphone techn...TECHNOLOGY ADOPTION - Analyse the diffusion of innovation of Smartphone techn...
TECHNOLOGY ADOPTION - Analyse the diffusion of innovation of Smartphone techn...Hansa Edirisinghe
 

Viewers also liked (17)

La programación
La programaciónLa programación
La programación
 
国内主流开放平台发展状况与盈利模式分析报告
国内主流开放平台发展状况与盈利模式分析报告国内主流开放平台发展状况与盈利模式分析报告
国内主流开放平台发展状况与盈利模式分析报告
 
DATABASE DESIGN AND MANAGEMENT - By Hansa Edirisinghe
DATABASE DESIGN AND MANAGEMENT - By Hansa EdirisingheDATABASE DESIGN AND MANAGEMENT - By Hansa Edirisinghe
DATABASE DESIGN AND MANAGEMENT - By Hansa Edirisinghe
 
DISTRIBUTED NETWORKING - By Hansa Edirisinghe
DISTRIBUTED NETWORKING - By Hansa EdirisingheDISTRIBUTED NETWORKING - By Hansa Edirisinghe
DISTRIBUTED NETWORKING - By Hansa Edirisinghe
 
Archive show
Archive showArchive show
Archive show
 
Legal Applications in Technology - Analyze the legal and professional impact ...
Legal Applications in Technology - Analyze the legal and professional impact ...Legal Applications in Technology - Analyze the legal and professional impact ...
Legal Applications in Technology - Analyze the legal and professional impact ...
 
ADVANCED SYSTEMS DEVELOPMENT - By Hansa Edirisinghe
ADVANCED SYSTEMS DEVELOPMENT - By Hansa EdirisingheADVANCED SYSTEMS DEVELOPMENT - By Hansa Edirisinghe
ADVANCED SYSTEMS DEVELOPMENT - By Hansa Edirisinghe
 
Norgren oil &-gas_technologies - shavo_norgren - complete_product_flyer_08
Norgren   oil &-gas_technologies - shavo_norgren - complete_product_flyer_08Norgren   oil &-gas_technologies - shavo_norgren - complete_product_flyer_08
Norgren oil &-gas_technologies - shavo_norgren - complete_product_flyer_08
 
Decatur File Clean Up Guide
Decatur File Clean Up GuideDecatur File Clean Up Guide
Decatur File Clean Up Guide
 
поздравляем с днём рождения!!!
поздравляем с днём рождения!!!поздравляем с днём рождения!!!
поздравляем с днём рождения!!!
 
Information Security Management - Hansa Edirisinghe
Information Security Management - Hansa EdirisingheInformation Security Management - Hansa Edirisinghe
Information Security Management - Hansa Edirisinghe
 
INFORMATION SECURITY MANAGEMENT - Critique the employment of ethical hacking ...
INFORMATION SECURITY MANAGEMENT - Critique the employment of ethical hacking ...INFORMATION SECURITY MANAGEMENT - Critique the employment of ethical hacking ...
INFORMATION SECURITY MANAGEMENT - Critique the employment of ethical hacking ...
 
Soal to 2011
Soal to 2011Soal to 2011
Soal to 2011
 
Legal Applications in Technology - Analyze the legal and professional impact ...
Legal Applications in Technology - Analyze the legal and professional impact ...Legal Applications in Technology - Analyze the legal and professional impact ...
Legal Applications in Technology - Analyze the legal and professional impact ...
 
深入了解Memcache
深入了解Memcache深入了解Memcache
深入了解Memcache
 
Guide to good dairy farming practice
Guide to good dairy farming practiceGuide to good dairy farming practice
Guide to good dairy farming practice
 
TECHNOLOGY ADOPTION - Analyse the diffusion of innovation of Smartphone techn...
TECHNOLOGY ADOPTION - Analyse the diffusion of innovation of Smartphone techn...TECHNOLOGY ADOPTION - Analyse the diffusion of innovation of Smartphone techn...
TECHNOLOGY ADOPTION - Analyse the diffusion of innovation of Smartphone techn...
 

Similar to Linux

探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUGYingSiang Geng
 
分会场二Storage foundation 中的多通道技术
分会场二Storage foundation 中的多通道技术分会场二Storage foundation 中的多通道技术
分会场二Storage foundation 中的多通道技术ITband
 
Hadoop+spark實作
Hadoop+spark實作Hadoop+spark實作
Hadoop+spark實作FEG
 
Monitor is all for ops
Monitor is all for opsMonitor is all for ops
Monitor is all for ops琛琳 饶
 
Hacking Nginx at Taobao
Hacking Nginx at TaobaoHacking Nginx at Taobao
Hacking Nginx at TaobaoJoshua Zhu
 
IBM Cloud Private Introduction
IBM Cloud Private IntroductionIBM Cloud Private Introduction
IBM Cloud Private IntroductionGuangya Liu
 
服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130Jinrong Ye
 
Osc scott linux下的数据库优化for_postgresql
Osc scott linux下的数据库优化for_postgresqlOsc scott linux下的数据库优化for_postgresql
Osc scott linux下的数据库优化for_postgresqlOpenSourceCamp
 
Bypat博客出品-利用cent os快速构建自己的发行版
Bypat博客出品-利用cent os快速构建自己的发行版Bypat博客出品-利用cent os快速构建自己的发行版
Bypat博客出品-利用cent os快速构建自己的发行版redhat9
 
Track2 -刘继伟--openstack in gamewave
Track2 -刘继伟--openstack in gamewaveTrack2 -刘继伟--openstack in gamewave
Track2 -刘继伟--openstack in gamewaveOpenCity Community
 
Mysql mmm演讲--冯浩
Mysql mmm演讲--冯浩Mysql mmm演讲--冯浩
Mysql mmm演讲--冯浩chinafenghao
 
Mysql mmm演讲-冯浩
Mysql mmm演讲-冯浩Mysql mmm演讲-冯浩
Mysql mmm演讲-冯浩chinafenghao
 
Mysql mmm演讲-冯浩
Mysql mmm演讲-冯浩Mysql mmm演讲-冯浩
Mysql mmm演讲-冯浩chinafenghao
 
Linux基础
Linux基础Linux基础
Linux基础zhuqling
 
SACC2015 ”互联网+“任重而道远-白金&高春辉
SACC2015 ”互联网+“任重而道远-白金&高春辉SACC2015 ”互联网+“任重而道远-白金&高春辉
SACC2015 ”互联网+“任重而道远-白金&高春辉ptcracker
 
5, system admin
5, system admin5, system admin
5, system adminted-xu
 
Elastic stack day-2
Elastic stack day-2Elastic stack day-2
Elastic stack day-2YI-CHING WU
 
淘宝软件基础设施构建实践
淘宝软件基础设施构建实践淘宝软件基础设施构建实践
淘宝软件基础设施构建实践Wensong Zhang
 

Similar to Linux (20)

探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
 
分会场二Storage foundation 中的多通道技术
分会场二Storage foundation 中的多通道技术分会场二Storage foundation 中的多通道技术
分会场二Storage foundation 中的多通道技术
 
Hadoop+spark實作
Hadoop+spark實作Hadoop+spark實作
Hadoop+spark實作
 
Monitor is all for ops
Monitor is all for opsMonitor is all for ops
Monitor is all for ops
 
Hacking Nginx at Taobao
Hacking Nginx at TaobaoHacking Nginx at Taobao
Hacking Nginx at Taobao
 
IBM Cloud Private Introduction
IBM Cloud Private IntroductionIBM Cloud Private Introduction
IBM Cloud Private Introduction
 
服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130
 
Osc scott linux下的数据库优化for_postgresql
Osc scott linux下的数据库优化for_postgresqlOsc scott linux下的数据库优化for_postgresql
Osc scott linux下的数据库优化for_postgresql
 
Bypat博客出品-利用cent os快速构建自己的发行版
Bypat博客出品-利用cent os快速构建自己的发行版Bypat博客出品-利用cent os快速构建自己的发行版
Bypat博客出品-利用cent os快速构建自己的发行版
 
Track2 -刘继伟--openstack in gamewave
Track2 -刘继伟--openstack in gamewaveTrack2 -刘继伟--openstack in gamewave
Track2 -刘继伟--openstack in gamewave
 
Mysql mmm演讲--冯浩
Mysql mmm演讲--冯浩Mysql mmm演讲--冯浩
Mysql mmm演讲--冯浩
 
Mysql mmm演讲-冯浩
Mysql mmm演讲-冯浩Mysql mmm演讲-冯浩
Mysql mmm演讲-冯浩
 
Mysql mmm演讲-冯浩
Mysql mmm演讲-冯浩Mysql mmm演讲-冯浩
Mysql mmm演讲-冯浩
 
Linux基础
Linux基础Linux基础
Linux基础
 
LinuxGuide4F2E
LinuxGuide4F2ELinuxGuide4F2E
LinuxGuide4F2E
 
SACC2015 ”互联网+“任重而道远-白金&高春辉
SACC2015 ”互联网+“任重而道远-白金&高春辉SACC2015 ”互联网+“任重而道远-白金&高春辉
SACC2015 ”互联网+“任重而道远-白金&高春辉
 
5, system admin
5, system admin5, system admin
5, system admin
 
Elastic stack day-2
Elastic stack day-2Elastic stack day-2
Elastic stack day-2
 
淘宝软件基础设施构建实践
淘宝软件基础设施构建实践淘宝软件基础设施构建实践
淘宝软件基础设施构建实践
 
Taobao base
Taobao baseTaobao base
Taobao base
 

Linux

  • 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
  • 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
  • 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
  • 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
  • 27. ipchains 的动作  ACCEPT  DENY  REJECT  MASQ  REDIRECT  RETURN www.chinaunix.net
  • 28. ipchains 指令  -A : --append 在所选择的链上  -X chain : --delete-chain 删除 加一条规则到末尾 一个用户自定义的链  -D : --delete 从所选链上删除  –P chain target : --policy 把一 一条或多条规则 个规链上策略(规则的动作)改  -R : --replace 在所选链上替换 变为目标 一条规则  –M : --masquerade 列出当前  -I : --insert 以给出的规则号在 伪装包的所有链接 所选链上插入一条或多条规则  -M -S tcp/tcpfin/udp : --set  -L : --list 列出指定链的规则 设置伪装的超时  -F : --flush 清除一个链的所有 规则  -Z : --zero 计数器清零  -N : --new 创建一个新的用户 链 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
  • 31. iptables 动作  ACCEPT  DROP  REJECT  MASQUERADE  REDIRECT  RETURN  SNAT  DNAT www.chinaunix.net
  • 32. iptables 指令  –A chain --append 添加到规则  –C chain --check 测试规则链 链中  –N chain --new 创建一个用户自  –D chain --delete 从规则链中删 定义的新链 除匹配的规则  -X chain --delete –chain 删除用  –D chain rulenum --delete 从规 户定义的新链 则中删除对应的规则号  -P chain target --policy 把一个  –I chain [rulenum] --insert 将规 规则链上的策略改变为目标 则插入对应的规则号  -E old-chain-name new-chain-  –R chain rulenum --replace 在 name --rename chain 改变规则 规则链中取代指定的规则号 链名  –L[chain] --list 列出在一条链或 所有链上的规则 • iptables 内置有三个表  –F [chain] --flush 清除一条链或 filter 、 nat 、 mangle ,缺省为 所有链上的规则 filter 表,可使用 -t 参数来选择操 作的表,用户可自定义表  –Z [chain] --zero 计数器清零 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
  • 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
  • 40. Linux 防火墙的应用  各类安全产品的低层模块  netfilter+iprouter2+squid 的透明代理  netfilter+iprouter2+tc 的 QoS 管理  网络的接入  网络的安全管理 www.chinaunix.net
  • 41. FAQ