1

I have a system (kernel 4.4) which has two network interfaces to the outside world - ethernet e.g. via an ADSL router, and ppp. Both are NAT'd. (Btw I don't need to accept incoming connections, and don't have ipv6) The ethernet connection is prone to failure - perhaps just the local cable, but maybe the ADSL router (e.g. switched off) or even the ISP/ADSL line. I can detect this by pinging on specifically that interface; what I'd like to do in this situation is set the ppp to be the system's default i.e. so that when an app opens a new connection it doesn't need to know or specify which interface to use. I don't want to simply take the eth interface down, as I need to keep pinging on it to learn when it's alive again.

Route info is as follows:

route -n

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.10.254  0.0.0.0         UG    100    0        0 eth0
0.0.0.0         10.68.55.242    0.0.0.0         UG    700    0        0 ppp0
10.68.55.242    0.0.0.0         255.255.255.255 UH    700    0        0 ppp0
192.168.10.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0

ip route

default via 192.168.10.254 dev eth0  proto static  metric 100
default via 10.68.55.242 dev ppp0  proto static  metric 700
10.68.55.242 dev ppp0  proto kernel  scope link  src 10.68.55.242  metric 700
192.168.10.0/24 dev eth0  proto kernel  scope link  src 192.168.10.125  metric 100

[I'm unsure about there being two 'default', or indeed why there are...]

ip address

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:c6:7f:e5:50 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.125/24 brd 192.168.10.255 scope global dynamic eth0
       valid_lft 75591sec preferred_lft 75591sec
3: ppp0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 3
    link/ppp
    inet 10.68.55.242/32 scope global ppp0
       valid_lft forever preferred_lft forever

I think I can get my desired result by removing/re-adding one of the routes, giving it a metric higher or lower than that of the other interface. But this means a lil bit of tortuous parsing in a script.

So I wondered if there was a 'slicker' way to do this? I've read a lot of pages about iptables & rules, but for slightly different scenarios and I'm struggling to adapt the principles to my particular (simpler?) situation. Also not sure whether they would ultimately be slicker anyway.

I've searched here too, and I sense that changing the route metric may in fact be the most straight-forward method after all. But any other quick and clean ways for me to look into? Something that gives a very simple command for prodding things to and fro. Thanks.

  • Is this of any help? – Arrow Jul 14 '17 at 0:40
  • Found a better solution (the kernel may do the change automatically). If useful I may convert it to an answer. – Arrow Jul 14 '17 at 3:38
  • I'd seen that article, and whilst it does kinda work, it only seemed to cater for the case of the local cable being unplugged i.e. causing a link up/down event. When the fault is upstream, I don't think it realises. Hence, I'd also been putting together a script similar to Apsu's - seems better for a variety of failure scenarios (though I'm still testing and refining the error handling) – ColH Jul 14 '17 at 6:05
  • Hmm, that sounds like it is correct. Maybe the shell script above, then. – Arrow Jul 14 '17 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.