apt-get -y install hostapd dnsmasq echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf sysctl -p /etc/sysctl.conf # # Hostapd service is masked by default. This is the working way # to unmask it and add to autostart: # echo "DAEMON_CONF=\"/etc/hostapd/hostapd.conf\"" >> /etc/default/hostapd rm -f /etc/systemd/system/hostapd.service ln -s /usr/lib/systemd/system/hostapd.service /etc/systemd/system/hostapd.service systemctl daemon-reload cat >> /etc/hostapd/hostapd.conf << EOF interface=wlan0 driver=nl80211 country_code=UA ssid=reise # g means 2.4Ghz frequency: hw_mode=g # Enable 802.11n: ieee80211n=1 wmm_enabled=1 channel=11 wpa=2 wpa_passphrase=nagorshkesidelkorol wpa_key_mgmt=WPA-PSK wpa_pairwise=CCMP rsn_pairwise=CCMP auth_algs=1 macaddr_acl=0 EOF # # WiFi interface cannot be assigned an IP address by netplan, # unless Access Point is configured. Here is how to autoassign IP: # cat >> /etc/hostapd/wificonfig.sh << EOF #!/bin/bash ip addr add 192.168.20.29 dev wlan0 ip route add 192.168.20.0/24 dev wlan0 scope link src 192.168.20.29 metric 100 EOF chmod 755 /etc/hostapd/wificonfig.sh (crontab -l ; echo "@reboot sleep 20; /etc/hostapd/wificonfig.sh") | crontab - cat >> /etc/dnsmasq.conf << EOF strict-order interface=wlan0 except-interface=lo listen-address=192.168.20.29 bind-dynamic dhcp-range=192.168.20.30,192.168.20.50,255.255.255.0,2h dhcp-leasefile=/var/lib/misc/dnsmasq-wlan0.leases #Let DHCP client recieve another DNS server, not local host: #dhcp-option=option:dns-server,10.1.2.5,8.8.8.8 log-dhcp # Create IP reserviation for known MAC: dhcp-host=54:87:a2:19:95:f0,192.168.20.59 EOF systemctl enable hostapd systemctl start hostapd systemctl enable dnsmasq systemctl stop dnsmasq systemctl start dnsmasq iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE service netfilter-persistent save