現在許多較新的raspberry pi支援wifi來當作網路的連接介面,讓raspberry pi能夠在找不到網孔的時候,使用wifi來當作連線,另一方面,如果可以用raspberry pi上的wifi晶片來當一個wifi ap,也是一個很好的利用方式
dnsmasq
以及hostapd
sudo apt install dnsmasq hostapd
sudo systemctl stop dnsmasq
sudo systemctl stop hostapd
/etc/dhcpcd.conf
,server的IP設定為192.168.4.1
子網路遮罩設定為/24
(也就是255.255.255.0
)interface wlan0
static ip_address=192.168.4.1/24
nohook wpa_supplicant
sudo service dhcpcd restart
/etc/dnsmasq.conf
備份起來,然後編輯一個新的設定檔sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
/etc/dnsmasq.conf
,以下設定檔為範例,保留192.168.4.2
以及192.168.4.20
,並且子網路遮罩為255.255.255.0
interface=wlan0 # Use the require wireless interface - usually wlan0
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
sudo systemctl reload dnsmasq
/etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
ssid=NameOfNetwork
hw_mode=n
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=AardvarkBadgerHedgehog
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
hostapd
設定檔放在哪裡,編輯/etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"
hostapd
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
/etc/sysctl.conf
並把下面那一行取消註解net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
iptables-restore < /etc/iptables.ipv4.nat
這樣就完成將raspberry pi變成wifi ap囉!當然這不是bridge模式,而是有NAT的功能