All postsTous les articles
CarPi CarPi

CarPi #3: Network CarPi #3 : Réseau

5 Feb 2016 Cédric Raguenaud

For the CarPi software, I had three constraints: phones must control the player; the CarPi needs occasional internet for updates; phones connected to the CarPi must also get internet.

Pour le logiciel du CarPi, j'avais trois contraintes : les téléphones doivent contrÎler le lecteur ; le CarPi doit avoir accÚs à internet de temps en temps pour les mises à jour ; les téléphones connectés au CarPi doivent aussi avoir internet.

Solution: two WiFi interfaces — one internal AP for phones (wlan1), one to connect upstream (wlan0). The CarPi acts as router/firewall.

Solution : deux interfaces WiFi — une en point d'accĂšs interne pour les tĂ©lĂ©phones (wlan1), une pour se connecter Ă  l'extĂ©rieur (wlan0). Le CarPi joue le rĂŽle de routeur/pare-feu.

Install DHCP server and hostapd

Installer le serveur DHCP et hostapd

sudo apt-get update
sudo apt-get install hostapd isc-dhcp-server

Configure DHCP

Configurer le DHCP

In /etc/dhcp/dhcpd.conf, make sure authoritative; is uncommented, then add:

Dans /etc/dhcp/dhcpd.conf, décommenter authoritative;, puis ajouter :

subnet 192.168.200.0 netmask 255.255.255.0 {
  range 192.168.200.100 192.168.200.200;
  option broadcast-address 192.168.200.255;
  option routers 192.168.200.1;
  default-lease-time 600;
  max-lease-time 7200;
  option domain-name "local";
  option domain-name-servers 8.8.8.8, 8.8.4.4;
}

Make wlan1 static

Rendre wlan1 statique

auto wlan1
allow-hotplug wlan1
iface wlan1 inet static
address 192.168.200.1
netmask 255.255.255.0
network 192.168.200.0
broadcast 192.168.200.255

Configure hostapd

Configurer hostapd

interface=wlan1
ssid=OnTheMove
hw_mode=g
channel=6
wpa=2
wpa_passphrase=VOTREMOTDEPASSE
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP

Enable IP forwarding and NAT

Activer le routage IP et le NAT

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -A FORWARD -i wlan1 -o wlan0 -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o wlan1 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
With some dongles (TP-Link, Edimax), the default hostapd can't act as an AP. You may need to replace it with Adafruit's patched version.
Avec certaines clĂ©s WiFi (TP-Link, Edimax), le hostapd de Raspbian ne sait pas gĂ©rer un point d'accĂšs. Il faudra peut-ĂȘtre le remplacer par la version patchĂ©e d'Adafruit.
CarPi completed