sudo bash
#切换root
sudo apt install -y hostapd isc-dhcp-server ifupdown
# 配置 hostapd
sudo nano /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
ssid=hostspot-name
macaddr_acl=0
auth_algs=1
#auth_algs=3
ignore_broadcast_ssid=0
hw_mode=bgn
channel=6
wpa=2
wpa_passphrase=password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
#wpa_pairwise=TKIP
#rsn_pairwise=CCMP
# 修改 hostapd 默认配置文件路径
sudo nano /etc/default/hostapd
DAEMON_CONF=/etc/hostapd/hostapd.conf
# 重启 hostapd
sudo service hostapd restart
sudo service hostapd status
# dhcp 配置
sudo nano /etc/dhcp/dhcpd.conf
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
authoritative;
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.10 10.0.0.200;
option broadcast-address 10.0.0.255;
option routers 10.0.0.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 223.5.5.5, 8.8.4.4;
}
# 设置 dhcp 网口
# 不进行操作会出现错误:Not configured to listen on any interfaces!
sudo nano /etc/default/isc-dhcp-server
INTERFACESv4="wlan0"
INTERFACESv6="wlan0"
# 设置 wlan0 地址
# 不进行操作会出现错误:Not configured to listen on any interfaces!
sudo ip addr add 10.0.0.1/24 dev wlan0
# 设置开机自动设置
mkdir /etc/network/interfaces.d/
echo -e "# armbian NAT hostapd\nallow-hotplug wlan0\niface wlan0 inet static\n \taddress 10.0.0.1\n\tnetmask 255.255.255.0\n\tnetwork 10.0.0.0\n\tbroadcast 10.0.0.255" > /etc/network/interfaces.d/armbian.ap.nat
# 开启转发
sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -s 10.0.0.1/24 -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
#设置开机启动自动设置
sudo iptables-save > /etc/iptables.ipv4.nat
cat <<-EOF > /etc/systemd/system/armbian-restore-iptables.service
[Unit]
Description="Restore IP tables"
[Timer]
OnBootSec=20Sec
[Service]
Type=oneshot
ExecStart=/sbin/iptables-restore /etc/iptables.ipv4.nat
[Install]
WantedBy=sysinit.target
EOF
systemctl enable armbian-restore-iptables.service
# 启动 dhcp 服务
systemctl enable isc-dhcp-server
systemctl start isc-dhcp-server
参考:https://gitee.com/xiayang0521/rk3399