2020-03-31-【迁移】树莓派开启蓝牙个人区域网.md 2.2 KB


title: 【迁移】树莓派开启蓝牙个人区域网 urlname: ssh-by-bluetooth-in-raspberrypi index_img: https://api.limour.top/randomImg?d=2024-10-27 05:47:53 date: 2020-03-31 13:47:53

tags: ['raspberrypi', 'ssh']

开启 SSH 连接

  • boot 目录下新建 ssh 的空文件
  • boot 目录下新建 wpa_supplicant.conf

    country=CN
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
     
    network={
    ssid="Limour123"
    psk="123456"
    key_mgmt=WPA-PSK
    priority=5
    }
     
    network={
    ssid="Redmi_719_2.4G"
    psk="123456"
    key_mgmt=WPA-PSK
    priority=1
    }
    

蓝牙局域网设置

sudo apt install bridge-utils bluez python-dbus python-gobject bluez-tools
sudo ufw disable # 关闭防火墙
sudo service bluetooth start # 开启蓝牙服务并设置为开机自启
sudo update-rc.d bluetooth enable

sudo nano /etc/systemd/network/pan0.netdev
# 输入:
[NetDev]
Name=pan0
Kind=bridge

sudo nano /etc/systemd/network/pan0.network
# 输入:
[Match]
Name=pan0

[Network]
Address=172.20.1.1/24
DHCPServer=yes

sudo nano /etc/systemd/system/bt-agent.service
# 输入:
[Unit]
Description=Bluetooth Auth Agent

[Service]
ExecStart=/usr/bin/bt-agent -c NoInputNoOutput
Type=simple

[Install]
WantedBy=multi-user.target

sudo nano /etc/systemd/system/bt-network.service
# 输入:
[Unit]
Description=Bluetooth NEP PAN
After=pan0.network

[Service]
ExecStart=/usr/bin/bt-network -s nap pan0
Type=simple

[Install]
WantedBy=multi-user.target

sudo systemctl enable systemd-networkd
sudo systemctl enable bt-agent
sudo systemctl enable bt-network
sudo systemctl start systemd-networkd
sudo systemctl start bt-agent
sudo systemctl start bt-network

连接蓝牙局域网

bluetoothctl # 启动蓝牙命令行工具
agent on # 开启代理
scan on # 扫描设备
pair 9C:19:C2:4D:88:DC # 树莓派与蓝牙设备进行配对
connect 9C:19:C2:4D:88:DC  # 连接设备
  • win11 上右键蓝牙加入个人区域网
  • 树莓派上 ifconfig 可以看到多了一个 bnep0 的网络
  • win11ipconfig.exe 可以看到多了一个以太网适配器 蓝牙网络连接
  • 其默认网关为 172.20.1.1
  • 此时 win11ssh 连接 172.20.1.1 即可连接到树莓派