Default route is always wlan0?

Hopefully this is an easy one to answer, might be harder to change :slight_smile:

I have wlan0 (client mode) and eth0.2 both connected to the same network

        root@Nexx-LEDE:~# route
        Kernel IP routing table
        Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
        default         192.168.50.1    0.0.0.0         UG    0      0        0 wlan0
        10.244.0.0      *               255.255.0.0     U     0      0        0 zt0
        192.168.8.0     *               255.255.255.0   U     0      0        0 br-lan
        192.168.50.0    *               255.255.255.0   U     0      0        0 eth0.2
        192.168.50.0    *               255.255.255.0   U     0      0        0 wlan0
        192.168.50.1    *               255.255.255.255 UH    0      0        0 wlan0
        root@Nexx-LEDE:~#

On bootup, wlan0 always becomes the default gateway route-even if eth0.2 is connected.I would have thought that good old Ethernet would always be default (because wired is better than wireless?) Is this a design thing ?

I ask as I would like the eth0.2 to be the default route at boot-I have been playing about with ip route del and add -but just wanted to ask if there is a "deep" command that will always prefer Ethernet as the default route.

cheers

cabs

There is no logic which decides default route based on medium. There's two possibilities:

  1. set option defaultroute 0 on the wlan interface to suppress installing a defaultroute while still doing dhcp
  2. set option metric 10 to assign a higher metric to the wifi default route which should cause the ethernet default route to be preferred

Thanks Jow
I tried the higher metric, which works-will try the other one. Just wanted to see if I could save myself some work :slight_smile:

cabs

I managed to find a way-might be a bit cack-handed but works for me:

#change default route on boot up (using /etc/init.d/rc.local)
ip route change default via 192.168.50.1 dev eth0.2
(change 192.168.50.1 to your default gateway)

Use the following script to sense if the WAN connection has gone down (will be eth0.2 by default because of step 1-put it in as a cronjob/under scheduled tasks in Luci)

root@Nexx-LEDE:~# cat /etc/check_internet.sh 
#! /bin/sh
# Checks if the connection to the Internet is up.  If not, it tries to restart all interfaces.  If that fails, then reboot.

if ping -c 3 bbc.co.uk > /dev/null
then
  echo check WAN is a sucesss > /dev/null
else
  /etc/init.d/network restart
#Moves onto 2nd part, to try for a 2nd time! 
sleep 15
  if ping -c 3 www.google.com > /dev/null
  then
    echo nothing > /dev/null
  else
    date >> /etc/reboot.log
    reboot -f
 fi
fi
root@Nexx-LEDE:~#

There seems to be a bonus point :slight_smile: in that when the eth0.2 comes back up/is reconnected, the default route swaps back to eth0.2. It does for me when you disconnected it physically anyway.

cheers

cabs