LinuxSir.cn,穿越时空的Linuxsir!

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

iptables 导致没法上网,怀疑iptables 改了内核的某个选项

[复制链接]
发表于 2010-9-12 10:49:32 | 显示全部楼层 |阅读模式
在2.6.30 2.6.35 内核上都出现了这种情况,开始以为是2.6.35 有bug
但后来证明不是
情况如下:

开始设置后用了一段时间(几十分钟),之后运行route 命令 显示不出default gw 等信息,,卡在那。即便把iptables 停了,也是如此 .没法上网。但是奇怪的是我虚拟机里可以上网。(用的是桥接)
问题出在哪



下面是我用的脚本,
sudo /etc/init.d/iptables save
sudo /etc/init.d/iptable restart
#清空表中规则链
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
#开放sshd服务
iptables -A INPUT  -p tcp --dport 22      -j ACCEPT
iptables -A OUTPUT  -p tcp --sport 22      -j ACCEPT
#默认drop 所有包
iptables -P INPUT  DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
#本机设备放行
iptables  -t filter  -I  INPUT 1 -i lo  -j ACCEPT
iptables  -t filter  -I   OUTPUT 1 -o lo  -j ACCEPT

#dns
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -A INPUT -p udp --sport 53 -j ACCEPT
#上网
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --sport 80 -j ACCEPT
#drcom
iptables -A INPUT  -p udp --sport 61440 --dport 61440 -s 211.64.208.160 -j ACCEPT
iptables -A OUTPUT  -p udp --sport 61440 --dport 61440 -d 211.64.208.160 -j ACCEPT
# ftp
# 在配置文件中加入  IPTABLES_MODULES="ip_conntrack_ftp"
iptables -I INPUT  2 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -I OUTPUT 2  -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 21 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
#web 服务
iptables -A INPUT -p tcp  --dport 80 -j ACCEPT
iptables -A OUTPUT  -p tcp  --sport 80 -j ACCEPT
发表于 2010-9-12 11:18:41 | 显示全部楼层
你把iptables关了, 能上网的话, 就是iptables有问题;不能上网的话, 那就不是iptables的问题. 另: 既然你的虚拟机能上网 那么 说明网是通的

1. ping下外网 贴提示
2. cat /etc/resolve.conf 贴结果
3. route 贴结果
4. ifconfig -a 贴结果

5. 假如不用贴就解决了问题, 以上当我没说!

===

粗心了 你的route没结果的话 是你网关没设好 设下就好了 以上文字请忽略 =. =!!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-9-12 13:04:36 | 显示全部楼层
这两个服务器是学校推荐使用的服务器,一直就用它,没什么问题
并且 我chattr +a /etc/resolv.conf ,以免dhcp 的时候改变它
jf jixiuf # cat /etc/resolv.conf
nameserver 202.102.128.68
nameserver 211.64.208.1

==============================================================
jf jixiuf # ifconfig  -a
eth0      Link encap:Ethernet  HWaddr 00:1e:ec:c1:94:75  
          inet6 addr: fe80::21e:ecff:fec1:9475/64 Scopeink
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:45436 errors:0 dropped:0 overruns:0 frame:0
          TX packets:240 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:61366180 (58.5 MiB)  TX bytes:39992 (39.0 KiB)
          Interrupt:17

lo        Link encapocal Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:9 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:767 (767.0 B)  TX bytes:767 (767.0 B)

sit0      Link encap:IPv6-in-IPv4  
          NOARP  MTU:1480  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

vboxnet0  Link encap:Ethernet  HWaddr 0a:00:27:00:00:00  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 00:21:00:7d:1f:b2  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

==============================================================
jf jixiuf #  route   我感觉问题就在这,没有eth0 这个设备的网关
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
loopback        jf.org          255.0.0.0       UG    0      0        0 lo
=========================================================
jf jixiuf #  ping baidu.com
ping: unknown host baidu.com

jf jixiuf # ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_req=1 ttl=64 time=0.055 ms
64 bytes from 127.0.0.1: icmp_req=2 ttl=64 time=0.048 ms
^C
--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.048/0.051/0.055/0.008 ms
jf jixiuf # ping 10.2.1.254
PING 10.2.1.254 (10.2.1.254) 56(84) bytes of data.
From 10.2.1.178 icmp_seq=2 Destination Host Unreachable
From 10.2.1.178 icmp_seq=3 Destination Host Unreachable
From 10.2.1.178 icmp_seq=4 Destination Host Unreachable
^C
--- 10.2.1.254 ping statistics ---
5 packets transmitted, 0 received, +3 errors, 100% packet loss, time 4002ms
pipe 3
jf jixiuf # ping 211.87.159.21
PING 211.87.159.21 (211.87.159.21) 56(84) bytes of data.
From 10.2.1.178 icmp_seq=2 Destination Host Unreachable
From 10.2.1.178 icmp_seq=3 Destination Host Unreachable
From 10.2.1.178 icmp_seq=4 Destination Host Unreachable
From 10.2.1.178 icmp_seq=6 Destination Host Unreachable
From 10.2.1.178 icmp_seq=7 Destination Host Unreachable










如果我运行这两个命令
sudo ifconfig eth0 10.2.1.178 netmask 255.255.254.0
sudo route add default gw 10.2.1.254
然后再运行route
jf jixiuf # route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
结果是卡在这,过个一两分钟后完整结果是
jf jixiuf # route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.2.0.0        *               255.255.254.0   U     0      0        0 eth0
loopback        jf.org          255.0.0.0       UG    0      0        0 lo
default         10.2.1.254      0.0.0.0         UG    0      0        0 eth0
重新route 又卡在那,
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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