Linux RTL8111/RTL8168 不能联网 / 驱动下载安装
斐夷所非 2024-09-08 10:37:02 阅读 94
注: 机翻,未校。
How to get an Realtek RTL8111/RTL8168 working under Linux
如何让 Realtek RTL8111/RTL8168 在 Linux 下工作
TuxByte, Feb 07, 2024
So, this article was released in August 2016 on my original blog. Even though the situation with RTL8111/RTL8168 network interfaces under Linux has become more and more stable these days, they still can cause problems like packet loss or an unstable network connection in general.
这篇文章于 2016 年 8 月在我的原始博客上发布。尽管 Linux 下 RTL8111/RTL8168 网络接口的情况如今越来越稳定,但它们仍然会导致数据包丢失或网络连接不稳定等问题。
With this short guide I want to show you how to install the r8168 instead of the r8169 driver. The r8169 driver is default by most Linux distributions these days. The r8168 driver is sometimes more stable but not enabled by default due to license restrictions. This guide describes two ways to install the r8168 driver.
通过这个简短的指南,我想向您展示如何安装 r8168 而不是 r8169 驱动程序。r8169 驱动程序是当今大多数 Linux 发行版的默认驱动程序。r8168 驱动程序有时更稳定,但由于许可证限制,默认情况下不启用。本指南介绍了两种安装 r8168 驱动程序的方法。
Requirements
要求
This guide assumes that you have a working network connection. If you already have a Wi-Fi / ethernet adapter / dongle you can simply use this one or you can buy yourself an USB ethernet adapter or Wi-Fi dongle which is fully supported by the Linux kernel. An additional network adapter is only required if you can’t download the packages with your actual RTL8111/RTL8168 and the r8169 driver (for e.g. because you’re already experiencing a massive packet loss / connection interruptions). An alternative would be to download each package individually (the r8168 driver AND dependencies) from another computer and transfer it with an USB stick. But using an USB ethernet adapter is definitly the way more convenient way here.
本指南假定您有一个有效的网络连接。如果您已经有 Wi-Fi / 以太网适配器 / 加密狗,您可以简单地使用它,或者您可以自己购买 Linux 内核完全支持的 USB 以太网适配器或 Wi-Fi 加密狗。只有当您无法下载带有实际 RTL8111/RTL8168 和 r8169 驱动程序的软件包时(例如,因为您已经遇到了大量的数据包丢失/连接中断),才需要额外的网络适配器。另一种方法是从另一台计算机单独下载每个软件包(r8168 驱动程序和依赖项),然后用 U 盘传输。但是使用 USB 以太网适配器绝对是更方便的方式。
The automatic way (only for Debian and Ubuntu)
自动方式(仅适用于 Debian 和 Ubuntu)
Debian added the r8168 driver a few years ago to their non-free repository. With that being said, if you haven’t enabled the non-free repository in your Debian installation yet, you have to do this now. If you’re using the latest Debian release (as of writing this article the latest one being bookworm), you have to adjust your /etc/apt/sources.list file like this:
Debian 几年前将 r8168 驱动程序添加到他们的非自由仓库中。话虽如此,如果你还没有在 Debian 安装中启用 non-free 仓库,你现在必须这样做。如果你使用的是最新的 Debian 版本(在撰写本文时,最新的版本是 bookworm),你必须像这样调整你的 /etc/apt/sources.list 文件:
<code>deb http://deb.debian.org/debian/ bookworm main contrib non-free
For Ubuntu their non-free repository is called universe. With Ubuntu 22.04 it is most likely already enabled. You can check your /etc/apt/sources.list and if the universe repository is missing adjust the file so that it contains something like this:
对于 Ubuntu,他们的非自由仓库称为 universe。在 Ubuntu 22.04 中,它很可能已经启用。你可以检查你的 /etc/apt/sources.list,如果缺少 Universe 仓库,请调整文件,使其包含如下内容:
deb http://archive.ubuntu.com/ubuntu/ jammy main restricted universe
After you enabled the non-free / universe repository you can refresh the packages list and install the r8168 driver like this:
启用 non-free / universe 仓库后,您可以刷新软件包列表并安装 r8168 驱动程序,如下所示:
user@ubuntu:~$ sudo apt update && sudo apt install r8168-dkms
The driver is compiled for your running Linux kernel. The packages utilizes DKMS to do this. DKMS ensures that the driver is always rebuild when there is a Linux kernel update installed. Depending on your CPU, the compilation could take a few minutes. After the compilation / installation is finished, reboot your machine. You should be able to use your network interface now as expected without any network issues or package loss. You can also check which driver is being used on the command line:
该驱动程序是针对您正在运行的 Linux 内核编译的。这些软件包利用 DKMS 来做到这一点。DKMS 确保在安装 Linux 内核更新时始终重建驱动程序。根据您的 CPU,编译可能需要几分钟时间。编译/安装完成后,重新启动计算机。您现在应该能够按预期使用网络接口,而不会出现任何网络问题或软件包丢失。
您还可以在命令行上检查正在使用的驱动程序:
user@ubuntu:~$ lspci -v | grep -A8 Ethernet | grep -A8 Realtek
[...]
Kernel driver in use: r8168
The manual way (for all distribution, not recommended)
手动方式(适用于所有发行版,不推荐)
The manual way is a little bit more complicated and I definitely don’t recommend this anymore. However, if your Linux distribution doesn’t ship the r8168 driver on one way or another, you may be forced to go this route. A huge disadvantage with going this way is, that you have to recompile the driver on your own everytime you update your kernel. So keep that in mind. Otherwise your network card will most likely not work after a kernel update and reboot of your system.
手动方式稍微复杂一些,我绝对不推荐再这样做了。但是,如果您的 Linux 发行版没有以某种方式提供 r8168 驱动程序,您可能会被迫走这条路。这种方式的一个巨大缺点是,每次更新内核时,您都必须自己重新编译驱动程序
。所以请记住这一点。否则,在内核更新和重启系统后,您的网卡很可能无法正常工作
。
In order to compile the r8168 driver on your own, you have to install the kernel headers and compilation utilities like gcc, make and configure. For Debian and Ubuntu systems you can install all the dependencies like this:
为了自己编译 r8168 驱动程序,您必须安装内核头文件和编译工具,如 gcc、make 和 configure。对于 Debian 和 Ubuntu 系统,您可以安装所有依赖项,如下所示:
user@ubuntu:~$ sudo apt update && sudo apt install build-essentials linux-headers-$(uname -r)
Next step is to download the driver. The official homepage from Realtek seems to not provide the driver anymore. Because of this we have to use a mirror on GitHub, provided by mtorromeo. You can use wget to download the driver directly like this (always check for the latest version on GitHub first):
下一步是下载驱动程序。Realtek 的官方主页似乎不再提供驱动程序(本文作者可能没找到,官方可用,下文提供)
。因此,我们必须使用 GitHub 上的镜像,由 mtorromeo 提供。你可以像这样直接使用 wget 下载驱动程序(总是先在 GitHub 上检查最新版本):
user@linux:~$ wget https://github.com/mtorromeo/r8168/archive/refs/tags/8.052.01.tar.gz
We have to ensure that the r8169 driver isn’t loaded when booting the machine in the future. The following command ensures this:
我们必须确保将来启动机器时不会加载 r8169 驱动程序。以下命令可确保这一点:
user@linux:~$ sudo sh -c 'echo blacklist r8169 >> /etc/modprobe.d/blockr8169.conf'
As next we can extract the previously downloaded driver archive:
接下来,我们可以提取以前下载的驱动程序存档:
user@linux:~$ tar xfvz r8168-8.052.01.tar.gz
With extracting the driver archive, there is a new folder with the same name scheme which we can change into:
解压缩驱动程序存档后,有一个具有相同名称方案的新文件夹,我们可以将其更改为:
user@linux:~$ cd r8168-8.052.01
NOTICE: The number can change, depending on the version of the driver in the future. So don’t forget to change the version number if needed.
注意: 该编号可能会更改,具体取决于将来的驱动程序版本。因此,如果需要,请不要忘记更改版本号。
Now that we are in the correct directory, we can finally start compiling the driver. To do so, simply enter the following command:
现在我们位于正确的目录中,我们终于可以开始编译驱动程序了。为此,只需输入以下命令:
user@linux:~/r8168-8.052.01$ sudo ./autorun.sh
You should then see an output like this one:
然后,您应该会看到如下所示的输出:
Check old driver and unload it.
rmmod r8168
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:178
sign-file: certs/signing_key.pem: No such file or directory
Backup r8169.ko
rename r8169.ko to r8169.bak
DEPMOD 4.4.0-31-generic
load module r8168
Updating initramfs. Please wait.
update-initramfs: Generating /boot/initrd.img-4.4.0-31-generic
Completed.
You can ignore the SSL error for now. The driver should be successfully compiled and installed into your system. The driver is already loaded and should work.
您现在可以忽略 SSL 错误。驱动程序应该已成功编译并安装到您的系统中。驱动程序已加载,应该可以正常工作。
To ensure that the driver is really used and loaded, you can use the same command as mentioned above:
要确保驱动程序被真正使用和加载,您可以使用与上述相同的命令:
user@ubuntu:~$ lspci -v | grep -A8 Ethernet | grep -A8 Realtek
[...]
Kernel driver in use: r8168
Also a user called Tim on my old blog mentioned ethtool which does the same and helps you to check if the correct driver is in use:
此外,在我的旧博客上,一位名叫 Tim 的用户提到了 ethtool,它做了同样的事情,并帮助你检查是否使用了正确的驱动程序:
user@linux:~$ sudo ethtool -i enp1s0
driver: r8168
version: 8.042.00-NAPI
firmware-version:
expansion-rom-version:
bus-info: 0000:07:00.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no
NOTE: You have to change enp1s0 to the device name of your network card. This can be eth0, eth1, enp2s0, and so on.
注意:您必须将 enp1s0 更改为网卡的设备名称。这可以是 eth0、eth1、enp2s0 等。
If r8168 is mentioned, the driver was installed correctly and you should be able use your network card now without any package loss or interruptions.
如果提到的 r8168 驱动程序安装正确,您现在应该能够使用您的网卡而不会丢失或中断任何软件包。
via:
How to get an Realtek RTL8111/RTL8168 working under Linux TUXBYTE FEB 07, 2024
https://tuxbyte.com/p/how-to-get-an-realtek-rtl8111rtl8168
驱动下载
Realtek 官方最新驱动下载
https://www.realtek.com/Download/List?cate_id=584
GitHub - mtorromeo/r8168: Linux device driver for Realtek Ethernet controllers ( unofficial mirror )
https://github.com/mtorromeo/r8168
其他型号 r 系列老驱动下载 r8168dl/files at master・bfanger/r8168dl・GitHub
https://github.com/bfanger/r8168dl/tree/master/files
注:来自下文 csdn 博主“小怪物爱吹牛”的安装提示 :…网卡信息还有 8111,但逐个试过之后只有 8168 可以用。
ubuntu20 解决网线不能联网 RTL8111/8168/8411
这种问题一般是驱动没有正确安装。
----RTL8111/8168/8411 是一块比较坑的网卡。
1、 查看网卡信息
lspci |grep Ethernet
2、 对于高版本的 Ubuntu,能直接使用命令安装驱动。下面的 r8168-dkms 需根据网卡信息修改,上面的网卡信息还有 8111,但<code>逐个试过之后只有 8168 可以用。
sudo apt install r8168-dkms
3、 测试手动能不能加载内核模块,如果 lsmod 能够显示信息,表明模块安装成功。
sudo modprobe r8168
lsmod |grep r8168
如果手动都不能加载 r8168,那就只能手动安装驱动。
a) 官网下载
b) 解压
<code>tar -jxvf r8168-8.053.00.tar.bz2
c) 编译安装
cd r8168-8.053.00/src
sudo make all
cd ../
sudo ./autorun.sh
4、重启电脑,看 r8168.ko 会不会被自动加载,如果重启后下面的命令没有显示信息,表明网卡内核驱动模块不能被自动加载。
lsmod |grep r8168
5、解决模块不能被自动加载的问题,系统服务的方法更安全
sudo vim /etc/systemd/system/load-r8168.service
添加如下配置
[Unit]
Description=Load r8168 module at boot
After=network.target
[Service]
Type=oneshot
ExecStart=/sbin/modprobe r8168
[Install]
WantedBy=multi-user.target
执行命令
sudo systemctl enable load-r8168.service
重启电脑,即可自动加载模块 r8168.ko
via:
ubuntu20 解决网线不能联网 RTL8111/8168/8411-CSDN 博客 小怪物爱吹牛 于 2024-04-18 16:15:43
https://blog.csdn.net/naibula/article/details/137924693
下一篇: [Linux#47][网络] 网络协议 | TCP/IP模型 | 以太网通信
本文标签
声明
本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。