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

Copyright © 2020 Herbert Hanewinkel, Neuried
 
updated 09.2021

Overview

A Raspberry Pi with LibreELEC/KODI makes 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 local 192.168.1.x network.
This could be solved by a Wifi access point bridged to ethernet. It avoids NAT and a second network.

Tethering and networking are 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 create a script with the following contents or download my script bridge.sh
    wget http://r.hanewin.net/bridge.sh
  4. What it contains:

    #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
    #extract and 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 addresses from eth0 to br0
    ip addr del $eth_ip dev eth0
    ip addr add $eth_ip broadcast + dev br0
    # add new default route
    route add -net default gw $eth_gw
    # add wlan interface to bridge br0
    ip link set wlan0 master br0

  5. Run it for a test
    chmod +x bridge.sh
    ./bridge.sh

    because ip addresses are modified, it will drop your ssh connection, reconnect and check ip addresses. If ssh access fails something went wrong and you have to reboot.
  6. If all is ok, 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.

  7. Test the bridge setup with Wifi clients, if all is ok, move bridge.sh to folder .config
  8. To run it on boot append the line
    /storage/.config/bridge.sh
    to .config/autostart.sh
  9. To avoid connman configuring the br0 interface, add ",br" to the NetworkInterfaceBlacklist in file
    /storage/.config/connman_main.conf

The eth0 interface must have a static ip address otherwise connman dhcp client will refresh the address.


www.haneWIN.net Home