-
Notifications
You must be signed in to change notification settings - Fork 4
Batman Adv and Batctl
I have created a script to install the newest version (at this time 2018.1) of batman-adv, batctl, alfred and batman-vis on a raspberrypi. The script also installs some important packages for compiling the module.
Hint: Last time i tried a clean install it did not work for some reason. Sometime it works sometimes not. So perhaps you should try a newer version of the software. Follow the links an use newer ones instead of 2018.1 Raspian stretch seems to change things a lot at the moment. Just give it a try.
Just run the following command:
time sh -c "$(curl -sSL https://raw.githubusercontent.com/suiluj/pi-adhoc-mqtt-cluster/master/install_scripts/batmaninstall.txt)"
This procedure takes some time. Because of the time
at the beginning of the command you get the execution time after it has finished.
On my RaspberryPi Zero W it took XX minutes.
The RaspberryPi 3 B+ took XX minutes.
This also depends on your internet connection speed.
Configure batman, the adhoc interfaces and optional internet gateways and network bridges at startup
Internal wlan0 will be used for the adhoc network.
Important:
Either choose Option 1: "Batman meshnode without bridge or gateway" or Option 2: "Batman meshnode with bridge" or Option 3: "Batman meshnode with internet gateway":
In your default user folder /home/pi
create a file for the script:
sudo nano batsetup-rpi.sh
:
iw wlan0 set type ibss
ip link set wlan0 up
iw wlan0 ibss join <adhocnetworkname> 2432 key d:2:<password>
# replace <adhocnetworkname> with a ssid for example: rpiadhoc
# replace <password> with a password of length 5 or 13 (WEP) for example: abcdefghijklm
modprobe batman-adv
batctl if add wlan0
ip link set up dev wlan0
ip link set up dev bat0
batctl gw_mode client # optional if there is a gateway for internet in your network
sleep 10
alfred -i bat0 -m -p 1 &
sleep 10
batadv-vis -i bat0 -s &
Do not forget to replace the bracket terms! All nodes need to have the same network name and password.
Add this line at the end of the file sudo nano /etc/dhcpcd.conf
:
sudo nano /etc/dhcpcd.conf
.
. something else is here
.
denyinterfaces wlan0
Go to "Start the script after boot".
The following configuration is very similar to the one above but bridges the eth0 (lan cable) connection of a raspberrypi 3 with the batman interface. So the mesh nodes get access to the local network of the eth0 interface and vice versa.
In your default user folder /home/pi
create a file for the script:
sudo nano batsetup-rpi.sh
:
iw wlan0 set type ibss
ip link set wlan0 up
iw wlan0 ibss join <adhocnetworkname> 2432 key d:2:<password>
# replace <adhocnetworkname> with a ssid for example: rpiadhoc
# replace <password> with a password of length 5 or 13 (WEP) for example: abcdefghijklm
modprobe batman-adv
batctl if add wlan0
ip link set up dev wlan0
ip link set up dev bat0
batctl gw_mode client # optional if there is a gateway for internet in your network
ip link add name mesh-bridge type bridge
ip link set dev eth0 master mesh-bridge
ip link set dev bat0 master mesh-bridge
ip link set up dev eth0
ip link set up dev bat0
ip link set up dev mesh-bridge
sleep 10
alfred -i mesh-bridge -m -p 1 &
sleep 10
batadv-vis -i mesh-bridge -s &
Do not forget to replace the bracket terms! All nodes need to have the same network name and password.
Deny wlan0 and eth0 interface to be able to use it as adhoc interface and bridge with the script above
interfaces: wlan0 and eth0
Add these lines at the end of the file sudo nano /etc/dhcpcd.conf
:
sudo nano /etc/dhcpcd.conf
.
. something else is here
.
denyinterfaces wlan0
denyinterfaces eth0
Go to "Start the script after boot".
wlan0 - used again for the adhoc network
eth0 (the cable) is connected to another network with internet and used as gateway for the meshnodes to have internet access
Alternative configuration: Additional usb wifi dongle as internet gateway network (Click here)
In your default user folder /home/pi
create a file for the script:
sudo nano batsetup-rpi.sh
:
iw wlan0 set type ibss
ip link set wlan0 up
iw wlan0 ibss join <adhocnetworkname> 2432 key d:2:<password>
# replace <adhocnetworkname> with a ssid for example: rpiadhoc
# replace <password> with a password of length 5 or 13 (WEP) for example: abcdefghijklm
modprobe batman-adv
batctl if add wlan0
ip link set up dev wlan0
ip link set up dev bat0
batctl gw_mode server
# set bat0 mac address as wlan0 mac address plus one
ip link set bat0 address b8:27:eb:77:3d:38
# set IPv6 link-local adress
# help link: https://ben.akrin.com/?p=1347
ip -6 addr add fe80::ba27:ebff:fe77:3d38/64 dev bat0
# Set Gateway IP
ip addr add 1.0.0.1/24 broadcast 1.0.0.255 dev bat0 # no duplicate IPs allowed when having multiple gateways
# This sets up routing between the mesh network (bat0) and the internet network (eth0)
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o bat0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i bat0 -o eth0 -j ACCEPT
sleep 10
alfred -i bat0 -m -p 1 &
sleep 10
batadv-vis -i bat0 -s &
Do not forget to replace the bracket terms! All nodes need to have the same network name and password.
Add this line at the end of the file sudo nano /etc/dhcpcd.conf
:
sudo nano /etc/dhcpcd.conf
.
. something else is here
.
denyinterfaces wlan0
Installation:
sudo apt-get update
sudo apt-get install dnsmasq
Configuration:
sudo nano /etc/dnsmasq.conf
:
# DHCP-Server active for the batman mesh network interface
interface=bat0
# DHCP-Server not active for internet network
no-dhcp-interface=eth0
# IPv4-address range and lease-time
dhcp-range=1.0.0.50,1.0.0.150,24h
# DNS
dhcp-option=option:dns-server,8.8.8.8
# Gateway: needs to be the same as the ip of the bat0 interface in the startup script
dhcp-option=3,1.0.0.1
Change the /etc/rc.local
file which will be executed at boot.
Add the following line before exit 0
:
/home/pi/batsetup-rpi.sh &
sudo nano /etc/rc.local
:
.
. something else is here
.
/home/pi/batsetup-rpi.sh &
exit 0
Just reboot your device and hope that everything works as expected. ;)
Now you cannot use your wifi in your normal local router home network. So you have to ssh connect differently to your device or use a monitor.
The raspberrypi 3 can be connected via lan cable eth0 to your home network.
The raspberrypi zero can even connect to your computer via usb. Then you can ssh via usb to your raspberrypi zero and even share the internet of your computer.
Here is an easy video tutorial for the usb ssh raspberrypi zero configuration:
YouTube Tutorial SSH over usb0
For internet access just share your internet connection:
Windows Internet Sharing
macOS Internet Sharing
- internet sharing over bridge ssl/https does not work
- i found the right configuration (see sources), will update my manual
- adhoc network uses only wep security which is bad and outdated.
- I read that
wpa_supplicant
is able to create adhoc networks with wpa security but i was not able to successfully configure it. (wpa_supplicant was not able to change the interface inibss (adhoc)
mode
- I read that
- change mtu size (i was not able to run the command for setting a mtu higher than 1500)
- dynamic ip adresses without central dhcp server. some solutions:
sudo avahi-autoipd bat0
- Kubernetes
Important note:
Some of following sources/tutorials work on older Raspbian versions and not on the new one due to some changes with the network commands and interfaces.