Raspbian命令行连接WiFi网络

Raspbian命令行连接WiFi网络

  • [1. 源由](#1. 源由)
  • [2. 环境](#2. 环境)
  • [3. 信号](#3. 信号)
  • [4. 连接](#4. 连接)
  • [5. 检查](#5. 检查)
  • [6. 断开](#6. 断开)

1. 源由

"懒人"多福,是什么原因,大家知道不,哈哈。

如果大家关注过之前《Ardupilot开源代码之Rover上路计划》,为了笔记本电脑在不断网的情况下进行配置树莓派,通常直接将网线连过去。

为了省去连网线这个步骤,就直接用一个usb无线网卡连接笔记本连接的路由器。

2. 环境

看了这个环境,大家要问:

  1. 树莓派不是自带了一个无线嘛,你直接连这个WiFi或者让这个WiFi连笔记本的路由器不就好了嘛?

那是因为装了伴机电脑,用作AP了。

  1. 上面不是有个VPN呢,为啥不用这个?

确实有VPN,但是4G卡没有插,也不是一直开着4G的。

所以就另外插了一个小的USBWiFi网卡,这个就是偷懒的方法

bash 复制代码
$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.201  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 2408:8240:610:9d30:e301:92a8:f296:4a2c  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::e6a4:f90a:cb72:9166  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:f3:69:a6  txqueuelen 1000  (Ethernet)
        RX packets 14578  bytes 2794676 (2.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 63410  bytes 53220714 (50.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 3727  bytes 807790 (788.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3727  bytes 807790 (788.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.100  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::e294:8cc7:c0e0:dc9e  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:a6:3c:f3  txqueuelen 1000  (Ethernet)
        RX packets 672  bytes 81754 (79.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 18636  bytes 18470468 (17.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether de:70:66:73:d0:07  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

zt44xhvvrc: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 2800
        inet 172.24.161.33  netmask 255.255.0.0  broadcast 172.24.255.255
        inet6 fe80::4c84:edff:fe49:df6  prefixlen 64  scopeid 0x20<link>
        ether 4e:84:ed:49:0d:f6  txqueuelen 1000  (Ethernet)
        RX packets 99  bytes 7899 (7.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 108  bytes 17153 (16.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

3. 信号

bash 复制代码
 $ nmcli dev wifi list
IN-USE  BSSID              SSID     MODE   CHAN  RATE      SIGNAL  BARS  SECURITY
*       B8:27:EB:A6:3C:F3  rpanion  Infra  1     0 Mbit/s  0       ____  WPA1 WPA2

IN-USE  BSSID              SSID           MODE   CHAN  RATE        SIGNAL  BARS  SECURITY
        B8:F8:83:6E:16:9F  AutoConnect    Infra  1     405 Mbit/s  100     ▂▄▆█  WPA1 WPA2
        3E:06:A7:46:A8:B0  --             Infra  6     195 Mbit/s  67      ▂▄▆_  WPA1 WPA2
        3C:06:A7:56:A8:B0  402            Infra  6     195 Mbit/s  67      ▂▄▆_  WPA1 WPA2
        46:FB:5A:1F:7B:DC  CMCC_Share     Infra  9     130 Mbit/s  67      ▂▄▆_  --
        46:FB:5A:2F:7B:DC  SSID3          Infra  9     130 Mbit/s  64      ▂▄▆_  WPA1 WPA2
        44:FB:5A:3F:7B:DC  CMCC-e33Q      Infra  9     130 Mbit/s  60      ▂▄▆_  WPA1 WPA2
        80:7E:B4:D9:E9:11  SJPSTAR        Infra  11    130 Mbit/s  60      ▂▄▆_  WPA1 WPA2
        48:CA:C6:9F:0B:52  206            Infra  11    130 Mbit/s  57      ▂▄▆_  WPA1 WPA2
        4A:CA:C6:BF:0B:52  --             Infra  11    130 Mbit/s  54      ▂▄__  WPA2
        84:65:69:D9:F4:6D  --             Infra  1     130 Mbit/s  47      ▂▄__  --
        8C:A6:DF:2D:E2:E6  zjt            Infra  6     405 Mbit/s  47      ▂▄__  WPA1 WPA2
        60:3A:7C:77:22:F1  suncheng       Infra  6     405 Mbit/s  47      ▂▄__  WPA1 WPA2
        62:3A:7C:27:22:F1  --             Infra  6     405 Mbit/s  47      ▂▄__  WPA1 WPA2
        F6:6D:2F:20:E0:39  --             Infra  6     405 Mbit/s  47      ▂▄__  WPA1 WPA2
        44:F9:71:B2:FD:EB  Qch001         Infra  6     405 Mbit/s  47      ▂▄__  WPA1 WPA2
        F4:6D:2F:30:E0:39  Suzuki         Infra  6     405 Mbit/s  47      ▂▄__  WPA1 WPA2
        14:B8:37:8F:A0:A8  ChinaNet-xinu  Infra  13    130 Mbit/s  47      ▂▄__  WPA1
        02:CB:66:CE:29:C2  ABCDE          Infra  1     130 Mbit/s  44      ▂▄__  WPA2
        02:CB:66:CE:29:D0  ABCDE_Wi-Fi5   Infra  1     130 Mbit/s  40      ▂▄__  WPA2
        C8:BF:4C:77:9F:8D  Xiaomi_FB33    Infra  1     540 Mbit/s  34      ▂▄__  WPA2 WPA3
        C6:1A:3A:1E:F9:9F  suncheng       Infra  6     405 Mbit/s  34      ▂▄__  WPA1 WPA2
        9C:9D:7E:EA:FB:BB  401            Infra  9     130 Mbit/s  34      ▂▄__  WPA1 WPA2
        54:A7:03:A3:B5:C7  502            Infra  11    270 Mbit/s  34      ▂▄__  WPA1 WPA2
        E0:5D:54:BC:2E:0B  312317         Infra  11    130 Mbit/s  34      ▂▄__  WPA2
        B0:30:55:2A:56:0E  CMCC-302       Infra  1     270 Mbit/s  30      ▂___  WPA1 WPA2
        A4:39:B3:0B:16:47  Xiaomi_FB33    Infra  1     130 Mbit/s  30      ▂___  WPA2 WPA3
        84:65:69:D9:F4:6F  202            Infra  1     130 Mbit/s  30      ▂___  WPA1 WPA2
        EC:6C:B5:25:F8:AE  CMCC-dQ7D      Infra  8     130 Mbit/s  30      ▂___  WPA1 WPA2
        CE:BF:4C:77:9F:8D  --             Infra  1     540 Mbit/s  27      ▂___  --
        24:CF:24:FE:E3:37  Xiaomi_FB33    Infra  1     130 Mbit/s  27      ▂___  WPA2 WPA3
        B8:27:EB:A6:3C:F3  rpanion        Infra  1     65 Mbit/s   27      ▂___  WPA1
        E0:5D:54:56:FC:97  招珍           Infra  6     270 Mbit/s  27      ▂___  WPA1 WPA2
        82:37:07:11:25:5D  茉莉家         Infra  6     130 Mbit/s  27      ▂___  WPA2
        2E:D1:27:84:97:A5  --             Infra  11    130 Mbit/s  27      ▂___  --
        14:57:9F:09:16:60  ChinaNet-HjdH  Infra  13    130 Mbit/s  27      ▂___  WPA1 WPA2
        38:16:72:CD:EB:A8  CMCC-Js65      Infra  4     130 Mbit/s  24      ▂___  WPA1 WPA2
        68:FE:DA:9E:C2:CD  ChinaNet-v2JP  Infra  13    130 Mbit/s  24      ▂___  WPA1
        8C:1A:50:0B:2D:A9  CMCC-xwm6      Infra  6     130 Mbit/s  20      ▂___  WPA1 WPA2

4. 连接

bash 复制代码
$ nmcli --ask dev wifi connect "AutoConnect" password "password" ifname wlan1
Device 'wlan1' successfully activated with '4b0a9e71-ce2f-4a40-82b6-938ceaf876ff'.

5. 检查

拔掉网线后检查个网络状态。

bash 复制代码
 $ nmcli dev status
DEVICE         TYPE      STATE                   CONNECTION
wlan0          wifi      connected               WiFiAP
wlan1          wifi      connected               AutoConnect
zt44xhvvrc     tun       connected (externally)  zt44xhvvrc
p2p-dev-wlan0  wifi-p2p  disconnected            --
p2p-dev-wlan1  wifi-p2p  disconnected            --
eth0           ethernet  unavailable             --
lo             loopback  unmanaged               --

6. 断开

bash 复制代码
$ nmcli dev disconnect wlan1
相关推荐
fantasy_arch5 小时前
CPU性能优化-磁盘空间和解析时间
网络·性能优化
是Dream呀7 小时前
Python从0到100(七十八):神经网络--从0开始搭建全连接网络和CNN网络
网络·python·神经网络
kaixin_learn_qt_ing8 小时前
了解RPC
网络·网络协议·rpc
安全小王子8 小时前
Kali操作系统简单介绍
网络·web安全
Hacker_LaoYi10 小时前
【漏洞分析】DDOS攻防分析(四)——TCP篇
网络·tcp/ip·ddos
爱吃水果蝙蝠汤10 小时前
DATACOM-IP单播路由(BGP)-复习-实验
网络·网络协议·tcp/ip
Sun_12_210 小时前
SQL注入(SQL lnjection Base)21
网络·数据库
网络安全Jack11 小时前
网络安全概论——身份认证
网络·数据库·web安全
易我数据恢复大师11 小时前
如何彻底删除电脑数据以防止隐私泄露
网络·电脑·数据删除·擦除