Internet Connection Priority Change

Hello,

As per my observation, the following is the priority setting for internet connection in the openwrt.

Existing priority:

  1. WIFI Client (Priority-1) (Highest priority)
  2. ETH1 (Priority-2) (Lowest priority)

I want these priorities to be changed in my application. I want following priority setting for internet connection in my device:

Desired priority:

  1. ETH1 (Priority-1) (Highest)
  2. WIFI Client (Priority-2) (Lowest)

Please help me to change these priorities as mentioned above.

Thank you

Specify a custom metric for each upstream interface.
The lower the metric, the higher the priority.

1 Like

Hello @vgaetera

Thank you for your response.

Can you please tell me how I can specify the custom metric for each upstream interface?

Thank you

https://openwrt.org/docs/guide-user/network/ipv4/configuration?s=metric#protocol_dhcp

Hello @vgaetera ,

I have tried to add metric value in network file as show below, However I am not able to see effect on traceroute.

image

image

Is this the same procedure you suggest?

Let me know.

Metric doesn't work with separate routing tables.
You need to switch routing priority using rules.

Hello, @vgaetera

I already did that. Below is the backup link script for your reference.

NET_IF="wan2"
PING_IP_IF="8.8.8.8"
NET_FIF="wan"
PING_IP_FIF="8.8.8.8"

. /lib/functions/network.sh
network_flush_cache

for IPV in 4 6
do
  NET_IF="${NET_IF}${IPV%4}"
  NET_FIF="${NET_FIF}${IPV%4}"
  NET_FIF_1="${NET_FIF_1}${IPV%4}"

  eval network_get_device NET_DEV "${NET_IF}"
  eval network_get_gateway${IPV%4} NET_GW "${NET_IF}"

  if ping -q -c 3 -w 5 -I "${NET_DEV}" "${PING_IP_IF}" &> /dev/null
  then
    NET_RT="${NET_IF}"
  else
    # If 'wan' fails, check 'wan2'
    eval network_get_device NET_DEV "${NET_FIF}"
    eval network_get_gateway${IPV%4} NET_GW "${NET_FIF}"

    if ping -q -c 3 -w 5 -I "${NET_DEV}" "${PING_IP_FIF}" &> /dev/null
    then
      NET_RT="${NET_FIF}"
    else
      echo "All WAN interfaces have failed"
      # You can add further handling here if all WAN interfaces fail.
      # For now, NET_RT will stay as 'wan3' since that's the last option.
    fi
  fi

  echo "'${NET_RT}'"
  echo "uci set network.default${IPV%4}.lookup='${NET_RT}'"
  uci set network.default${IPV%4}.lookup="${NET_RT}"
  /etc/init.d/network reload
done

Below is the network file ...


config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config globals 'globals'
	option ula_prefix 'fd3d:89e2:c5a1::/48'

config interface 'lan'
	option type 'bridge'
	option ifname 'eth0'
	option proto 'static'
	option ipaddr '192.168.1.1'
	option netmask '255.255.255.0'
	option ip6assign '60'
	option ip4table 'lan'
	option ip6table 'lan'

config interface 'wan'
	option proto 'dhcp'
	option _orig_ifname 'eth1'
	option _orig_bridge 'false'
	option ifname 'usb0'
	option ip4table 'wan'
	option ip6table 'wan'
	option metric '10'
	option dns_metric '10'

config interface 'wan6'
	option ifname 'eth1'
	option proto 'dhcpv6'
	option ip4table 'wan'
	option ip6table 'wan'

config switch
	option name 'switch0'
	option reset '1'
	option enable_vlan '1'

config switch_vlan
	option device 'switch0'
	option vlan '1'
	option ports '0 1 2 3 6'

config switch_vlan
	option device 'switch0'
	option vlan '2'
	option ports '4 5'

config interface 'L2TP_Client'
	option proto 'l2tp'
	option server 'SERVER_ADDRESS'
	option username 'USERNAME'
	option password 'PASSWORD'
	option ipv6 'auto'
	option ip4table 'L2TP_Client'
	option ip6table 'L2TP_Client'

config interface 'wwan'
	option proto 'dhcp'
	option ifname 'apcli0'
	option ip4table 'wwan'
	option ip6table 'wwan'

config interface 'PPTP_Client'
	option proto 'pptp'
	option server 'SERVER_ADDRESS'
	option username 'USERNAME'
	option password 'PASSWORD'
	option ipv6 '1'
	option ip4table 'PPTP_Client'
	option ip6table 'PPTP_Client'

config interface 'wan2'
	option proto 'dhcp'
	option _orig_ifname 'usb0'
	option _orig_bridge 'false'
	option ifname 'eth1'
	option ip4table 'wan2'
	option ip6table 'wan2'
	option macaddr '70:B3:D5:10:22:F1'
	option metric '20'
	option dns_metric '20'

config rule 'default'
	option priority '80000'
	option lookup 'wan2'

config rule6 'default6'
	option priority '80000'
	option lookup 'wan2'

Above setup is between Cellular and Ethernet.

However, when I connect wifi client than my internet routing will be changed and it is coming from wifi instead of cellular.

I want below configuration.

  1. Cellular
  2. Wifi
  3. Ethernet

I hope you get my point.

1 Like

I updated the script to support multiple ISPs:
https://openwrt.org/docs/guide-user/network/wan/multiwan/mwan_netifd


You may also consider another well-known solution:
https://openwrt.org/docs/guide-user/network/wan/multiwan/mwan3

the metric affects the speed, so set 0 and 1 in the interface settings, 0 is the highest priority.
no need to set 10 or 20, may reduce connection speed

To be clear (and for anyone else viewing this thread later) setting a metric doesn't directly affect connection speeds at all. Giving a lower speed connection at lower metric (i.e. higher priority) will lead to you having a 'slower' connection, but that is an indirect effect. You can freely use 10, 20, 30, (or higher numbers) as metric scores without any impact on the connection itself.

1 Like

Hello @vgaetera ,

Thank you for your response.

I will use multiwan script that you suggested.

But I have two questions.

1.WiFi will take highest priority from eth1 and USB0 when wifi client will connect in between dual WAN fail over script will run.
2. I am using OPENWRT 17.01 LEDE. So, can i use mwan3 latest package?

Please let me know.

my dual wan backup script...

NET_IF="wan2"
PING_IP_IF="8.8.8.8"
NET_FIF="wan"
PING_IP_FIF="8.8.8.8"

. /lib/functions/network.sh
network_flush_cache

for IPV in 4 6
do
  NET_IF="${NET_IF}${IPV%4}"
  NET_FIF="${NET_FIF}${IPV%4}"
  NET_FIF_1="${NET_FIF_1}${IPV%4}"

  eval network_get_device NET_DEV "${NET_IF}"
  eval network_get_gateway${IPV%4} NET_GW "${NET_IF}"

  if ping -q -c 3 -w 5 -I "${NET_DEV}" "${PING_IP_IF}" &> /dev/null
  then
    NET_RT="${NET_IF}"
  else
    # If 'wan' fails, check 'wan2'
    eval network_get_device NET_DEV "${NET_FIF}"
    eval network_get_gateway${IPV%4} NET_GW "${NET_FIF}"

    if ping -q -c 3 -w 5 -I "${NET_DEV}" "${PING_IP_FIF}" &> /dev/null
    then
      NET_RT="${NET_FIF}"
    else
      echo "All WAN interfaces have failed"
      # You can add further handling here if all WAN interfaces fail.
      # For now, NET_RT will stay as 'wan3' since that's the last option.
    fi
  fi

  echo "'${NET_RT}'"
  echo "uci set network.default${IPV%4}.lookup='${NET_RT}'"
  uci set network.default${IPV%4}.lookup="${NET_RT}"
  /etc/init.d/network reload
done

Thank you

The current MWAN with netifd implementation loops trough the list of interfaces specified in the relevant network config section and checks connectivity to their gateways.
When it receives a positive reply, the respective interface is used for default routing and the rest of the list is ignored, so the higher the position in the list, the higher the routing priority.

Hello @vgaetera

Any suggestion to set Wifi priority in openwrt lede using route command?

Because when I connect wifi apcli0 it will take highest priority and my wifi apcli0 will disconnect when network is reload.

I want below mwan backup.

  1. Cellular
  2. Wifi
  3. Ethernet

Please help me out from this errors.