Iptables防火墙与NAT的服务.ppt
Iptables防火墙与NAT服务,防火墙概述,防火墙简介 防火墙种类 包过滤防火墙(静态、 ACL) 状态防火墙(动态) 应用层防火墙 代理服务型防火墙 网闸,Iptables是什么?,netfilter/iptables IP 信息包过滤系统是一种功能强大的工具,可用于添加、编辑和除去规则,这些规则是在做信息包过滤决定时,防火墙所遵循和组成的规则。 netfilter 组件也称为内核空间(kernelspace),是内核的一部分,由一些信息包过滤表组成,这些表包含内核用来控制信息包过滤处理的规则集。 iptables 组件是一种工具,也称为用户空间(userspace),它使插入、修改和除去信息包过滤表中的规则变得容易。,Iptables工作流程,规则(rules),规则(rules)是网络管理员预定义的条件,如: Intables -A INPUT -i eth0 -s 124.11.132.180 -j REJECT Iptables A OUTPUT o eth0 d 211.2.1.3 j ACCEPT,链(chains),链(chains)是数据包传播途径,由多条规则组成,默认有五种链: PREROUTING INPUT FORWARD OUTPUT POSTROUTING 自定义链,表(tables),表(tables)提供特定的功能。Iptables内置三个表: Filter表 Nat表 Mangle表,常用命令与目录,iptables、iptable-save、iptables-restore /etc/sysconfig/iptables 启动:/etc/init.d/iptables start 或services iptables start 停止:/etc/init.d/iptables stop 或services iptables stop,/etc/sysconfig/iptables内容,rootSM log# cat /etc/sysconfig/iptables # Firewall configuration written by system-config-securitylevel # Manual customization of this file is not recommended. *filter :INPUT ACCEPT 0:0 :FORWARD ACCEPT 0:0 :OUTPUT ACCEPT 0:0 :RH-Firewall-1-INPUT - 0:0 -A INPUT -j RH-Firewall-1-INPUT -A FORWARD -j RH-Firewall-1-INPUT -A RH-Firewall-1-INPUT -i eth0 -s 60.181.166.185 -j REJECT -A RH-Firewall-1-INPUT -i eth0 -s 124.11.132.180 -j REJECT -A RH-Firewall-1-INPUT -i lo -j ACCEPT -A RH-Firewall-1-INPUT -p icmp -icmp-type any -j ACCEPT -A RH-Firewall-1-INPUT -p 50 -j ACCEPT -A RH-Firewall-1-INPUT -p 51 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -dport 5353 -d 224.0.0.251 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m udp -dport 631 -j ACCEPT -A RH-Firewall-1-INPUT -p tcp -m tcp -dport 631 -j ACCEPT -A RH-Firewall-1-INPUT -m state -state ESTABLISHED,RELATED -j ACCEPT -A RH-Firewall-1-INPUT -m state -state NEW -m tcp -p tcp -dport 21 -j ACCEPT -A RH-Firewall-1-INPUT -m state -state NEW -m tcp -p tcp -dport 25 -j ACCEPT -A RH-Firewall-1-INPUT -m state -state NEW -m tcp -p tcp -dport 2049 -j ACCEPT -A RH-Firewall-1-INPUT -m state -state NEW -m tcp -p tcp -dport 22 -j ACCEPT -A RH-Firewall-1-INPUT -m state -state NEW -m udp -p udp -dport 137 -j ACCEPT -A RH-Firewall-1-INPUT -m state -state NEW -m udp -p udp -dport 138 -j ACCEPT -A RH-Firewall-1-INPUT -m state -state NEW -m tcp -p tcp -dport 139 -j ACCEPT -A RH-Firewall-1-INPUT -m state -state NEW -m tcp -p tcp -dport 445 -j ACCEPT -A RH-Firewall-1-INPUT -m state -state NEW -m tcp -p tcp -dport 443 -j ACCEPT -A RH-Firewall-1-INPUT -m state -state NEW -m tcp -p tcp -dport 23 -j ACCEPT -A RH-Firewall-1-INPUT -m state -state NEW -m tcp -p tcp -dport 80 -j ACCEPT -A RH-Firewall-1-INPUT -m state -state NEW -m tcp -p tcp -dport 110 -j ACCEPT -A RH-Firewall-1-INPUT -m state -state NEW -m tcp -p tcp -dport 143 -j ACCEPT -A RH-Firewall-1-INPUT -j REJECT -reject-with icmp-host-prohibited COMMIT,NAT使用,echo 1 /proc/sys/net/ipv4/ip_forward # echo Starting iptable rules . /sbin/modprobe iptable_filter /sbin/modprobe ip_tables /sbin/modprobe iptable_nat /sbin/modprobe ip_nat_ftp /sbin/modprobe ip_conntrack_ftp /sbin/modprobe ip_conntrack hashsize=2097152 # echo 2097152 /proc/sys/net/ipv4/netfilter/ip_conntrack_max echo 2097152 /proc/sys/net/ipv4/ip_conntrack_max,NAT使用(续),iptables -F INPUT iptables -F FORWARD iptables -F OUTPUT iptables -F POSTROUTING -t nat iptables -F PREROUTING -t nat # iptables -P INPUT DROP # iptables -P FORWARD DROP # iptables -P OUTPUT ACCEPT #,NAT使用(续),# # 2006-10-07 JiZhiCheng GPRS, Teacher Zhu, 13506187381 iptables -A PREROUTING -t nat -i eth0 -p tcp -d 61.177.142.230 -dport 1099 -j DNAT -to-destination 172.18.152.237:1099 iptables -A FORWARD -i eth0 -p tcp -d 172.18.152.237 -dport 1099 -j ACCEPT iptables -A FORWARD -i eth1 -p tcp -s 172.18.152.237 -sport 1099 -j ACCEPT #,NAT使用(续),iptables -A POSTROUTING -t nat -o eth0 -s 202.195.144.0/20 -j SNAT -to-source 61.177.142.227 iptables -A POSTROUTING -t nat -o eth0 -s 210.28.16.0/20 -j SNAT -to-source 61.177.142.227 iptables -A POSTROUTING -t nat -o eth0 -s 211.65.24.0/22 -j SNAT -to-source 61.177.142.227 # iptables -A POSTROUTING -t nat -o eth0 -s 172.16.0.0/16 -j SNAT -to-source 61.177.142.228 iptables -A POSTROUTING -t nat -o eth0 -s 172.17.0.0/16 -j SNAT -to-source 61.177.142.229 iptables -A POSTROUTING -t nat -o eth0 -s 172.18.0.0/16 -j SNAT -to-source 61.177.142.230,