LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 742|回复: 0

请教能人一个iptables的问题

[复制链接]
发表于 2004-2-20 10:20:11 | 显示全部楼层 |阅读模式
启用iptables脚本之后firefox无法正常使用,
现象:
只要在地址栏输入网址,
firefox立刻无反应,(输入第一个字母就没反应了)
只能kill掉;
但是只要不用这个脚本就没有问题。

脚本就是从linuxsir抄的,
改了改。
问题出在哪里,
请能人帮忙看一下。

双网卡,
eth0接内网,
eth1接adsl猫。

  1. #!/bin/sh

  2. #启用转发(FORWARD)功能
  3. # Enabling IP Forwarding......"
  4. echo "Enabling IP Forwarding........"
  5. echo 1 > /proc/sys/net/ipv4/ip_forward

  6. #这一步不是很需要。
  7. # Non-Required proc configration
  8. #echo 1 > /proc/sys/net/ipv4/ip_dynaddr

  9. #开始定义iptables
  10. # Enabling iptables rules

  11. # Internet Configuration.
  12. INET_IF="ppp0"

  13. #外网网卡
  14. EXT_IF="eth1"

  15. #内网网卡
  16. LAN_IF="eth0"
  17. LAN_IP="192.168.0.1"
  18. LAN_IP_RANGE="192.168.0.0/24"
  19. TRUSTED_TCP_PORT="22 25 53 80 110 143 443 3128 6000 6001 6002 7100"

  20. # your LAN's IP range and localhost IP. /24 means to only use the first 24
  21. # bits of the 32 bit IP address. the same as netmask 255.255.255.0
  22. # Localhost Configuration.
  23. LO_IF="lo"
  24. LO_IP="127.0.0.1"

  25. #加载模块,有些已经内建,为了以防万一,还是加上了
  26. # Module loading.
  27. echo "modprobe modules"
  28. modprobe ip_tables
  29. modprobe ip_nat_ftp
  30. modprobe ip_conntrack
  31. modprobe ip_conntrack_ftp
  32. # 规则初始化,设置为默认都为DROP
  33. echo "Enabling iptables rules"

  34. # Reset the default policies in the tables
  35. iptables -F
  36. iptables -X
  37. iptables -F -t mangle
  38. iptables -X -t mangle
  39. iptables -F -t nat
  40. iptables -X -t nat
  41. iptables -Z -t nat

  42. # Set policies
  43. iptables -P INPUT DROP
  44. iptables -P OUTPUT DROP
  45. iptables -P FORWARD DROP

  46. # 允许ping localhost,ping 192.168.0.1/2
  47. # Allow loopback access
  48. iptables -A INPUT -p icmp -i lo -j ACCEPT
  49. iptables -A OUTPUT -p icmp -o lo -j ACCEPT

  50. # 允许代理和内网客户机互相传输数据(包括ping)
  51. # Allow ping LAN
  52. iptables -A INPUT -p ALL -i $LAN_IF -s $LAN_IP_RANGE -j ACCEPT
  53. iptables -A OUTPUT -p ALL -o $LAN_IF -d $LAN_IP_RANGE -j ACCEPT

  54. # 允许外网的网卡与内网互相通讯。接收数据只接受响应封包,否则不予放行。发送数据没有限制。
  55. # Allow ppp0
  56. iptables -A INPUT -p ALL -i $INET_IF -m state --state ESTABLISHED,RELATED -j ACCEPT
  57. iptables -A OUTPUT -p ALL -o $INET_IF -j ACCEPT

  58. # 建立用户定义的链
  59. # Creat userspecified chains
  60. iptables -N allowed
  61. iptables -N tcp_packets
  62. iptables -N bad_tcp_packets
  63. iptables -N icmp_packets

  64. #bad_tcp_packets规则链的作用是,将要求重新导向的联机记录起来,然后将封包丢弃(防止联机被绑架,但是会影响第三方交谈的服务,如MS Media Server)
  65. # bad_tcp_packets chain
  66. iptables -A bad_tcp_packets -p tcp --tcp-flags SYN,ACK SYN,ACK -m state --state NEW -j REJECT --reject-with tcp-reset
  67. iptables -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j LOG --log-prefix "New not syn:"
  68. iptables -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP

  69. # allowed规则链的作用是:允许要求联机封包或响应封包进入,其余丢弃。
  70. # allowed chain
  71. iptables -A allowed -p tcp --syn -j ACCEPT
  72. iptables -A allowed -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
  73. iptables -A allowed -p tcp -j DROP

  74. # icmp_packets规则链的功能是:允许ping 封包进入,将其余封包丢弃。
  75. # ICMP rules
  76. iptables -A icmp_packets -p icmp -s 0/0 --icmp-type 8 -j ACCEPT
  77. iptables -A icmp_packets -p icmp -s 0/0 --icmp-type 11 -j ACCEPT

  78. # INPUT chain
  79. # 进入防火墙主机的tcp封包必须先进行bad_tcp_packets过滤。但是有时候影响网络性能。
  80. # first bad_tcp_packets filter
  81. iptables -A INPUT -p tcp -j bad_tcp_packets

  82. #从外网进入防火墙主机的icmp封包必须先进行icmp_packets过滤。这是防止黑客传送不完整的ip封包,系统会响应icmp封包通知对方,导致主机位置被侦测出来。

  83. # second icmp_packets filter
  84. iptables -A INPUT -p icmp -i $INET_IF -j icmp_packets

  85. # 打开信任的服务
  86. # Open trusted ports
  87. echo "Open trusted ports....."
  88. iptables -N services
  89. for PORT in $TRUSTED_TCP_PORT; do
  90. iptables -A tcp_packets -s 0/0 -p tcp --dport $PORT -j allowed
  91. done
  92. iptables -A INPUT -p tcp -i $INET_IF -j tcp_packets

  93. # Allow BitTorrent connections
  94. # modified for only ports (was 6881:6889)
  95. iptables -A INPUT -p tcp -s 0/0 -i ppp0 --dport 6881:6883 -j ACCEPT
  96. iptables -A INPUT -p tcp -s 0/0 -i ppp0 --dport 6969 -j ACCEPT

  97. # 拒绝外部使用内网ip欺骗。
  98. # deny local cheat
  99. iptables -A INPUT -i $INET_IF -s 192.168.0.0/16 -j DROP
  100. iptables -A INPUT -i $INET_IF -s 10.0.0.0/8 -j DROP
  101. iptables -A INPUT -i $INET_IF -s 192.168.1.0/24 -j DROP
  102. iptables -A INPUT -i $INET_IF -s 127.0.0.0/8 -j DROP

  103. # 从LAN进入防火墙主机的DHCP封包,予以放行,只有当防火墙担任DHCP时才有用
  104. # allow DHCP_packets from LAN
  105. iptables -A INPUT -p udp -i $LAN_IF --dport 67 --sport 68 -j ACCEPT

  106. #限制过滤规则的比对频率为每分钟平均流量三个封包(超过上限的封包将暂停比对),并将瞬间流量设定为一次最多处理三个封包(超过上限的封包将丢弃不予处理),这类封包通常是黑客用来进行阻断式攻击
  107. iptables -A INPUT -m limit --limit 3/minute --limit-burst 3 -j LOG --log-level INFO --log-prefix "IPT INPUT packets died:"

  108. # FORWARD chain
  109. # bad_tcp_packets filter
  110. iptables -A FORWARD -p tcp -j bad_tcp_packets

  111. # 从LAN到WAN的封包统统放行
  112. iptables -A FORWARD -o $INET_IF -s $LAN_IP_RANGE -j ACCEPT

  113. # same to above 和上面的规则功能相同
  114. #iptables -A FORWARD -i $LAN_IF -s $LAN_IP_RANGE -j ACCEPT
  115. # 从WAN到LAN的封包仅放行回应封包
  116. iptables -A FORWARD -i $INET_IF -d $LAN_IP_RANGE -m state --state ESTABLISHED,RELATED -j ACCEPT

  117. #限制过滤规则的比对频率为每分钟平均流量三个封包(超过上限的封包将暂停比对),并将瞬间流量设定为一次最多处理三个封包(超过上限的封包将丢弃不予处理),这类封包通常是骇客用来进行阻断式攻击
  118. iptables -A FORWARD -m limit --limit 3/minute --limit-burst 3 -j LOG --log-level DEBUG --log-prefix "IPT FORWARD packets died:"

  119. # 一下是防止PING
  120. iptables -A FORWARD -f -m limit --limit 100/s --limit-burst 100 -j ACCEPT
  121. iptables -A FORWARD -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT
  122. # 防止DDOS

  123. #iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
  124. # UDP包一律放行
  125. # allow UDP
  126. iptables -A FORWARD -p udp -d $LAN_IP_RANGE -i $EXT_IF -j ACCEPT

  127. # 将WWW服务转向Squid。
  128. iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
  129. iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o ppp0 -j MASQUERADE

  130. ## iptables END
  131. #echo "Enabling Squid"
  132. #/usr/local/squid/sbin/squid
  133. echo "Enabling ADSL"
  134. adsl-start
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表