Using a Raspberry Pi with LibreELEC/KODI as a bridged WiFi Access point

Copyright 2020 Herbert Hanewinkel, Neuried
 
08.2020

Overview

A Raspberry Pi with LibreELEC/KODI is a great media center. By adding: it could be used for:
My Raspberry Pi is connected by an ethernet cable to a DSL router for internet access. The DSL router serves also as Wifi access point.
My problem: Near the TV set the routers Wifi signal was weak.
Why not use the Raspberry Pi itself as Wifi access point itself?

Using LibreELEC/KODI as bridged Wifi access point

LibreELEC supports "tethering" via Wifi for supporting a mobile as remote control. "Tethering" is enabled under LibreELEC network options by enabling the "tethering" option, define your SSID name for the Wifi access point and change the password to an individual value.
It creates a new interface "tether" and assign it an IP address 192.168.0.1.
Wifi clients will receive via DHCP protocol  IP addresses starting from 192.168.0.2, gateway 192.168.0.1, dns server 8.8.8.8

This works fine, but:
with tethering enabled we get a second network in our LAN that is not directly connected to the router.
Because of NAT Wifi clients are not addressable from the 192.168.1.x network.
This could be solved by a Wifi access point bridged to ethernet.

Tethering and networking is handled in LibreELEC by connman package. connman contains software to create a Wifi access point, a DNS cache, a DHCP server for Wifi clients and NAT for ip masquerading.
We only need the Wifi access point and have to avoid the tether interface created by connman.
With the ip tool we can create a bridge interface and configure a bridge between eth0 and wlan0.
  1. Use the LibreELEC network setup to configure a static ip address and a gateway address for the ethernet interface.
  2. Use the LibreELEC network setup to enable tethered and setup a Wifi access point.
  3. Login via ssh and add the following lines to .config/autostart.sh

    #create bridge interface br0
    ip link add name br0 type bridge
    ip link set br0 up
    #assign eth0 to br0, eth0 must be up
    ip link set eth0 up
    ip link set eth0 master br0
    #save eth0 ip-address and gw
    eth_ip=`ip addr show eth0 | awk '/inet / {printf("%s", $2)}'`
    eth_gw=`route -n | awk '/^0.0.0.0/ {printf("%s", $2)}'`
    #move from eth0 to br0
    ip addr del $eth_ip dev eth0
    ip addr add $eth_ip broadcast + dev br0
    route add -net default gw $eth_gw

  4. After reboot LibreELEC should show a bridge interface with the static ip address and a default route with the defined gateway using interface br0. eth0 must show no ip address, or access will fail, e.g.

  5. If ssh access to the static ip address fails, connect to the WiFi access point and ssh to 192.168.0.1 to fix the script.
    If the set up is ok, start the bridge with

    ip link set wlan0 master br0

  6. Test the bridge with Wifi clients, if all is ok, append the command to autostart.sh

    #assign wlan0 to br0
    ip link set wlan0 master br0

    and reboot.

Easy setup using a script:
  1. Use the LibreELEC network setup to configure a static ip address and a gateway address for the ethernet interface.
  2. Use the LibreELEC network setup to enable tethered and setup a Wifi access point.
  3. Login via ssh and download my script bridge.sh
    wget http://r.hanewin.net/bridge.sh
  4. Run it for a test
    chmod +x bridge.sh
    ./bridge.sh

    because ip addresses are modified, it will drop your connection, reconnect and check ip addresses.
  5. If it works, move it in folder .config and call it from .config/autostart.sh.
www.haneWIN.net Home