Skip to content

Instantly share code, notes, and snippets.

@tyhenry
Last active July 13, 2019 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyhenry/257617d922b50d9ad63f4ccaaeff53d2 to your computer and use it in GitHub Desktop.
Save tyhenry/257617d922b50d9ad63f4ccaaeff53d2 to your computer and use it in GitHub Desktop.
install and setup batman-adv on raspberry pi
# tested on Raspberry Pi 3B+ with Raspbian Stretch 2018
############ SETTINGS:
# the wlan interface batman should use, probably wlan0 or wlan1
WLAN="wlan0"
# static ip, adjust as needed
BATMAN_IP="172.27.0.1"
# mesh ssid
MESH_SSID="mesh_net"
# wifi channel (probably 1, 6 or 11)
CHANNEL="1"
# the path and name of the batman boot script we'll create
BOOTSCRIPT_PATH="${HOME}/batman-adv_start.sh"
############# END SETTINGS
# generate the script
BOOTSCRIPT="
# Activate batman-adv
sudo modprobe batman-adv
# Disable and configure wlan interface
sudo ip link set ${WLAN} down
sudo ifconfig ${WLAN} mtu 1500
sudo iwconfig ${WLAN} mode ad-hoc
sudo iwconfig ${WLAN} essid ${MESH_SSID}
sudo iwconfig ${WLAN} ap 02:12:34:56:78:9A
sudo iwconfig ${WLAN} channel ${CHANNEL}
sleep 1s
sudo ip link set ${WLAN} up
sleep 1s
sudo batctl if add ${WLAN}
sleep 1s
sudo ifconfig bat0 up
sleep 5s
sudo ifconfig bat0 ${MESH_IP}/24
"
# 1. install batman
echo "installing batman-adv..."
sudo apt-get update
sudo apt-get install -y batctl
# 2. create boot script
echo "creating boot script at ${BOOTSCRIPT_PATH}..."
echo "${BOOTSCRIPT} > ${BOOTSCRIPT_PATH}"
sudo chmod +x "${BOOTSCRIPT_PATH}"
# 3. deny dhcp on the batman wlan interface at boot
echo "denying dhcp on ${WLAN} using /etc/dhcpcd.conf
echo "denyinterfaces ${WLAN}" | sudo tee -a /etc/dhcpcd.conf >/dev/null
# 3. run batman script on boot
echo "setting up batman boot from /etc/rc.local"
echo "${BATMAN_BOOT_SCRIPT}" | sudo tee -a /etc/rc.local >/dev/null
# install dependencies
sudo apt-get update
sudo apt install dnsmasq hostapd
# configure static ip
WLAN_CONF="
interface wlan0
static ip_address=192.168.4.1/24
nohook wpa_supplicant
"
# WIP, TODO - copy from: https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment