0

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?

2

Wireless Ad Hoc Networking with Raspberry Pi - 2 Model B / Pi - 3 with IPv6

OS used: Raspbian Jessie 8.0

kernel version:

  • 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, r8188eu or rt2x00lib for external dongles.

Note:

Edimax 7811UN dongles or dongles with 8192cu drivers 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 fd00::/8.

For instance, a Pi can have an ULA address: fd23:4567:89ab:1::1/64 and another pi may have fd23:4567:89ab:1::2/64.

To get more information or generate a random ULA for an application, refer to Unique Local IPv6 Generator


Configuration Steps

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 /etc/network/interfaces file.

Pi - 3 Configuration

  • /etc/network/interfaces file:

    # 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:

    iwconfig wlan0
    

    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
    

    parameter like Tx-Power and Power Management can be changed using iwconfig.

    # for Tx-Power to be 5 dBm
    iwconfig wlan0 txpower 5
    
  • Finally, perform sudo ifdown wlan0 && sudo ifup wlan0 to set the ULA on wlan0.

    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:dead is your Link-Local Address synonymous to IPv4 169.254.0.0/16.

Pi - 2 Configuration

  • /etc/network/interfaces file is the same as previously mentioned for Pi - 3. The Pi - 2 may have the address as fd23:4567:89ab:1::2 with 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 wlan0 using sudo ifdown wlan0 && sudo ifup wlan0

  • To check perform iwconfig wlan0 and ifconfig wlan0 on Pi - 2


Checking connectivity

instead of 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:

  • in /etc/nsswitch.conf change to the line with [hosts] to the following:

    hosts:      files mdns_minimal [NOTFOUND=return] dns mdns
    
  • in order to use the .local domain add search local in the /etc/resolv.conf.

  • In /etc/avahi/avahi-daemon.conf make sure you have use-ipv6=yes.

  • In the end It is suggested to reboot your Pis and configure them to the Ad Hoc mode using iwconfig again. 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

or

ping6 -I wlan0 myPi2.local

This proves to be useful also when using ssh:

ssh -I wlan0 -l pi myPi3.local

or

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
  • Is this some sort of tutorial that you followed for installation or you wrote this? what is the problem/question? – hcheung Mar 8 '17 at 13:42
  • No I have been working with ad hoc networks for a year and I tried all possible ways to create it. I just wrote this as a part of references for future usage. The problem was with Edimax dongles and their incomptibility to form ad hoc networks. But on the contrary other dongles with their respective drivers worked so thought of sharing the answer. For generic references – Shan-Desai Mar 8 '17 at 13:45
  • @hcheung I am still open to modifications to both the answer and question. Any suggestions? – Shan-Desai Mar 8 '17 at 13:48
  • First of all, this is not a place to self-post a question and self-answering a question. If you want to share with your write-up, try post it on your own blog or github or other platform. Secondly, your 2nd post give me an impression that you had a problem on ip6 avahi resolve, and 1st post doesn't outline what's the problem and how you solve it, but more or less look like of how to setup an ad hoc network with ip6. By the way, since the release of Jessie, the configuration of network is supposed to be done via /etc/dhcpcd.conf than the old way of changing the /etc/network/interface. – hcheung Mar 8 '17 at 14:22
  • 1
    Ok just tried. Works like a charm. That is, IPv6 configuration with Raspberry Pi3. 0 issues, connectivity confirmed with ping6. Now I just need to change the interface configuration to start ad-hoc mode automatically. Thanks! – Dash83 Nov 23 '18 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.