1

I'm working on a custom Linux OS (built with Yocto) and I have two internet sources, one is GSM and another one is Wi-Fi. GSM is handled with PPP connection (ppp0 interface) and for Wi-Fi I use wpa_supplicant on wlan0 interface. I can switch between AP and client mode on wlan0 interface. Whenever I switch to client mode, and I'm already connected with pppd, my device still uses GSM by default, it means it still consume data transfer form SIM card instead of Wi-Fi. To use Wi-Fi as a network source I have to stop pppd and do dhclient -v -1 wlan0

I would like to set up a connection with some kind of prioritizing. When I'm connected to Wi-Fi network and there is Internet access, use Wi-Fi as a source of the network, otherwise use GSM. Now it looks like it works the other way around.

I tried with setting metric value (equal to 0) on networkd or as a route parameter but, what is interesting, I have ppp0 metric set as 0 by default, but the command I use to set it up is route add default dev $PPP_IFACE metric 1

Here is my route output:

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         *               0.0.0.0         U     0      0        0 ppp0
default         *               0.0.0.0         U     1      0        0 ppp0
10.8.8.0        *               255.255.255.0   U     0      0        0 proxy
10.64.64.64     *               255.255.255.255 UH    0      0        0 ppp0
192.168.1.0     *               255.255.255.0   U     0      0        0 wlan0
192.168.77.0    *               255.255.255.0   U     0      0        0 br0

Can somebody explain to me how to set it up to get my target setup?

1
  • If iptables and policy routing are out of the question, then you could use ifmetric to change the metric value of an existing route. Supposedly you have 2 routes, a ppp0 and a wlan0, both with meric 0. If you want to downgrade, let's say ppp0, run ifmetric ppp0 800 (or any number higher that the metric of wlan0) and ppp0 will get route priority.
    – gmelis
    Commented Mar 9, 2021 at 9:20

1 Answer 1

-1

I don't think you can prioritize routes without using ip route, but you can use multiple routing tables and some iptables.

Route tables: Linux-2.x can pack routes into several routing tables identified by a number
in the range from 1 to 2^32-1 or by name from the file /etc/iproute2/rt_tables By default
all normal routes are inserted into the main table (ID 254) and the kernel only uses this
table when calculating routes. Values (0, 253, 254, and 255) are reserved for built-in use. 

You can create multiple routing tables, with each having its own default gateway, then use iptables to route packets using one of those routing tables. I have used this scheme along with a script which ping periodically a host via my primary interface. If it failed it would switch routing tables and if it later received a reply, it would change back to the default configuration. Simple and effective.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .