Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

树莓派启动时自动连接wifi #16

Open
qiwihui opened this issue Sep 10, 2018 · 0 comments
Open

树莓派启动时自动连接wifi #16

qiwihui opened this issue Sep 10, 2018 · 0 comments
Labels
技术 技术相关
Milestone

Comments

@qiwihui
Copy link
Owner

qiwihui commented Sep 10, 2018

这篇文章的目的是为了配置树莓派,使其在启动时自动获取静态IP.

启动并连接树莓派

1. 启动树莓派并找到其IP地址

把树莓派用网线连接到路由器上,插上SD卡,打开树莓派电源,等大约90秒.
在Mac上打开命令行终端,输入arp -a命令,可以看到树莓派的ip地址为 192.168.199.199.
当然也可以从路由器后台看到这个IP地址.

$ arp -a
? (169.254.99.51) at (incomplete) on en0 [ethernet]
hiwifi.lan (192.168.199.1) at d4:ee:7:20:18:6e on en0 ifscope [ethernet]
raspberrypi.lan (192.168.199.199) at f0:f6:1c:af:7a:28 on en0 ifscope [ethernet]

2. 使用SSH连接树莓派

输入"ssh pi@192.168.199.199", 根据要求输入密码,默认为raspberry.

$ ssh pi@192.168.199.199
pi@192.168.199.199s password: 
Linux qiwihuisrpi 3.18.7+ #755 PREEMPT Thu Feb 12 17:14:31 GMT 2015 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Apr 17 14:45:28 2015 from 192.168.199.186

配置网络连接

1. 设置网络接口文件/etc/network/interfaces

编辑这个文件:

$ sudo nano /etc/network/interfaces

添加如下内容:

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
# iface wlan0 inet dhcp # 如果想自动获取ip
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

# 设置静态ip
iface wlan0 inet static
address 192.168.199.199
netmask 255.255.255.0
gateway 192.168.199.1

iface default inet dhcp

2. 设置wpa_supplicant.conf配置文件

编辑文件wpa_supplicant.conf设置连接的网络热点.

$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

为:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="YOUR_NETWORK_NAME"
    psk="YOU_NETWORK_PASSWORD"
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP
    auth_alg=OPEN
}

其中:

  • proto 可以是 RSN (WPA2) 或者 WPA (WPA1).
  • key_mgmt 可以是 WPA-PSK (大部分) 或者 WPA-EAP (企业网络)
  • pairwise 可以是 CCMP (WPA2) 或者 TKIP (WPA1)
  • auth_alg 常为 OPEN, 其他可选为 LEAPSHARED

重启树莓派,之后就会自动连上wifi了.

@qiwihui qiwihui added the 技术 技术相关 label Sep 10, 2018
@qiwihui qiwihui added this to the 技术 milestone Jan 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
技术 技术相关
Projects
None yet
Development

No branches or pull requests

1 participant