How to connect multiple Raspberry Pis (Pi -2 and Pi - 3) using WLAN(wifi) in Ad Hoc fashion? Is it possible to use IPv6 addressing schemes rather than IPv4? Since IPv6 addresses are quite long, how can one use avahi to resolve a Pi within the network?
Wireless Ad Hoc Networking with Raspberry Pi - 2 Model B / Pi - 3 with IPv6
OS used: Raspbian Jessie 8.0
4.4.38-v7+ for Raspberry Pi 3
4.4.13-v7+ for Raspberry Pi - 2
Raspberry Pi - 2 Model B require specific external USB WLAN dongle for creating Ad Hoc networks, while as the internal WLAN module for Raspberry Pi 3 is sufficient.
External USB Dongles
Tests with following Drivers on the dongles for creation of ad hoc networks were conducted:
| Driver Name | USB dongle |
| Ralink RT5370 | LogiLink WL1045A v.2.0 |
|Ralink R8188EU | LogiLink WL1045A v.1.0|
In order to check if any USB dongle one uses features the above mentioned drivers perform the following command:
lsmod | grep "cfg80211"
The command would specifically tell you which driver module is available for WLAN e.g.
brcmfmac for Pi - 3,
rt2x00lib for external dongles.
Edimax 7811UN dongles or dongles with
8192cudrivers are Incompatible in forming ad hoc networks.
Unique Local Addresses (ULA) IPv6
Synonymous to IPv4 Private Addresses viz.
10.0.0.0 - 10.255.255.255
172.16.0.0 - 172.31.255.255
192.168.0.0 - 192.168.255.255
ULA for IPv6 can be assigned to each Pi for Unicast purpose.
They start with
For instance, a Pi can have an ULA address:
fd23:4567:89ab:1::1/64 and another pi may have
To get more information or generate a random ULA for an application, refer to Unique Local IPv6 Generator
For both the Pis, we use the
iwconfig cmdline tool to create a ad hoc network. Adding the IPv6 address can be done by using
Pi - 3 Configuration
# only showing wlan0 Configuration # for brevity auto wlan0 allow-hotplug wlan0 iface wlan0 inet6 static address fd23:4567:89ab:1::1 netmask 64 autoconf 1 dad-attempts 0 accept ra 0
for ad hoc Configuration:
sudo iwconfig wlan0 mode ad-hoc sudo iwconfig wlan0 essid my-adhoc sudo iwconfig wlan0 channel 1
to check if your wireless network is configured do the following:
which should produce the following output:
wlan0 IEEE 802.11bgn ESSID:"my-adhoc" Mode:Ad-Hoc Frequency:2.437 GHz Cell: 72:FD:2F:DC:FD:CE Tx-Power=20 dBm Retry short limit:7 RTS thr:off Fragment thr:off Power Management:off
Power Managementcan be changed using
# for Tx-Power to be 5 dBm iwconfig wlan0 txpower 5
sudo ifdown wlan0 && sudo ifup wlan0to set the ULA on
ifconfig wlan0 wlan0 Link encap:Ethernet HWaddr b8:27:eb:74:65:d6 inet6 addr: fd5d:12c9:2201:1::1/64 Scope:Global inet6 addr: fe80::beef:ebff:fe11:dead/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
ULA is assigned and
fe80::beef:ebff:fe11:deadis your Link-Local Address synonymous to IPv4
Pi - 2 Configuration
/etc/network/interfacesfile is the same as previously mentioned for Pi - 3. The Pi - 2 may have the address as
fd23:4567:89ab:1::2with other parameters being the same.
Since the WLAN dongle is external for Pi - 2, it is preferable to do the following steps to configure ad hoc operation:
sudo ifconfig wlan0 down sudo iwconfig wlan0 mode ad-hoc sudo iwconfig wlan0 essid my-adhoc sudo iwconfig wlan0 channel 1 sudo ifconfig wlan0 up
add the ULA address to
sudo ifdown wlan0 && sudo ifup wlan0
To check perform
ifconfig wlan0on Pi - 2
ping we use
ping6 in the following way:
Pi - 3 --> Pi -2
ping6 -I wlan0 fd23:4567:89ab:1::2
This should ping your Pi - 2 proving both your pis are in Ad-Hoc operation wirelessly.
Using mDNS Avahi
For IPv6 change the following files on the Pis:
/etc/nsswitch.confchange to the line with
[hosts]to the following:
hosts: files mdns_minimal [NOTFOUND=return] dns mdns
in order to use the
search localin the
/etc/avahi/avahi-daemon.confmake sure you have
In the end It is suggested to reboot your Pis and configure them to the Ad Hoc mode using
iwconfigagain. or a bash script can be created and triggered on boot.
Finally you can now reach the Pis using their names:
ping6 -I wlan0 myPi3.local
ping6 -I wlan0 myPi2.local
This proves to be useful also when using
ssh -I wlan0 -l pi myPi3.local
ssh -I wlan0 -l pi myPi2.local
To resolve the Name and Address of a pi in the Ad Hoc network use:
avahi-resolve -n nameofpi.local