树莓派上有有线网口(eth0)和无线WIFI(wlan0),因此可以配置成为一个WIFI热点,这里笔记下最简单配置流程。
CONTENTS
软件安装与使能
root@raspberrypi:~# apt-get install hostapd dnsmasq root@raspberrypi:~# systemctl unmask hostapd.service root@raspberrypi:~# systemctl enable hostapd.service
配置dhcpcd.conf
修改/etc/dhcpcd.conf,配置wlan0为静态IP,作为热点使用。
interface wlan0 static ip_address=192.168.100.1/24
修改后如下图:
配置hostapd参数
修改/etc/default/hostapd中的DAEMON_CONF参数,将hostapd的conf指向特定的配置文件,这里修改如下:
DAEMON_CONF=”/etc/hostapd/hostapd.conf”
这里笔记2种典型的hostapd配置。
WPA2加密模式
cat /etc/hostapd/hostapd.conf ctrl_interface=/var/run/hostapd ctrl_interface_group=0 interface=wlan0 driver=nl80211 hw_mode=g channel=6 macaddr_acl=0 ieee80211n=1 ssid=hello_raspi4 wpa_passphrase=12345678 auth_algs=1 wpa=2 wpa_key_mgmt=WPA-PSK wpa_pairwise=CCMP rsn_pairwise=CCMP
Open模式
cat /etc/hostapd/hostapd.conf ctrl_interface=/var/run/hostapd ctrl_interface_group=0 interface=wlan0 driver=nl80211 hw_mode=g channel=6 macaddr_acl=0 ieee80211n=1 ssid=hello_raspi4_free
配置dnsmasq参数
新建dnsmasq配置文件/etc/dnsmasq.conf,内容如下,使用dnsmasq作为dhcp服务器和dns中转服务器。
root@raspberrypi:~# cat /etc/dnsmasq.conf interface=wlan0 dhcp-range=192.168.100.100,192.168.100.254,12h
打开热点
root@raspberrypi:~# sysctl -w net.ipv4.ip_forward=1 root@raspberrypi:~# service hostapd reload root@raspberrypi:~# service hostapd restart root@raspberrypi:~# service dnsmasq restart
关闭热点
root@raspberrypi:~# service hostapd stop root@raspberrypi:~# service dnsmasq stop
打开外网访问权限
允许设备通过WIFI热点访问外网
root@raspberrypi:~# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
关闭外网访问权限
root@raspberrypi:~# iptables -t nat -F
查看已经连接热点的设备信息
root@raspberrypi:~# arp -i wlan0 Address HWtype HWaddress Flags Mask Iface Honor ether 1d:15:1f:b5:bf:1c C wlan0 root@raspberrypi:~# cat /var/lib/misc/dnsmasq.leases 1574708080 1d:15:1f:b5:bf:1c 192.168.100.179 Honor
发表评论