树莓派连 wifi

2017-09-04 23:03:11

假设当前路由器为 10.0.124.1

配置正确的 nameserver

# /etc/resolv.conf
nameserver 114.114.114.114
nameserver 114.114.115.115

编辑 wifi 密码

# /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

ap_scan=1

network={
    ssid="xxxx"
    psk="xxxx"
    id_str="home"
    priority=4
}

network={
    ssid="xxxx"
    psk="xxxx!"
    id_str="work"
    priority=5
}

配置正确的 gateway

# /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
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

## 动态 IP
iface home inet dhcp
iface work inet dhcp


## 静态 IP
## home
# iface home inet static
# address 192.168.31.199
# gateway 192.168.31.1
# netmask 255.255.255.0
#
## work
# iface work inet static
# address 10.0.124.99
# gateway 10.0.124.1
# netmask 255.255.255.0

##重启网络服务使用的命令

sudo /etc/init.d/networking restart

OK!

- EOF -