Bridge LAN and Wi-Fi clients (using relayd)

You are here:
Estimated reading time: 2 min

Sometimes, it is needed to setup your router as a Wi-Fi client and, at the same time, allowing the LAN clients of the Maestro router to be in the same network of your main router. Most wireless drivers do not support bridging in client mode, therefore the traffic between LAN and the wireless clients must be routed. The relayd package helps to implement a bridge-like behavior.

It is important to note that the 192.168.2.0 network in the above picture is not going to be used by any clients, but relayd requires the LAN interface to be in a different subnet to work.

Configure bridged client

The easiest way to achieve this setup is by accessing your E220/E220 router via SSH and follow these instructions:

  • Create a new file
    vim /usr/sbin/bridged-client.sh
  • Type i to enter insert mode and paste following script (fields written as <value> must be edited to match your specific settings/values):
    #!/bin/sh
    # Make sure the Wi-Fi interface is enabled
    uci set wireless.@wifi-device[0].disabled=0
    uci commit wireless
    wifi
    # Create an interface for the wireless station
    uci set network.wwan=interface
    uci set network.wwan.proto=dhcp
    uci commit network
    # Configure the wireless settings to connect to your WiFi Acces Point
    uci set wireless.radio0.channel=<channel>
    uci set wireless.@wifi-iface[0].network=wwan
    uci set wireless.@wifi-iface[0].mode=sta
    uci set wireless.@wifi-iface[0].ssid=<ssid>
    uci set wireless.@wifi-iface[0].encryption=<encryption>
    uci set wireless.@wifi-iface[0].key=<key>
    uci commit wireless
    wifi down; wifi
    # Configure the default OpenWrt repositories to install relayd package
    echo "dest root /" > /etc/opkg.conf
    echo "dest ram /tmp" >> /etc/opkg.conf
    echo "lists_dir ext /var/opkg-lists" >> /etc/opkg.conf
    echo "option overlay_root /overlay" >> /etc/opkg.conf
    echo "src/gz barrier_breaker_base http://downloads.openwrt.org/barrier_breaker/14.07/ramips/mt7620a/packages/base/" >> /etc/opkg.conf
    echo "src/gz barrier_breaker_luci http://downloads.openwrt.org/barrier_breaker/14.07/ramips/mt7620a/packages/luci/" >> /etc/opkg.conf
    echo "src/gz barrier_breaker_management http://downloads.openwrt.org/barrier_breaker/14.07/ramips/mt7620a/packages/management/" >> /etc/opkg.conf
    echo "src/gz barrier_breaker_oldpackages http://downloads.openwrt.org/barrier_breaker/14.07/ramips/mt7620a/packages/oldpackages/" >> /etc/opkg.conf
    echo "src/gz barrier_breaker_packages http://downloads.openwrt.org/barrier_breaker/14.07/ramips/mt7620a/packages/packages/" >> /etc/opkg.conf
    echo "src/gz barrier_breaker_routing http://downloads.openwrt.org/barrier_breaker/14.07/ramips/mt7620a/packages/routing/" >> /etc/opkg.conf
    echo "src/gz barrier_breaker_telephony http://downloads.openwrt.org/barrier_breaker/14.07/ramips/mt7620a/packages/telephony/" >> /etc/opkg.conf
    opkg update
    opkg install relayd
    /etc/init.d/relayd enable
    # Declare a relay interface
    uci set network.stabridge=interface
    uci set network.stabridge.proto=relay
    uci set network.stabridge.network="lan wwan"
    uci commit network
    # Add gateway and DNS for the LAN interface (this is usually the IP address of the Access Point)
    uci set network.lan.gateway=<dhcp_router_ip>
    uci set network.lan.dns=<dhcp_router_ip>
    uci commit network
    # Disable the local DHCP server
    uci set dhcp.lan.ignore=1
    uci commit dhcp
    # Adjust the firewall
    uci set firewall.@zone[0].forward=ACCETP
    uci set firewall.@zone[0].network="lan wwan"
    uci commit firewall
    # Apply the changes by restarting DHCP, firewall and wireless
    /etc/init.d/dnsmasq restart
    /etc/init.d/firewall restart
    wifi down; wifi
  • Now unplug and plug again the LAN cable of your laptop from Maestro router and you will see you will be assigned an IP address in the range of the main router, i.e. 192.168.1.0 following the schematic above.

Enable access from client network

After this the relay should work, however you will have trouble reaching the router from the client network if the client IP is not changed. To get to it you will need to manually set the IP address on your computer to an IP address on the same subnet (like 192.168.2.201 if you set the router LAN IP to 192.168.2.1). This is kind of tedious but you can set things up so you can get it from the client network. Execute following commands to do so (<wireless_ip> is the IP address assigned to the Maestro router by the WiFi Access Point):

uci set network.stabridge.ipaddr=<wireless_ip>
uci commit network

Enable access from main router

It is also possible to access your Maestro router from the main router. In order to do so, it is needed to enable web access from WAN zone with following commands:

uci set firewall.@rule[8].enabled=1
uci commit firewall

Via OpenWrt.

Was this article helpful?
Dislike 0 0 of 0 found this article helpful.
Views: 1148
Back to Top