系统相关
首页 > 系统相关> > Linux 无线网络断开的解决方案

Linux 无线网络断开的解决方案

作者:互联网

Linux 系统用着用着突然发现电脑上的 WiFi 图标不见了,电脑无法连接到无线网。这可急坏了,找遍设置也没找到哪里可以重新打开无线网,感觉就像是凭空消失了一样。折腾了一天,终于把无线网络恢复正常了。

这篇文章就来梳理一下在 Linux 上修复无线网络的一些简单常用的操作。

首先,CTRL + ALT + T 打开 bash,我们可以使用 rfkill 命令查看无线设备的状态。

 
  1. <span style="color:#000000"><code class="language-bash">$<span style="color:#669900">></span> rfkill list

  2. <span style="color:#5c6370"># 正常情况应该显示如下内容</span>

  3. 0: hci0: Bluetooth

  4. Soft blocked: no

  5. Hard blocked: no

  6. 1: phy0: Wireless LAN

  7. Soft blocked: no

  8. Hard blocked: no

  9. </code></span>

  1. 如果无线网络设备(Wireless LAN)显示 Soft blocked: yes ,即软阻塞,通常原因是软件层面关闭了无线网络。笔记本电脑可以看看是否误触到了飞行模式按键,导致无线网络被关闭。飞行模式按键通常是 Fn + F12 或 Fn + INSERT 。 rfkill 也提供了如下命令来解除软阻塞:
 
  1. <span style="color:#000000"><code class="language-bash">$<span style="color:#669900">></span> rfkill unblock wlan <span style="color:#5c6370">#解除无线网络的软阻塞</span>

  2. </code></span>

  1. 如果显示 Hard blocked: yes ,即硬阻塞,通常原因是网卡或网卡驱动损坏,网卡损坏的几率相对较小,可以尝试重新安装驱动是否能够解决问题。使用 lspci 指令查看电脑网卡的型号,然后从网上下载对应型号的网卡驱动进行编译安装。
 
  1. <span style="color:#000000"><code class="language-bash">lspci <span style="color:#669900">|</span> <span style="color:#61aeee">grep</span> Ethernet

  2. </code></span>

rfkill 命令显示的内容正常后,我们再用 ifconfig 命令查看网络设备的状态。

 
  1. <span style="color:#000000"><code class="language-bash">$<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span>

  2. eno1: flags<span style="color:#669900">=</span>4099<span style="color:#669900"><</span>UP,BROADCAST,MULTICAST<span style="color:#669900">></span> mtu 1500

  3. ether 84:a9:3a:1c:7f:e4 txqueuelen 1000 <span style="color:#999999">(</span>Ethernet<span style="color:#999999">)</span>

  4. RX packets 0 bytes 0 <span style="color:#999999">(</span>0.0 B<span style="color:#999999">)</span>

  5. RX errors 0 dropped 0 overruns 0 frame 0

  6. TX packets 0 bytes 0 <span style="color:#999999">(</span>0.0 B<span style="color:#999999">)</span>

  7. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  8.  
  9. lo: flags<span style="color:#669900">=</span>73<span style="color:#669900"><</span>UP,LOOPBACK,RUNNING<span style="color:#669900">></span> mtu 65536

  10. inet 127.0.0.1 netmask 255.0.0.0

  11. inet6 ::1 prefixlen 128 scopeid 0x10<span style="color:#669900"><</span>host<span style="color:#669900">></span>

  12. loop txqueuelen 1000 <span style="color:#999999">(</span>Local Loopback<span style="color:#999999">)</span>

  13. RX packets 736 bytes 59264 <span style="color:#999999">(</span>57.8 KiB<span style="color:#999999">)</span>

  14. RX errors 0 dropped 0 overruns 0 frame 0

  15. TX packets 736 bytes 59264 <span style="color:#999999">(</span>57.8 KiB<span style="color:#999999">)</span>

  16. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  17. </code></span>

可以看到,此时可用的网络设备只显示了有线网卡(以太网接口 eno1)和回环接口(lo),并没有显示无线网卡。如果使用 -a 参数展示所有的网络设备,则可以看到无线网卡(wlo1)的信息。

 
  1. <span style="color:#000000"><code class="language-bash">$<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span> -a

  2. eno1: flags<span style="color:#669900">=</span>4099<span style="color:#669900"><</span>UP,BROADCAST,MULTICAST<span style="color:#669900">></span> mtu 1500

  3. ether 84:a9:3a:1c:7f:e4 txqueuelen 1000 <span style="color:#999999">(</span>Ethernet<span style="color:#999999">)</span>

  4. RX packets 0 bytes 0 <span style="color:#999999">(</span>0.0 B<span style="color:#999999">)</span>

  5. RX errors 0 dropped 0 overruns 0 frame 0

  6. TX packets 0 bytes 0 <span style="color:#999999">(</span>0.0 B<span style="color:#999999">)</span>

  7. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  8.  
  9. lo: flags<span style="color:#669900">=</span>73<span style="color:#669900"><</span>UP,LOOPBACK,RUNNING<span style="color:#669900">></span> mtu 65536

  10. inet 127.0.0.1 netmask 255.0.0.0

  11. inet6 ::1 prefixlen 128 scopeid 0x10<span style="color:#669900"><</span>host<span style="color:#669900">></span>

  12. loop txqueuelen 1000 <span style="color:#999999">(</span>Local Loopback<span style="color:#999999">)</span>

  13. RX packets 736 bytes 59264 <span style="color:#999999">(</span>57.8 KiB<span style="color:#999999">)</span>

  14. RX errors 0 dropped 0 overruns 0 frame 0

  15. TX packets 736 bytes 59264 <span style="color:#999999">(</span>57.8 KiB<span style="color:#999999">)</span>

  16. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  17.  
  18. wlo1: flags<span style="color:#669900">=</span>4098<span style="color:#669900"><</span>BROADCAST,MULTICAST<span style="color:#669900">></span> mtu 1500

  19. ether 18:1e:ea:a6:0b:5f txqueuelen 1000 <span style="color:#999999">(</span>Ethernet<span style="color:#999999">)</span>

  20. RX packets 0 bytes 0 <span style="color:#999999">(</span>0.0 B<span style="color:#999999">)</span>

  21. RX errors 0 dropped 0 overruns 0 frame 0

  22. TX packets 0 bytes 0 <span style="color:#999999">(</span>0.0 B<span style="color:#999999">)</span>

  23. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

  24. </code></span>

这说明,虽然阻塞问题被我们解决了,但无线网卡仍处于关闭状态。我们需要手动开启无线网卡。

 
  1. <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

  2. </code></span>

开启后,再执行 ifconfig 命令就能够看到无线网卡(wlo1)的信息啦。等待一会儿之后,WiFi 的图标就能又重新出现在了我们的桌面上啦~

如果仍没有效果,可以尝试重启网络服务。

 
  1. <span style="color:#000000"><code class="language-bash">$<span style="color:#669900">></span> systemctl restart network-manager

  2. </code></span>

ifconfig 是在 Linux 上调试网络的重要工具,下面列举了 ifconfig 的一些常用操作。

 
  1. <span style="color:#000000"><code class="language-bash"><span style="color:#5c6370"># 显示 up 状态的网络设备信息</span>

  2. $<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span>

  3.  
  4. <span style="color:#5c6370"># 显示所有网络设备信息 </span>

  5. $<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span> -a

  6.  
  7. <span style="color:#5c6370"># 启动 eth0 网卡 </span>

  8. $<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span> eth0 up

  9.  
  10. <span style="color:#5c6370"># 关闭 eth0 网卡</span>

  11. $<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span> eth0 down

  12.  
  13. <span style="color:#5c6370"># 给 eth0 网卡配置IP地址</span>

  14. $<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span> eth0 192.168.1.56

  15.  
  16. <span style="color:#5c6370"># 给 eth0 网卡配置IP地址,并加上子掩码 </span>

  17. $<span style="color:#669900">></span> <span style="color:#61aeee">ifconfig</span> eth0 192.168.1.56 netmask 255.255.255.0

  18. </code></span>

希望本文能够帮助大家快速定位到病灶,顺利解决遇到的问题!

标签:errors,断开,bytes,RX,ifconfig,网卡,dropped,Linux,无线网络
来源: https://blog.csdn.net/its666/article/details/110429167