安裝軟體
首先設定軟體源:
vim /etc/apt/sources.list
檢視軟體源後面的版本,如果是wheezy,需要換成jessie
wheezy是基于deb 7的版本
而現在是基于jessie
也可以直接拿這個:
deb http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib
安裝:
apt install -y dnsmasq hostapd dhcpcd5
設定并開啟dhcp服務
1. 配置網卡
vim /etc/network/interfaces
将wlan0網卡的配置改成這樣,如果之前沒有wlan0的配置,則直接粘貼即可:
如果不配置這個,則dhcp配置無效
allow-hotplug wlan0
iface wlan0 inet manual
2. dhcp配置
vim /etc/dhcpcd.conf
添加這個:
interface wlan0
static ip_address=10.10.10.1/24
static routers=10.10.10.1
static domain_name_servers=10.10.10.1 8.8.8.8
3. 重新開機dhcp服務
service dhcpcd restart
建議這之後重新開機下樹莓派,不然dhcp不生效
熱點配置
1. 建立配置檔案
vim /etc/hostapd/hostapd.conf
填入如下内容:
interface=wlan0
driver=nl80211
ssid=rpi
hw_mode=g
channel=6
wmm_enabled=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
2. 測試是否有效
/usr/sbin/hostapd /etc/hostapd/hostapd.conf
此時可搜尋到熱點
3. 設定自動啟動
vim /etc/default/hostapd
改一行:
DAEMON_CONF="/etc/hostapd/hostapd.conf"