0,安装软件
apt-get install hostapd
apt-get install isc-dhcp-server
1,编辑 /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# auto lo
# iface lo inet loopback
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
#有线接口静态配置,也可以使用dhcp方式,请参考手册,dhcp的话下面到默认路由都可以不要
#iface eth0 inet static
#address 10.0.0.204
#geteway 10.0.0.1
#netmask 255.255.255.0
#域名服务器,看需求配置,就配只114.114.114.114也行
#dns-nameservers 8.8.8.8 10.0.0.1
#默认路由
#up ip route add default via 10.0.0.1
#热插拔自动启动模式,即如果此接口存在的话系统会自动ifup此接口
allow-hotplug wlan1
#无线接口静态配置,此处使用静态IP,因为要配合dhcp server配置,见附录
iface wlan1 inet static
address 192.168.0.1
netmask 255.255.255.0
#启动接口前杀死hostapd进程清空iptables
up if pgrep hostapd ; then pkill hostapd ; fi
up iptables -t nat -F
#接口启动后执行脚本 #启动hostapd服务,制定配置文件,配置文件见附录
post-up hostapd /etc/hostapd/hostapd.conf -B
#重启hdcp服务,
post-up service isc-dhcp-server restart
#iptables配置NAT
post-up iptables -A FORWARD -i wlan1 -o eth0 -s 192.168.0.1/24 -m state --state NEW -j ACCEPT
post-up iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
post-up iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
post-up echo "1" >/proc/sys/net/ipv4/ip_forward
#ifdown时自动执行脚本
down if pgrep hostapd ; then pkill hostapd ; fi
down iptables -t nat -F
2,编辑 /etc/hostapd/hostapd.conf
interface=wlan1
driver=nl80211
ssid=AAAA
channel=9
hw_mode=g
macaddr_acl=0
ignore_broadcast_ssid=0
auth_algs=1
wpa=3
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
3,编辑 /etc/dhcp/dhcpd.conf
subnet 192.168.0.0 netmask 255.255.255.0
{
range 192.168.0.2 192.168.0.10;
option domain-name-servers 8.8.8.8; #这个DNS根据实际需要设置
option routers 192.168.0.1;
}
}