新电脑是自己组装的,主板是华硕TUF GAMING B460M-PRO。在安装ubuntu18.04后无法识别以太网。
ifconfig 后只有回环地址127.0.0.1
先查询了网卡型号:lspci | grep -i ethernet
~# lspci | grep -i ethernet
04:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. Device 8125 (rev 05)
得知网卡类型为瑞昱Realtek@ RTL8125-CG 2.5G LAN
网上下载了r8125-9.009.01.tar.bz 这个驱动安装包。
解压后 执行sudo ./autorun,sh完成安装。
但是这个方法重启后无效。
网上给的建议是用什么dkms,感觉好麻烦,所以想每次启动时执行一个脚本不就行了。
下面是执行步骤。
首先明白,ubuntu18是没有/etc/rc.d/rc.local 这个玩儿意儿的,所以网上修改它的方法都没用。
所以要修改开机启动项,
一般正常的启动文件主要分成三部分。
[Unit] 段: 启动顺序与依赖关系
[Service] 段: 启动行为,如何启动,启动类型
[Install] 段: 定义如何安装这个配置文件,即怎样做到开机启动
新安装的程序只有前两项,即:
sudo vim /lib/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
在此基础上增加 Install 段,少了 Install 段,也就没有定义如何做到开机启动,配置也就无效的,所以增加一个 Install 段。
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
Ubuntu 18版本默认是没有rc.local这个文件(/etc/rc.local),所以新建这个文件。
#!/bin/bash
//命令添加在exit 0之前。里面可以直接写命令或者执行Shell脚本文件sh
sudo cd /home/**/r8125-9.009.01
sudo ./autorun.sh
sudo cd -
exit 0
chmod +x /etc/rc.local
再重启试试。