Linux 无线网络断开的解决方案
作者:互联网
Linux 系统用着用着突然发现电脑上的 WiFi 图标不见了,电脑无法连接到无线网。这可急坏了,找遍设置也没找到哪里可以重新打开无线网,感觉就像是凭空消失了一样。折腾了一天,终于把无线网络恢复正常了。
这篇文章就来梳理一下在 Linux 上修复无线网络的一些简单常用的操作。
首先,CTRL + ALT + T
打开 bash,我们可以使用 rfkill
命令查看无线设备的状态。
-
<span style="color:#000000"><code class="language-bash">$<span style="color:#669900">></span> rfkill list
-
<span style="color:#5c6370"># 正常情况应该显示如下内容</span>
-
0: hci0: Bluetooth
-
Soft blocked: no
-
Hard blocked: no
-
1: phy0: Wireless LAN
-
Soft blocked: no
-
Hard blocked: no
-
</code></span>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 注:
rfkill
是一个内核级的无线设备管理工具,意为 radio frequency kill 。
- 如果无线网络设备(Wireless LAN)显示
Soft blocked: yes
,即软阻塞,通常原因是软件层面关闭了无线网络。笔记本电脑可以看看是否误触到了飞行模式按键,导致无线网络被关闭。飞行模式按键通常是Fn + F12
或Fn + INSERT
。rfkill
也提供了如下命令来解除软阻塞:
-
<span style="color:#000000"><code class="language-bash">$<span style="color:#669900">></span> rfkill unblock wlan <span style="color:#5c6370">#解除无线网络的软阻塞</span>
-
</code></span>
- 1
- 如果显示
Hard blocked: yes
,即硬阻塞,通常原因是网卡或网卡驱动损坏,网卡损坏的几率相对较小,可以尝试重新安装驱动是否能够解决问题。使用lspci
指令查看电脑网卡的型号,然后从网上下载对应型号的网卡驱动进行编译安装。
-
<span style="color:#000000"><code class="language-bash">lspci <span style="color:#669900">|</span> <span style="color:#61aeee">grep</span> Ethernet
-
</code></span>
- 1
- 注:
lspci
指令用于查看所有的 pci 设备信息。pci 是一种总线,pci 设备就是通过 pci 总线连接的设备。如今,我们常用的设备大部分都采用的是 pci 总线,如网卡、存储等。
rfkill
命令显示的内容正常后,我们再用 ifconfig
命令查看网络设备的状态。
-
<span style="color:#000000"><code class="language-bash">$<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span>
-
eno1: flags<span style="color:#669900">=</span>4099<span style="color:#669900"><</span>UP,BROADCAST,MULTICAST<span style="color:#669900">></span> mtu 1500
-
ether 84:a9:3a:1c:7f:e4 txqueuelen 1000 <span style="color:#999999">(</span>Ethernet<span style="color:#999999">)</span>
-
RX packets 0 bytes 0 <span style="color:#999999">(</span>0.0 B<span style="color:#999999">)</span>
-
RX errors 0 dropped 0 overruns 0 frame 0
-
TX packets 0 bytes 0 <span style="color:#999999">(</span>0.0 B<span style="color:#999999">)</span>
-
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
lo: flags<span style="color:#669900">=</span>73<span style="color:#669900"><</span>UP,LOOPBACK,RUNNING<span style="color:#669900">></span> mtu 65536
-
inet 127.0.0.1 netmask 255.0.0.0
-
inet6 ::1 prefixlen 128 scopeid 0x10<span style="color:#669900"><</span>host<span style="color:#669900">></span>
-
loop txqueuelen 1000 <span style="color:#999999">(</span>Local Loopback<span style="color:#999999">)</span>
-
RX packets 736 bytes 59264 <span style="color:#999999">(</span>57.8 KiB<span style="color:#999999">)</span>
-
RX errors 0 dropped 0 overruns 0 frame 0
-
TX packets 736 bytes 59264 <span style="color:#999999">(</span>57.8 KiB<span style="color:#999999">)</span>
-
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
</code></span>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
可以看到,此时可用的网络设备只显示了有线网卡(以太网接口 eno1)和回环接口(lo),并没有显示无线网卡。如果使用 -a
参数展示所有的网络设备,则可以看到无线网卡(wlo1)的信息。
-
<span style="color:#000000"><code class="language-bash">$<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span> -a
-
eno1: flags<span style="color:#669900">=</span>4099<span style="color:#669900"><</span>UP,BROADCAST,MULTICAST<span style="color:#669900">></span> mtu 1500
-
ether 84:a9:3a:1c:7f:e4 txqueuelen 1000 <span style="color:#999999">(</span>Ethernet<span style="color:#999999">)</span>
-
RX packets 0 bytes 0 <span style="color:#999999">(</span>0.0 B<span style="color:#999999">)</span>
-
RX errors 0 dropped 0 overruns 0 frame 0
-
TX packets 0 bytes 0 <span style="color:#999999">(</span>0.0 B<span style="color:#999999">)</span>
-
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
lo: flags<span style="color:#669900">=</span>73<span style="color:#669900"><</span>UP,LOOPBACK,RUNNING<span style="color:#669900">></span> mtu 65536
-
inet 127.0.0.1 netmask 255.0.0.0
-
inet6 ::1 prefixlen 128 scopeid 0x10<span style="color:#669900"><</span>host<span style="color:#669900">></span>
-
loop txqueuelen 1000 <span style="color:#999999">(</span>Local Loopback<span style="color:#999999">)</span>
-
RX packets 736 bytes 59264 <span style="color:#999999">(</span>57.8 KiB<span style="color:#999999">)</span>
-
RX errors 0 dropped 0 overruns 0 frame 0
-
TX packets 736 bytes 59264 <span style="color:#999999">(</span>57.8 KiB<span style="color:#999999">)</span>
-
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
wlo1: flags<span style="color:#669900">=</span>4098<span style="color:#669900"><</span>BROADCAST,MULTICAST<span style="color:#669900">></span> mtu 1500
-
ether 18:1e:ea:a6:0b:5f txqueuelen 1000 <span style="color:#999999">(</span>Ethernet<span style="color:#999999">)</span>
-
RX packets 0 bytes 0 <span style="color:#999999">(</span>0.0 B<span style="color:#999999">)</span>
-
RX errors 0 dropped 0 overruns 0 frame 0
-
TX packets 0 bytes 0 <span style="color:#999999">(</span>0.0 B<span style="color:#999999">)</span>
-
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
-
</code></span>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
这说明,虽然阻塞问题被我们解决了,但无线网卡仍处于关闭状态。我们需要手动开启无线网卡。
-
<span style="color:#000000"><code class="language-bash">$<span style="color:#669900">></span> <span style="color:#61aeee">sudo</span> <span style="color:#61aeee">ifconfig</span> wlo1 up
-
</code></span>
- 1
开启后,再执行 ifconfig
命令就能够看到无线网卡(wlo1)的信息啦。等待一会儿之后,WiFi 的图标就能又重新出现在了我们的桌面上啦~
如果仍没有效果,可以尝试重启网络服务。
-
<span style="color:#000000"><code class="language-bash">$<span style="color:#669900">></span> systemctl restart network-manager
-
</code></span>
- 1
- 注:
systemctl
命令常用于管理服务的启动和关闭,意为 system control 。
ifconfig
是在 Linux 上调试网络的重要工具,下面列举了 ifconfig
的一些常用操作。
-
<span style="color:#000000"><code class="language-bash"><span style="color:#5c6370"># 显示 up 状态的网络设备信息</span>
-
$<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span>
-
<span style="color:#5c6370"># 显示所有网络设备信息 </span>
-
$<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span> -a
-
<span style="color:#5c6370"># 启动 eth0 网卡 </span>
-
$<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span> eth0 up
-
<span style="color:#5c6370"># 关闭 eth0 网卡</span>
-
$<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span> eth0 down
-
<span style="color:#5c6370"># 给 eth0 网卡配置IP地址</span>
-
$<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span> eth0 192.168.1.56
-
<span style="color:#5c6370"># 给 eth0 网卡配置IP地址,并加上子掩码 </span>
-
$<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span> eth0 192.168.1.56 netmask 255.255.255.0
-
</code></span>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
希望本文能够帮助大家快速定位到病灶,顺利解决遇到的问题!
标签:errors,断开,bytes,RX,ifconfig,网卡,dropped,Linux,无线网络 来源: https://blog.csdn.net/its666/article/details/110429167