Skip to content

Instantly share code, notes, and snippets.

@MatteoRagni
Last active September 24, 2015 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatteoRagni/326553b197d9926fc5a7 to your computer and use it in GitHub Desktop.
Save MatteoRagni/326553b197d9926fc5a7 to your computer and use it in GitHub Desktop.
Impostare un access point su Raspberry Pi 2 con scheda wifi RT5370

Raspberry Pi Access point

Aggiornamento

Assolutamento necessario che il dispositivo sia aggiornato, sia come software che come firmware. Di seguito la lista di comandi necessario

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo rpi-update

Attenzione all'update tramite rpi-update. Un update del firmware non concluso puo' brikkare la scheda!

Completare l'operazione con un reboot:

sudo reboot

Installare il software

Installare il software necessario:

sudo apt-get install firmware-ralink # particolare per questa scheda wifi
sudo apt-get install hostapd dnsmasq

Configurare il software

hostapd

Configurare i parametri di access point. Attenzione: questa configurazione contiene una voce, driver, sufficientemente generale, driver, che potrebbe cambiare in funzione del chipset della scheda di rete.

Creare un nuovo file di configurazione:

sudo nano /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=INSERT_HERE_SSID_NAME
channel=1

macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0

wpa=2
wpa_passphrase=INSERT_HERE_PASSWORD
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

ieee80211n=1
hw_mode=g

Attenzione a non inserire linee vuote a fine file.

Inserire la posizione del file precedente nel file di configurazione di default /etc/default/hostapd

sudo nano /etc/default/hostapd
[... omissis ...]
DAEMON_CONF="/etc/hostapd/hostapd.conf
[... omissis ...]

Networking

Definire un indirizzo IP statico per la scheda di rete wlan0, che prendiamo come unica interfaccia wifi connessa alla Raspberry:

sudo nano /etc/network/interfaces
[... omissis ...]
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
  address 10.0.0.1
  netmask 255.255.255.0

up iptables-restore < /etc/iptables.ipv4.nat

Affinche' vanga assegnato l'ip statico, bisogna evitare che la interfaccia rientri in alcune politiche di re-up del sistema. Modificare nel file /etc/default/ifplugd i parametri INTERFACES e HOTPLUG_INTERFACES

sudo nano /etc/default/ifplugd
#INTERFACES="all"
INTERFACES="eth0"
#HOTPLUG_INTERFACES="all"
HOTPLUG_INTERFACES="eth0"

IpTables

Andiamo a creare il file NAT che verra' caricato ogni volta che la interfaccia wlan0 sara' up: /etc/iptalbes.ipv4.nat

sudo nano /etc/iptables.ipv4.nat
# Generated by iptables-save v1.4.14 on Mon Sep 21 18:48:37 2015
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o eth0 -j MASQUERADE
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Mon Sep 21 18:48:37 2015
# Generated by iptables-save v1.4.14 on Mon Sep 21 18:48:37 2015
*filter
:INPUT ACCEPT [1:78]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -j ACCEPT
-A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -j ACCEPT
COMMIT
# Completed on Mon Sep 21 18:48:37 2015

dnsmask

Configuriamo il dnsmasq affinche' fornisca gli indirizzi IP richiesti:

sudo mv /etc/dnsmasq.conf /etc/dnsconf.conf.bkp
sudo nano /etc/dnsmasq.conf
interface=wlan0
dhcp-range=10.0.0.2,10.0.0.100,255.255.255.0,12h

wpa_supplicant

Vuoi che non provi a rompere? Disabilitiamolo all'origine aggiungendo agli script di pre-up e up qualcosa per evitarne la esecuzione:

sudo nano /etc/network/if-pre-up.d/wpasupplicant
#!/bin/sh
exit 0

[... omissis ...]

update-rc

Se non e' stato fatto automaticamente, aggiungere hostapd e dnsmasq alla lista dei servizi di default.

Device RTL8188CUS Realtek

Il binario hostapd non supporta questo dispositivo. Per fortuna ne esiste una versione patchata pre compilata messa a disposizione da Adafruit.

cd /tmp
wget http://adafruit-download.s3.amazonaws.com/adafruit_hostapd_14128.zip
unzip adafruit_hostapd_14128.zip
sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG
sudo mv hostapd /usr/sbin
sudo chmod 755 /usr/sbin/hostapd

E' necessario inserire il driver giusto in /etc/hostapd/hostapd.conf:

sudo nano /etc/hostapd/hostapd.conf
[... omissis ...]
driver=rtl871xdrv
[... omissis ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment