Configuration d’un point d’accès wifi sur Raspbian

Installation de paquets supplémentaires

Installation des paquets nécessaires :

apt-get install usbutils
apt-get install hostapd firmware-realtek bridge-utils iw
apt-get install isc-dhcp-server unbound dnsutils firehol fail2ban

Quelques détails sur les paquets :

  • isc-dhcp-server : serveur DHCPD simple et robuste
  • unbound : un validateur DNS qui évite d’utiliser les DNS menteurs fournis par mon fournisseur d’accès
  • firehol : un script de configuration d’un firewall basé sur iptables
  • fail2ban : il analyse les log pour détecter des tentatives d’intrusions et modifier les règles de filtrage automatiquement

Configuration de hostapd

Ajout de la configuration de l’inteface wlan0 dans le fichier /etc/network/interfaces :

auto wlan0
iface wlan0 inet static
  hostapd /etc/hostapd/hostapd.conf
  address 192.168.2.1
  netmask 255.255.255.0
  wireless-power off

Le fichier /etc/hostapd/hostapd.conf :

# Basic configuration

interface=wlan0
ssid=MON RESEAU WIFI
channel=1

# WPA and WPA2 configuration
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=MON_MOT_DE_PASSE
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

# Hardware configuration
driver=rtl871xdrv
ieee80211n=1
hw_mode=g
device_name=RTL8192CU
manufacturer=Realtek

Ajout de la ligne suivante dans /etc/default/hostapd :

DAEMON_CONF="/etc/hostapd/hostapd.conf"

La version de hostapd fournie sur raspbian n’est pas compatible avec le plug usb wifi que je possède :

# lsusb | grep Edimax
Bus 002 Device 005: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]

Message d’erreur affiché lors du lancement :

# hostapd /etc/hostapd/hostapd.conf
Configuration file: /etc/hostapd/hostapd.conf
Line 21: invalid/unknown driver 'rtl871xdrv'
1 errors found in configuration file '/etc/hostapd/hostapd.conf'
Failed to set up interface with /etc/hostapd/hostapd.conf
Failed to initialize interface

Il faut donc désinstaller hostapd et installer notre version :

apt-get remove hostapd

Vous pouvez récupérer une version de remplacement déjà compilée ici. Pour l’installer :

wget http://xael.org/2015/hostapd_2.3-1+deb8u1-1_armhf.deb
dpkg -i hostapd_2.3-1+deb8u1-1_armhf.deb

Ou sinon il faut compiler et installer notre version :

apt-get install make gcc checkinstall
cd /opt
wget https://github.com/jenssegers/RTL8188-hostapd/archive/v2.0.tar.gz
tar xvf v2.0.tar.gz
cd RTL8188-hostapd-2.0/hostapd
make

Pour l’installation, nous allons réaliser un paquet debian grâce à checkinstall :

checkinstall make install

Pour éviter qu’à la prochaine mise à jour notre paquet soit remplacé, il faut le geler :

echo "hostapd hold" | dpkg --set-selections

Configuration du DHCP

Éditer le fichier /etc/dhcp/dhcpd.conf pour ajouter notre zone :

ddns-update-style none;
# option definitions common to all supported networks...
option domain-name "xael.local";
option domain-name-servers 192.168.2.1;

default-lease-time 600;
max-lease-time 7200;

subnet 192.168.2.0 netmask 255.255.255.0 {
  range 192.168.2.10 192.168.2.100;
  option routers 192.168.2.1;
}

Configuration de unbound

Je veux juste que unbound agisse en tant que résolveur DNS, accessible depuis mes réseaux. La configuration est simple, il suffit d’éditer le fichier /etc/unbound/unbound.conf.d/simple_dns.conf

## Simple recursive caching DNS
server:
    interface: 0.0.0.0
        access-control: 192.168.2.0/24 allow 
        access-control: 192.168.0.0/24 allow
        verbosity: 2

forward-zone:
      name: "."
      forward-addr: 8.8.8.8        # Google Public DNS
      forward-addr: 74.82.42.42    # Hurricane Electric
      forward-addr: 4.2.2.4        # Level3 Verizon

Configuration de firehol

Édition du fichier /etc/firehol/firehol.conf :

version 5

FIREHOL_LOG_PREFIX="firehol: "
FIREHOL_LOG_LEVEL="crit"

interface eth0 laneth
    policy reject
    server http accept
    server https accept
    server ICMP accept
    server ssh accept
    server smtp accept
    server pop3s accept
    server dns accept
    server dhcprelay accept
    server dhcp accept
    client all accept

interface wlan0 lanwifi
    policy reject
    server dns accept
    server http accept
    server https accept
    server ICMP accept
    server ssh accept
    client all accept
    masquerade

router wifi2internet inface "wlan0" outface "eth0"
       masquerade
       route all accept

Afin de permetre d’utiliser les services qui nous intéressent et de faire le routage entre le réseau wifi et le lan.

Pour permettre le démarrage de firehol, éditer le fichier /etc/default/firehol pour y mettre :

START_FIREHOL=YES

On teste tout ça

Redémarrer le réseau pour prendre en compte les modifications :

service networking restart
service unbound restart
service hostapd restart
service firehol restart

La suite

Et on peut passer à la suite : configuration de postfix