Ubuntu configures WIFI as AP mode

0, install the software
apt-get install hostapd

apt-get install isc-dhcp-server

1. Edit /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
#Static configuration of wired interface, dhcp method can also be used, please refer to the manual, if dhcp is used, the default route can be omitted below
#iface eth0 inet static
#address 10.0.0.204
#geteway 10.0.0.1
#netmask 255.255.255.0
#Domain name server, depending on the configuration of the needs, you can only match 114.114.114.114
#dns-nameservers 8.8.8.8 10.0.0.1
#default route
#up ip route add default via 10.0.0.1
#Hot-plug auto-start mode, that is, if this interface exists, the system will automatically ifup this interface
allow-hotplug wlan1
#Wireless interface static configuration, use static IP here, because it needs to be configured with dhcp server, see appendix
iface wlan1 inet static
address 192.168.0.1
netmask 255.255.255.0
#Kill the hostapd process to clear iptables before starting the interface
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;
}
  1. }


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324661154&siteId=291194637