Set an Access Point on Raspberry Pi

Installazione

Installare hostapd e dnsmasq:

sudo apt update
sudo apt -y install hostapd dnsmasq

Per non far gestire le interfacce a dhcpcd:

sudo nano /etc/dhcpcd.conf

Aggiungere:

denyinterfaces wlan0
denyinterfaces eth0

Editare il file /etc/network/interfaces

sudo nano /etc/network/interfaces

aggiungendo le seguenti righe:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet static
    address 192.168.5.1
    netmask 255.255.255.0
    network 192.168.5.0
    broadcast 192.168.5.255

Abilitare l'IP forwarding

Editare il file /etc/sysctl.conf

sudo nano /etc/sysctl.conf

modificando questa linea da:

#net.ipv4.ip_forward=1

a

net.ipv4.ip_forward=1

Quindi fare il reboot e controllare che l'ip forward sia attivo:

sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

o

cat /proc/sys/net/ipv4/ip_forward
1

Lanciare iptables al boot:

sudo nano /etc/rc.local

e aggiungere questa riga prima di exit

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE  

Hostapd

Configurare hostapd:

sudo nano /etc/hostapd/hostapd.conf

Con questi contenuti:

interface=wlan0
driver=nl80211
hw_mode=g
channel=6
wmm_enabled=1
ieee80211n=1
#bridge=br0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ssid=tanzoap
wpa_passphrase=123abc456

Abilita il demone hostapd

sudo systemctl unmask hostapd
sudo systemctl enable hostapd

Start:

sudo systemctl start hostapd

Per avere il log di hostapd:

sudo nano /etc/default/hostapd

e aggiungere

DAEMON_OPTS="-dd -t -f /home/pi/hostapd.log"

Dnsmasq

File:

sudo nano /etc/dnsmasq.conf

Contenuto:

interface=wlan0
listen-address=192.168.5.1
bind-interfaces
server=8.8.8.8
domain-needed
bogus-priv
dhcp-range=192.168.5.100,192.168.5.200,24h

interface=eth1
listen-address=192.168.4.1
bind-interfaces
server=8.8.8.8
domain-needed
bogus-priv
dhcp-range=192.168.4.100,192.168.4.200,24h

Restart:

sudo service dnsmasq restart

Nota per la CM3-Panel

Per usare il modulo WiFi presente sulla CM3-Panel bisogna aggiungere le seguenti righe in /etc/rc.local prima dell'istruzione exit in modo da dare alimentazione al modulo.

echo 37 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio37/direction                                   
echo 1 > /sys/class/gpio/gpio37/value

Comandi utili

Log degli errori dei demoni

systemctl status dnsmasq.service
systemctl status hostapd.service

Per disabilitare wifi e bluetooth a bordo scheda

echo "dtoverlay=pi3-disable-wifi" | sudo tee -a /boot/config.txt
echo "dtoverlay=pi3-disable-bt" | sudo tee -a /boot/config.txt
sudo systemctl disable hciuart

Links