[转] Ubuntu 16.04 RTL8111/8168/8411 不能上网 经常断网解决办法

系统环境:
OS: Ubuntu 16.04 LTS 64位
  之前也遇到过这样的问题,使用有线网络上网时,有时会出现断网的现象,不过一般重新启用网络后就可以用了。但是这次断网后,却怎么也连不上网了。后来上网查了很久,终于找到原因了,是网卡的驱动问题导致的。
查找问题
首先,查看系统 Log:

1
2
3
4
5
6
# cat /var/log/syslog | grep enp
NetworkManager[1002]: <info> [1494831368.7343] device (enp3s0): state change: disconnected -> unmanaged (reason 'sleeping') [30 10 37]
NetworkManager[1002]: <info> [1494831368.7589] device (enp3s0): link disconnected
NetworkManager[1002]: <info> [1494831376.6517] device (enp3s0): state change: unmanaged -> unavailable (reason 'managed') [10 20 2]
kernel: [ 602.158370] IPv6: ADDRCONF(NETDEV_UP): enp3s0: link is not ready
kernel: [ 602.286519] r8169 0000:03:00.0 enp3s0: link down

之后执行如下命令查看系统内核版本:

1
2
# uname -a
Linux ubuntupc 4.4.0-77-generic #98-Ubuntu SMP Wed Apr 26 08:34:02 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

然后查看网卡及使用的驱动信息:

1
2
3
4
5
6
7
# lspci -knn
......
......
03:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller [10ec:8168] (rev 06)
Subsystem: Dell RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller [1028:0585]
Kernel driver in use: r8169
Kernel modules: r8169

注意以上信息表明,网卡为 Dell RTL8111/8168/8411,但是使用的驱动却是 “r8169”,所以这就是问题所在。
Tips:
也可以执行下面的命令查看网卡及版本信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# lshw -C network
*-network
description: Ethernet interface
product: RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
vendor: Realtek Semiconductor Co., Ltd.
physical id: 0
bus info: pci@0000:03:00.0
logical name: enp3s0
version: 06
serial: xx:bb:cc:yy:dd:zz
size: 100Mbit/s
capacity: 1Gbit/s
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress msix vpd bus_master cap_list ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=r8169 driverversion=2.3LK-NAPI duplex=full firmware=rtl8168e-3_0.0.4 03/27/12 ip=192.168.21.189 latency=0 link=yes multicast=yes port=MII speed=100Mbit/s
resources: irq:26 ioport:d000(size=256) memory:f2104000-f2104fff memory:f2100000-f2103fff
......
......

其中的 driver=r8169 driverversion=2.3LK-NAPI 为网卡的驱动版本。
驱动下载
之后在官网下载对应内核版本的驱动程序:
http://www.realtek.com.tw/downloads/downloadsView.aspx?Langid=1&PNid=13&PFid=5&Level=5&Conn=4&DownTypeID=3&GetDown=false#2
下载 Unix (Linux) 中的 LINUX driver for kernel up to 4.7 驱动文件。
驱动安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# tar xjvf 0009-r8168-8.044.02.tar.bz2
# cd r8168-8.044.02/
# ./autorun.sh
Check old driver and unload it.
rmmod r8169
Build the module and install
At main.c:222:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:175
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:182
sign-file: certs/signing_key.pem: No such file or directory
Backup r8169.ko
rename r8169.ko to r8169.bak
DEPMOD 4.4.0-77-generic
load module r8168
Updating initramfs. Please wait.
update-initramfs: Generating /boot/initrd.img-4.4.0-77-generic
Completed.

之后重启电脑(最好再重新启用下网络连接)即可。
参考文献:

坚持原创及高品质技术分享,您的支持将鼓励我继续创作!