请教能人一个iptables的问题

由 aaccdd 在 02-20-2004 10:20 发表:

请教能人一个iptables的问题

启用iptables脚本之后firefox无法正常使用,

现象:

只要在地址栏输入网址,

firefox立刻无反应,(输入第一个字母就没反应了)

只能kill掉;

但是只要不用这个脚本就没有问题。

脚本就是从linuxsir抄的,

改了改。

问题出在哪里,

请能人帮忙看一下。

双网卡,

eth0接内网,

eth1接adsl猫。

> > 源码: >
> * * * >
> #!/bin/sh
> > >
> > > #启用转发(FORWARD)功能
> > > # Enabling IP Forwarding......"
> > > echo "Enabling IP Forwarding........"
> > > echo 1 > /proc/sys/net/ipv4/ip_forward
> > >
> > > #这一步不是很需要。
> > > # Non-Required proc configration
> > > #echo 1 > /proc/sys/net/ipv4/ip_dynaddr
> > >
> > > #开始定义iptables
> > > # Enabling iptables rules
> > >
> > > # Internet Configuration.
> > > INET_IF="ppp0"
> > >
> > > #外网网卡
> > > EXT_IF="eth1"
> > >
> > > #内网网卡
> > > LAN_IF="eth0"
> > > LAN_IP="192.168.0.1"
> > > LAN_IP_RANGE="192.168.0.0/24"
> > > TRUSTED_TCP_PORT="22 25 53 80 110 143 443 3128 6000 6001 6002 7100"
> > >
> > > # your LAN's IP range and localhost IP. /24 means to only use the first 24
> > > # bits of the 32 bit IP address. the same as netmask 255.255.255.0
> > > # Localhost Configuration.
> > > LO_IF="lo"
> > > LO_IP="127.0.0.1"
> > >
> > > #加载模块,有些已经内建,为了以防万一,还是加上了
> > > # Module loading.
> > > echo "modprobe modules"
> > > modprobe ip_tables
> > > modprobe ip_nat_ftp
> > > modprobe ip_conntrack
> > > modprobe ip_conntrack_ftp
> > > # 规则初始化,设置为默认都为DROP
> > > echo "Enabling iptables rules"
> > >
> > > # Reset the default policies in the tables
> > > iptables -F
> > > iptables -X
> > > iptables -F -t mangle
> > > iptables -X -t mangle
> > > iptables -F -t nat
> > > iptables -X -t nat
> > > iptables -Z -t nat
> > >
> > > # Set policies
> > > iptables -P INPUT DROP
> > > iptables -P OUTPUT DROP
> > > iptables -P FORWARD DROP
> > >
> > > # 允许ping localhost,ping 192.168.0.1/2
> > > # Allow loopback access
> > > iptables -A INPUT -p icmp -i lo -j ACCEPT
> > > iptables -A OUTPUT -p icmp -o lo -j ACCEPT
> > >
> > > # 允许代理和内网客户机互相传输数据(包括ping)
> > > # Allow ping LAN
> > > iptables -A INPUT -p ALL -i $LAN_IF -s $LAN_IP_RANGE -j ACCEPT
> > > iptables -A OUTPUT -p ALL -o $LAN_IF -d $LAN_IP_RANGE -j ACCEPT
> > >
> > > # 允许外网的网卡与内网互相通讯。接收数据只接受响应封包,否则不予放行。发送数据没有限制。
> > > # Allow ppp0
> > > iptables -A INPUT -p ALL -i $INET_IF -m state --state ESTABLISHED,RELATED -j ACCEPT
> > > iptables -A OUTPUT -p ALL -o $INET_IF -j ACCEPT
> > >
> > > # 建立用户定义的链
> > > # Creat userspecified chains
> > > iptables -N allowed
> > > iptables -N tcp_packets
> > > iptables -N bad_tcp_packets
> > > iptables -N icmp_packets
> > >
> > > #bad_tcp_packets规则链的作用是,将要求重新导向的联机记录起来,然后将封包丢弃(防止联机被绑架,但是会影响第三方交谈的服务,如MS Media Server)
> > > # bad_tcp_packets chain
> > > iptables -A bad_tcp_packets -p tcp --tcp-flags SYN,ACK SYN,ACK -m state --state NEW -j REJECT --reject-with tcp-reset
> > > iptables -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j LOG --log-prefix "New not syn:"
> > > iptables -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP
> > >
> > > # allowed规则链的作用是:允许要求联机封包或响应封包进入,其余丢弃。
> > > # allowed chain
> > > iptables -A allowed -p tcp --syn -j ACCEPT
> > > iptables -A allowed -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
> > > iptables -A allowed -p tcp -j DROP
> > >
> > > # icmp_packets规则链的功能是:允许ping 封包进入,将其余封包丢弃。
> > > # ICMP rules
> > > iptables -A icmp_packets -p icmp -s 0/0 --icmp-type 8 -j ACCEPT
> > > iptables -A icmp_packets -p icmp -s 0/0 --icmp-type 11 -j ACCEPT
> > >
> > > # INPUT chain
> > > # 进入防火墙主机的tcp封包必须先进行bad_tcp_packets过滤。但是有时候影响网络性能。
> > > # first bad_tcp_packets filter
> > > iptables -A INPUT -p tcp -j bad_tcp_packets
> > >
> > > #从外网进入防火墙主机的icmp封包必须先进行icmp_packets过滤。这是防止黑客传送不完整的ip封包,系统会响应icmp封包通知对方,导致主机位置被侦测出来。
> > >
> > > # second icmp_packets filter
> > > iptables -A INPUT -p icmp -i $INET_IF -j icmp_packets
> > >
> > > # 打开信任的服务
> > > # Open trusted ports
> > > echo "Open trusted ports....."
> > > iptables -N services
> > > for PORT in $TRUSTED_TCP_PORT; do
> > > iptables -A tcp_packets -s 0/0 -p tcp --dport $PORT -j allowed
> > > done
> > > iptables -A INPUT -p tcp -i $INET_IF -j tcp_packets
> > >
> > > # Allow BitTorrent connections
> > > # modified for only ports (was 6881:6889)
> > > iptables -A INPUT -p tcp -s 0/0 -i ppp0 --dport 6881:6883 -j ACCEPT
> > > iptables -A INPUT -p tcp -s 0/0 -i ppp0 --dport 6969 -j ACCEPT
> > >
> > > # 拒绝外部使用内网ip欺骗。
> > > # deny local cheat
> > > iptables -A INPUT -i $INET_IF -s 192.168.0.0/16 -j DROP
> > > iptables -A INPUT -i $INET_IF -s 10.0.0.0/8 -j DROP
> > > iptables -A INPUT -i $INET_IF -s 192.168.1.0/24 -j DROP
> > > iptables -A INPUT -i $INET_IF -s 127.0.0.0/8 -j DROP
> > >
> > > # 从LAN进入防火墙主机的DHCP封包,予以放行,只有当防火墙担任DHCP时才有用
> > > # allow DHCP_packets from LAN
> > > iptables -A INPUT -p udp -i $LAN_IF --dport 67 --sport 68 -j ACCEPT
> > >
> > > #限制过滤规则的比对频率为每分钟平均流量三个封包(超过上限的封包将暂停比对),并将瞬间流量设定为一次最多处理三个封包(超过上限的封包将丢弃不予处理),这类封包通常是黑客用来进行阻断式攻击
> > > iptables -A INPUT -m limit --limit 3/minute --limit-burst 3 -j LOG --log-level INFO --log-prefix "IPT INPUT packets died:"
> > >
> > > # FORWARD chain
> > > # bad_tcp_packets filter
> > > iptables -A FORWARD -p

Published At
Categories with 服务器类
Tagged with
comments powered by Disqus