首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

Raspbian命令行连接WiFi网络

  • 25-02-20 11:41
  • 4427
  • 7211
blog.csdn.net

Raspbian命令行连接WiFi网络

  • 1. 源由
  • 2. 环境
  • 3. 基本操作
    • 3.1 信号扫描
    • 3.2 网络连接
    • 3.3 断开连接
  • 4. 多网卡
    • 4.1 信号扫描
    • 4.2 网络连接
    • 4.3 断开连接
  • 5 状态检查
  • 6. 配置网卡
    • 6.1 配置密码
    • 6.2 连接WiFi
    • 6.3 获取IP
    • 6.4 查看IP
  • 7. 自启动
  • 8. lshw查看硬件
  • 9. ethtool查看硬件

1. 源由

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

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

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

2. 环境

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

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

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

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

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

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

$ 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

3. 基本操作

3.1 信号扫描

 $ 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

3.2 网络连接

$ nmcli --ask dev wifi connect "AutoConnect" password "password" ifname wlan1
Device 'wlan1' successfully activated with '4b0a9e71-ce2f-4a40-82b6-938ceaf876ff'.
  • 1
  • 2

3.3 断开连接

$ nmcli dev disconnect wlan1
  • 1

4. 多网卡

4.1 信号扫描

$ nmcli device wifi list ifname wlan0
$ nmcli device wifi list ifname wlan1
  • 1
  • 2

4.2 网络连接

$ nmcli device wifi connect "" password "" ifname wlan0
$ nmcli device wifi connect "" password "" ifname wlan1
  • 1
  • 2

4.3 断开连接

$ nmcli dev disconnect wlan0
$ nmcli dev disconnect wlan1
  • 1
  • 2

5 状态检查

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

 $ 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               --
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

6. 配置网卡

6.1 配置密码

$ sudo nano /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
$ sudo cat /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
network={
    ssid="SSID1"
    psk="password1"
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
$ sudo nano /etc/wpa_supplicant/wpa_supplicant-wlan1.conf
$ sudo cat /etc/wpa_supplicant/wpa_supplicant-wlan1.conf
network={
    ssid="SSID2"
    psk="password2"
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

6.2 连接WiFi

$ sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
$ sudo wpa_supplicant -B -i wlan1 -c /etc/wpa_supplicant/wpa_supplicant-wlan1.conf
  • 1
  • 2

6.3 获取IP

$ sudo dhclient wlan0
$ sudo dhclient wlan1
  • 1
  • 2

6.4 查看IP

$ ifconfig
  • 1

7. 自启动

$ sudo nano /etc/rc.local
$ tail -n 3 /etc/rc.local
sudo wpa_supplicant -B -i wlan1 -c /etc/wpa_supplicant/wpa_supplicant-wlan1.conf
sudo dhclient wlan1
exit 0
  • 1
  • 2
  • 3
  • 4
  • 5

8. lshw查看硬件

$ sudo apt install lshw
  • 1
$ sudo lshw -C network
  *-usb
       description: Ethernet interface
       vendor: Microchip Technology, Inc. (formerly SMSC)
       physical id: 1
       bus info: usb@1:1.1.1
       logical name: eth0
       version: 3.00
       serial: b8:27:eb:f3:69:a6
       capacity: 1Gbit/s
       capabilities: usb-2.10 ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=lan78xx driverversion=6.6.47+rpt-rpi-v8 link=no maxpower=2mA multicast=yes port=twisted pair speed=480Mbit/s
  *-interface:0
       description: Wireless interface
       product: 43430
       vendor: Broadcom
       physical id: 1
       bus info: mmc@1:0001:1
       logical name: mmc1:0001:1
       logical name: wlan0
       serial: b8:27:eb:a6:3c:f3
       capabilities: ethernet physical wireless
       configuration: broadcast=yes driver=brcmfmac driverversion=7.45.16.144 firmware=01-b677b91b multicast=yes wireless=IEEE 802.11
  *-network:0 DISABLED
       description: Ethernet interface
       physical id: 8
       logical name: usb0
       serial: 8a:64:47:92:a3:61
       capabilities: ethernet physical
       configuration: broadcast=yes driver=g_ether driverversion=29-May-2008 firmware=3f980000.usb link=no multicast=yes
  *-network:1
       description: Wireless interface
       physical id: 9
       bus info: usb@1:1.3
       logical name: wlan1
       serial: 14:cf:92:05:3c:d3
       capabilities: ethernet physical wireless
       configuration: broadcast=yes driver=rtl8192cu driverversion=6.6.47+rpt-rpi-v8 firmware=N/A ip=192.168.1.15 link=yes multicast=yes wireless=IEEE 802.11
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

9. ethtool查看硬件

$ sudo apt install ethtool
  • 1
$ sudo ethtool -i wlan0
driver: brcmfmac
version: 7.45.16.144
firmware-version: 01-b677b91b
expansion-rom-version:
bus-info: mmc1:0001:1
supports-statistics: no
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no
$ sudo ethtool -i wlan1
driver: rtl8192cu
version: 6.6.47+rpt-rpi-v8
firmware-version: N/A
expansion-rom-version:
bus-info: 1-1.3:1.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
注:本文转载自blog.csdn.net的lida2003的文章"https://blog.csdn.net/lida2003/article/details/139982311"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top