Mobile Mesh Networks with the Raspberry Pi – Part 4

A Raspberry Pi mesh network with internet access.In the last tutorial I explained how to set up an ad-hoc mesh network on the Raspberry Pi. That was pretty neat, but not as useful as one might hope because each of the individual nodes did not have internet access. I will now explain how to set up internet access on each of the nodes.

Setting up Internet Access on the Mesh Network

In order to connect the Pi mesh network to the internet, one of the interfaces on the device will have to be connected to a network that has internet access. In this case, I used the ethernet connection as a bridge to the internet — but I do not see any reason why you could not use two wireless cards in the same way. The Pi that has the connection to the internet is going to act as a gateway for the rest of the mesh network by acting as a NAT conduit. Like your router, the Pi board will keep track of what traffic is sent where and provide access to the Pi subnet.

  1. First, enable ip forwarding: # echo 1 > /proc/sys/net/ipv4/ip_forward
  2. Now modify the IP tables so the subnet on one interface can talk to the subnet on the other interface. In this case, eth0 is the external network card and wlan0 is the internal network card:
    1. # iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    2. # iptables -A FORWARD -i eth0 -o wlan0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
    3. # iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
  3. Now we have to add a route so the other Pis will know where to send traffic not subnet specific, aka traffic to the internet. A protocol must be specified in order for babeld to pass it along to the mesh. Issue this command on the node that is connected to the internet; it will propagate to the other nodes. In this case, is the address of my router that leads to the internet, not the Pi that is acting as a router: # ip route add via dev eth0 proto static
  4. All the nodes on the mesh network should now have access to internet IP addresses. But, if you are like me and you would like to type in domain names instead of numbers, we need to set up DNS access on the rest of the nodes. The node connected to the internet should already have it due to dhcpcd. Modify the following file on the rest of the nodes to enable DNS lookup: # nano /etc/resolv.conf . Append the file with the address of your DNS server. In this case my router acts as my DNS server: nameserver . The change should take effect immediately, and you will be able to ping and other addresses.

If you want to see statistics about your network, try installing nmon: # pacman -S nmon .


I decided to test the throughput of the connection by downloading a linux iso. When the gateway was connected directly to node 3, I got speeds around 400kb/s. I then moved node 3 further away so traffic had to be routed from node 1 to node 2 and then to node 3. After the network healed itself, I received throughput close to 250kb/s. Not too shabby! You can see how the data flows from one interface and one node to the next in the screenshot above.

I have also consistently gotten over 14 hours of battery life from the cell phone chargers I picked up to make the mesh networks mobile.

Potential Problems

For small mesh networks, this is a quick and dirty way to get internet access. As they grow and you would like more internet gateways to ensure redundant access, you will probably need a different plan of attack to make sure network traffic  gets routed appropriately.

Additional Resources

These pages helped me out,  they might help you out too:

See Also

Part 1

Part 2

Part 3

This Post Has 7 Comments

  1. gsugizmo says:

    Just to clarify, are your throughput figures in kilobits or kilobytes per second?

    Great work on your project!

    • Eric Erfanian says:

      Hmm. Good question. I’m not sure what the tools are actually reporting. I’m going to guess bytes.

      • aardvark says:

        Could you please figure that out, or tell me the tools that you are using so I can look it up myself? I want to do this, but the throughput would be quite a deal breaker for me.


  2. Arif says:

    I have a problem with self-configure the node mobile ad hoc network, when the node is outside the reach of network wireless signal, then back into the range of the signal, can not connect anymore to the Manet?

    thank you Mr..

  3. Username* says:

    can i use dynamic ip instead of static ip because i trying to create a mobile network node.example i have 3 node, basic,a-b-c will connect to each other. if i remove node b,i want node a to automatic to connect to node c. i still new and still learning about it and Raspberry Pi

    • Eric Erfanian says:

      See the above commend about Avahi for dynamic ip addresses. IIRC the nodes all can talk to one another — even if one of them leaves the mesh — as long as they share the same routing table.

Leave A Reply