忘了在哪裏看來的, 但最終這是唯一確定可用的設定, PC 和 RPI 3 皆可用
ubuntu 現在不用 eth0 wlan0 了, 而是用一串很詭異的名字, 要先用 ifconfig 看一下再去改
1.
/etc/dhcpcd.conf
add denyinterfaces wlan0 (above any interface line)
2.
/etc/network/interfaces
edit wlan0 setion as
-------------------
allow-hotplug wlan0
iface wlan0 inet static
address 172.24.1.1
netmask 255.255.255.0
network 172.24.1.0
broadcast 172.24.1.255
-------------------
3.
install/config hostapd
/etc/hostapd/hostapd.conf
-------------------------
#this is the name of the WiFi interface we configured above
interface=wlan0
# Use the nl80211 driver with the brcmfmac driver
driver=nl80211
# This is the name of the network
ssid=Pi3-AP
# Use the 2.4GHz band
hw_mode=g
# Use channel 6
channel=6
# Enable 802.11n
ieee80211n=1
# Enable WMM
wmm_enabled=1
# Enable 40MHz channels with 20ns guard interval
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
# Accept all MAC addresses
macaddr_acl=0
# Use WPA authentication
auth_algs=1
# Require clients to know the network name
ignore_broadcast_ssid=0
# Use WPA2
wpa=2
# Use a pre-shared key
wpa_key_mgmt=WPA-PSK
# The network passphrase
wpa_passphrase=raspberry
# Use AES, instead of TKIP
rsn_pairwise=CCMP
-------------------------
/etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"
4.
install/config dnsmasq.conf
/etc/dnsmasq.conf ( orig : /etc/dnsmasq.conf.orig)
-------------------------
interface=wlan0 # Use interface wlan0
listen-address=172.24.1.1 # Explicitly specify the address to listen on
bind-interfaces # Bind to the interface to make sure we aren't sending things elsewhere
server=8.8.8.8 # Forward DNS requests to Google DNS
domain-needed # Don't forward short names
bogus-priv # Never forward addresses in the non-routed address spaces.
dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time
-------------------------
5. IPV4 forwarding
/etc/sysctl.conf
net.ipv4.ip_forward=1 (# mark/unmark)
command line :
-------------------------
sudo iptables -t nat -A POSTROUTING -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 sh -c "iptables-save > /etc/iptables.ipv4.nat"
------------------------
/etc/rc.local
iptables-restore < /etc/iptables.ipv4.nat
6.
sudo service hostapd start
sudo service dnsmasq start