如果给电脑安装完 ubuntu 系统,但是不能上网,你可以尝试如下方式诊断一下,每一步都有很丰富的信息,发现任何异常再 google 之。
1 . 查看网络配置,是否配置了静态ip
如果配置了静态ip, 需要查看路由器是否开启了 DHCP,尝试关闭 DHCP 试一下。 或者开启路由器的 DHCP 服务,并限制 ip 地址范围为 192.168.0.100-192.168.0.110,然后设置静态 ip 为 192.168.0.111, 这样就不会发生冲突了。 在设置静态ip之前,需要查看对应的ip是否已经被分配了。以及 ethX 名字是否对应。
cat /etc/network/interfaces
2 . 检查一下网卡接口
ifconfig // 检查是否获得了 ip 地址,网卡是否已开启等状态信息,还有很多工具,如下:
# 如果安装了NetworkManager 工具, 执行:
# nm-tool
# 或者执行:
# ip a
# 或者执行:
# ethtool eth0
# ethtool -i eth0 // 查看网卡驱动信息
ifconfig -a // 检查所有 网络接口
sudo ifconfig eth0 up // 开启某个网络接口
如果 ethtool eth0
显示的:
Speed: Unknown!
Duplex: Unknown! (255)
...
Link detected: no
则可能网卡速率设置有问题(毕竟现在千兆网卡也很多),跳到 第5条,查看如何设置网卡速率。。。
3 . 查看 linux 开机日志,看 linux 内核是否能够发现你的网卡。
pci/pci-e/usb 这种网卡,linux是可以通过扫描总线发现你的设备的。 如果插上后 linux 还是没能发现你的网卡,那就是没找到对应的驱动程序。 手动编译对应设备的驱动模块,然后 sudo modprobe xxx.ko
, see link: http://blog.csdn.net/gw569453350game/article/details/53127800
dmesg | grep eth
[ 4.085406] e1000e 0000:00:19.0 eth0: (PCI Express:2.5GT/s:Width x1) 00:0b:ab:46:65:97
[ 4.085422] e1000e 0000:00:19.0 eth0: Intel(R) PRO/1000 Network Connection
[ 4.085499] e1000e 0000:00:19.0 eth0: MAC: 6, PHY: 8, PBA No: FFFFFF-0FF
[ 4.210613] e1000e 0000:03:00.0 eth1: registered PHC clock
[ 4.210628] e1000e 0000:03:00.0 eth1: (PCI Express:2.5GT/s:Width x1) 00:0b:ab:46:65:98
[ 4.210638] e1000e 0000:03:00.0 eth1: Intel(R) PRO/1000 Network Connection
[ 4.210740] e1000e 0000:03:00.0 eth1: MAC: 4, PHY: 8, PBA No: FFFFFF-0FF
[ 110.168445] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
4 . 查看系统硬件信息以及网卡驱动是否已经装好
sudo lshw -C network
例如,这里有三个网卡, eth0, eth1, wlan0,其中 eth1 没有开启:
*-network
description: Ethernet interface
product: 82567V-3 Gigabit Network Connection
vendor: Intel Corporation
physical id: 19
bus info: pci@0000:00:19.0
logical name: eth0
version: 04
serial: 00:0b:ab:46:65:97
size: 100Mbit/s
capacity: 1Gbit/s
width: 32 bits
clock: 33MHz
capabilities: pm msi bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=e1000e driverversion=3.2.6-k duplex=full firmware=0.4-0 ip=10.10.60.93 latency=0 link=yes multicast=yes port=twisted pair speed=100Mbit/s
resources: irq:26 memory:feac0000-feadffff memory:feafe000-feafefff ioport:c080(size=32)
*-network DISABLED
description: Ethernet interface
product: 82583V Gigabit Network Connection
vendor: Intel Corporation
physical id: 0
bus info: pci@0000:03:00.0
logical name: eth1
version: 00
serial: 00:0b:ab:46:65:98
capacity: 1Gbit/s
width: 32 bits
clock: 33MHz
capabilities: pm msi pciexpress msix bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=e1000e driverversion=3.2.6-k firmware=1.10-0 latency=0 link=no multicast=yes port=twisted pair
resources: irq:27 memory:febe0000-febfffff ioport:ec00(size=32) memory:febdc000-febdffff
*-network
description: Wireless interface
physical id: 1
bus info: usb@1:1
logical name: wlan0
serial: ac:a2:13:11:82:c4
capabilities: ethernet physical wireless
configuration: broadcast=yes driver=mt7601u driverversion=4.4.0-31-generic firmware=N/A ip=192.168.1.219 link=yes multicast=yes wireless=IEEE 802.11bgn
可以看出所有网卡的驱动都已经安装: driver=e1000e driverversion=3.2.6-k
5 . 从以上信息感觉硬件软件都没有问题,接上网线,手动获取 ip 地址试一下:
sudo dhclient -v eth0
# 如果 dhclient 没反应,多半是网卡设置或者 dhcp 服务器有点问题,可以手动设置 ip:
ifconfig eth0 192.168.1.111 netmask 255.255.255.0 // 必须加上netmask,否则 route add default gw 会失败
sudo route add default gw 192.168.1.1 // 添加网关
ifconfig // 查看是否能已经获得ip
ping 192.168.1.1 // ping 一下网关
这里又能引出另外一个问题 (see link: http://askubuntu.com/questions/575487/network-eth0-dhcp-static-ip-and-autonegotiation-issues),如果 sudo dhclient -v eth0
出现如下信息:
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 10 (xid=0x80d90217)
No DHCPOFFERS received.
No working leases in persistent database - sleeping.
则表示不能从 dhcp 服务器获得 ip,可能是网卡速率设置的问题,也可能是 dhcp 服务器的问题,不过我就遇到了网卡的设置问题,解决方法如下:
Turn off auto-negotiation on the server and fix the network speed to the highest level that the Network Interface Card (NIC) can sustain.
Start with 10Mbps, half duplex and work upwards to 10Mbps FD, 100Mbps HD, … until the problem starts. Then go down one notch and leave it at that speed.
First, install ethtool (if already installed you will just get a warning that the latest version is already installed)
sudo apt-get install ethtool
Now:
Type the following command (and test them one by one):
sudo ethtool --change eth0 speed xxx duplex yyy autoneg off
where xxx = 10, 100 or 1000 and yyy = half or full.
So start with 10 half, 10 full, 100 half, …
Do an ifconfig to check whether you got an IP address.
Go back to 1 until it stops working and use the previous values that still worked to:
To make the change permanent, execute the following command:sudo nano /etc/network/interfaces
and type at the pre-up section:
pre-up /usr/sbin/ethtool –change eth0 speed xxx duplex yyy autoneg off
找到允许的最大速率设置,写到 /etc/network/interfaces
中:
DHCP 的设置:
auto eth0
iface eth0 inet dhcp
pre-up ifconfig eth0 up
pre-up ethtool -s eth0 speed 100 duplex full autoneg off
Static 的设置:
auto eth0
iface eth0 inet static
post-up ethtool -s eth0 speed 100 duplex full autoneg off
address 192.168.1.111
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 10.10.10.10
6 . 如果是电脑的两个网卡连接在同一个局域网,关闭其中一个再试一下。
如果ping
不通其他电脑,可以尝试一下ping
网关(192.168.1.1),因为有可能是 windows 的防火墙没开启 回显请求-ICMPv4-In
To be continued …
国外牛人总结, jump to here: http://blog.csdn.net/gw569453350game/article/details/53021099
ref link:
1.http://www.tecmint.com/linux-network-configuration-and-troubleshooting-commands/
2.http://www.davidpashley.com/articles/network-troubleshooting/
3.http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:Ch04:_Simple_Network_Troubleshooting#DHCP_Considerations
4.http://askubuntu.com/questions/575487/network-eth0-dhcp-static-ip-and-autonegotiation-issues