參考網頁:
dhcpd – ArchWiki
安裝 hostapd
# pacman -S hostapd
安裝 DHCP Server
# pacman -S dhcp
備份原設定檔
# mv /etc/dhcpd.conf /etc/dhcpd.conf.$(date +%F)
建立 DHCP Server 設定檔
# vim /etc/dhcpd.conf
ddns-update-style none;
option domain-name “example.org”;
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 172.16.0.0 netmask 255.255.255.0 {
range 172.16.0.1 172.16.0.10;
option domain-name-servers 168.95.1.1;
option domain-name-servers 8.8.8.8;
option routers 172.16.0.254;
}[@more@]
# vim /etc/systemd/system/dhcpd4@.service
[Unit]
Description=IPv4 DHCP server on %I
Wants=network.target
After=network.target
[Service]
Type=forking
PIDFile=/run/dhcpd4.pid
ExecStart=/usr/bin/dhcpd -4 -q -pf /run/dhcpd4.pid %I
KillSignal=SIGINT
[Install]
WantedBy=multi-user.target
修改 wlan0 網路卡設定
# cat /etc/netctl/wlan0
Description=’A simple WPA encrypted wireless connection using a static IP’
Interface=wlan0
Connection=ethernet
AutoWired=yes
IP=static
Address=’172.16.0.254/24′
DNS=(‘168.95.1.1’ ‘140.111.66.1’ ‘8.8.8.8’)
# Uncomment this if your ssid is hidden
#Hidden=yes
重新啟動 wlan0
# netctl restart wlan0
# ifconfig wlan0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.0.254 netmask 255.255.255.0 broadcast 172.16.0.255
inet6 fe80::9a3b:16ff:fe1e:67d8 prefixlen 64 scopeid 0x20<link>
ether 98:3b:16:1e:67:d8 txqueuelen 1000 (Ethernet)
RX packets 15 bytes 1914 (1.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 69 bytes 7236 (7.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
啟動 DHCP Server
# systemctl start dhcpd4@wlan0.service
設定開機時啟動 DHCP Server
# systemctl enable dhcpd4@wlan0.service
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd4@wlan0.service to /etc/systemd/system/dhcpd4@.service.
設定防火牆
# vim /etc/firewall.wifiap
#!/bin/bash
IPTABLES=/sbin/iptables
$IPTABLES -F
$IPTABLES -F -t nat
$IPTABLES -X
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
modprobe ip_conntrack
modprobe iptable_nat
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
echo 1 > /proc/sys/net/ipv4/ip_forward
$IPTABLES -t nat -A POSTROUTING -j MASQUERADE
執行防火牆規則
# sh /etc/firewall.wifiap
在 /etc/rc.local 檔案最後面加入執行防火牆規則的設定
# sed -i ‘$a # NAT 防火牆nsh /etc/firewall.wifiap’ /etc/rc.local
設定 hostapd
# cat /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
ssid=CubieTruck
channel=11
hw_mode=g
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_psk=ee07bee15c9c33bf7bcc53d84aac17e2b83f82476f96e32efcd03d716d99a4d2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
執行 hostapd
# systemctl start hostapd
查詢執行狀態
# systemctl status hostapd
● hostapd.service – Hostapd IEEE 802.11 AP, IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator
Loaded: loaded (/usr/lib/systemd/system/hostapd.service; enabled)
Active: active (running) since Tue 2014-10-14 13:23:38 CST; 1s ago
Process: 353 ExecStart=/usr/bin/hostapd /etc/hostapd/hostapd.conf -P /run/hostapd.pid -B (code=exited, status=0/SUCCESS)
Main PID: 354 (hostapd)
CGroup: /system.slice/hostapd.service
└─354 /usr/bin/hostapd /etc/hostapd/hostapd.conf -P /run/hostapd.pid -B
直接使用命令列執行
# /usr/bin/hostapd /etc/hostapd/hostapd.conf -P /run/hostapd.pid -B
Configuration file: /etc/hostapd/hostapd.conf
Using interface wlan0 with hwaddr 98:3b:16:1e:67:d8 and ssid “CubieTruck”
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
設定開機時執行
# systemctl enable hostapd