How to use ip command to change default routing metric on Linux

Hi,

I have two internet connections. One is from ADSL router (eth0) and another one is from 4G LTE USB stick. When I connect USB stick I see two routing entries

ip route show
default via 192.168.1.1 dev eth0 proto static metric 425 
default via 103.x.y.z dev wwx001e101f0000 proto static metric 700 

Because of metric traffic always go through eth0. There is case when I need to route traffic using wwx001e101f0000 interface of USB 4G LTE stick. How can I change that without disconnecting eth0? Is it possible to change routing metric for wwx001e101f0000 to say ‘200’ so that route traffic via that interface when connected?

Have you tried the ip route replace command?

sudo ip route replace default via {IP} dev {DEVICE} metric {METRIC}

Set metric to 100 for the ip called 1.2.3.4 and interface named wwx001e101f0000:

sudo ip route replace default via 1.2.3.4 dev wwx001e101f0000 proto static metric 100

Then see it:

sudo ip route show
sudo ip route show default

It works but it is creating three entries in routing table. Is that correct?

Before

default via 192.168.1.1 dev eth0 proto static metric 425 
default via 103.x.y.z dev wwx001e101f0000 proto static metric 700 

Now

default via 103.x.y.z dev wwx001e101f0000 proto static metric 100
default via 192.168.1.1 dev eth0 proto static metric 425 
default via 103.x.y.z dev wwx001e101f0000 proto static metric 700 

How can i remove the last metric 700 entry?


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki