网络连接:仅当再次断开/连接电线时才连接

网络连接:仅当再次断开/连接电线时才连接

我刚刚开始使用 Linux。显然已经遇到了很多问题,但还是得解决它。有一个问题让我有点困扰,但我找到了临时的解决方法,那就是我的网络连接。我的拓扑是:NAT->调制解调器->路由器(NetGear 192.168.1.1)->TPLink(192.168.0.1)TPLink 为我提供了家里的无线网络。但我也有通过有线连接到 TPLink 的 ubuntu 12.10。

其他机器(无线)的 IP 地址为 192.168.0.100,ubuntu(有线)的 eth0 配置为地址 192.168.0.101,网络掩码 255.255.255.0,网关 192.168.0.1,它可以正常工作,但重新启动或关闭系统后,我断开了连接。ping 192.168.0.1 出现“无网络”错误,如果我断开电线,等待一段时间再插入,我可以再次连接。有时它可以立即工作,但有时不能,有时我得到 IP 192.168.1.5,就好像 ubuntu 直接连接到路由器(NetGear .1.1),但它连接到 TPLink(.0.1)-> 这怎么可能???

我看到一个帖子说可能是dhcp,所以安装了dhcpcd。这是在断开连接的情况下运行它的结果。

[sudo] password for user: 
info, eth0: dhcpcd 3.2.3 starting
info, eth0: hardware address = d4:3d:7e:4b:47:dc
info, eth0: DUID = 00:01:00:01:18:ab:f5:fd:d4:3d:7e:4b:47:dc
info, eth0: broadcasting for a lease
debug, eth0: sending DHCP_DISCOVER with xid 0x105db75d
debug, eth0: waiting for 20 seconds
debug, eth0: sending DHCP_DISCOVER with xid 0x105db75d
debug, eth0: sending DHCP_DISCOVER with xid 0x105db75d
debug, eth0: sending DHCP_DISCOVER with xid 0x105db75d
debug, eth0: sending DHCP_DISCOVER with xid 0x105db75d
debug, eth0: sending DHCP_DISCOVER with xid 0x105db75d
debug, eth0: sending DHCP_DISCOVER with xid 0x105db75d
err, eth0: timed out
info, eth0: trying to use old lease in `/var/lib/dhcpcd/dhcpcd-eth0.info'
info, eth0: probing for an IPV4LL address
debug, eth0: sending ARP probe #1
debug, eth0: sending ARP probe #2
debug, eth0: sending ARP probe #3
debug, eth0: sending ARP claim #1
debug, eth0: sending ARP claim #2
warn, eth0: using IPV4LL address 169.254.146.212
info, eth0: adding IP address 169.254.146.212/16
debug, eth0: no dns information to write
debug, eth0: writing /var/lib/dhcpcd/dhcpcd-eth0.info
debug, eth0: exec "/etc/dhcpcd.sh" "/var/lib/dhcpcd/dhcpcd-eth0.info" "new"
debug, eth0: forking to background
info, eth0: exiting
user@cmp:~$ dhcpcd.sh: interface eth0 has been configured with new IP=169.254.146.212

它不起作用,我获得了 IP 169.254.146.212(ifconfig,如下)但没有网络连接。再次,我通过拔下电线重新连接,等待一段时间并再次插入。

ifconfig
eth0      Link encap:Ethernet  HWaddr b4:1u:2b:4b:41:c7  
          inet addr:169.254.146.212  Bcast:169.254.255.255  Mask:255.255.0.0
          inet6 addr: fe91::d62d:7eff:ft4b:54hc/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:138 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:35345 (35.3 KB)

lo        Link encap:Local 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:80 errors:0 dropped:0 overruns:0 frame:0
          TX packets:80 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:6432 (6.4 KB)  TX bytes:6432 (6.4 KB)

有谁经历过这样的事吗?

答案1

我认为这与我的机器(Ubuntu 12.10)无法找到 DHCP 服务器(即我的 TP-LINK)有关。

UPnP 网络的基础是 IP 寻址。每台设备都必须实现 DHCP 客户端,并在首次连接到网络时搜索 DHCP 服务器。如果没有可用的 DHCP 服务器,设备必须为自己分配一个地址。UPnP 设备为自己分配地址的过程在 UPnP 设备架构中称为 AutoIP。在 UPnP 设备架构版本 1.0 中[6],AutoIP 在规范本身中定义;在 UPnP 设备架构版本 1.1 中[7],AutoIP 引用 IETF RFC 3927。[8] 如果在 DHCP 事务期间,设备获得域名(例如,通过 DNS 服务器或通过 DNS 转发),则设备应在后续网络操作中使用该名称;否则,设备应使用其 IP 地址。

我找到了至少暂时的解决方法:终止 dhcp 进程

root@ubuntu:/home/user# dhcpcd eth0
err, eth0: dhcpcd already running on pid 2186 (/var/run/dhcpcd-eth0.pid)
root@ubuntu:/home/user# kill -9 2186
root@ubuntu:/home/user# ifconfig
eth0      Link encap:Ethernet  HWaddr b4:1u:2b:4b:41:c7  
          inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe91::d62d:7eff:ft4b:54hc/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8729693 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7491675 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:4836487722 (4.8 GB)  TX bytes:720522105 (720.5 MB)

lo        Link encap:Local 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:51131 errors:0 dropped:0 overruns:0 frame:0
          TX packets:51131 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:5025732 (5.0 MB)  TX bytes:5025732 (5.0 MB)

拔掉网线再插上,然后重新开启dhcp服务:

root@ubuntu:/home/user# dhcpcd eth0
root@ubuntu:/home/user# dhcpcd.sh: interface eth0 has been configured with new IP=192.168.0.100

root@ubuntu:/home/user# 

并且应该可以工作;)

相关内容