E
E
Eugene2014-06-26 18:43:30
linux
Eugene, 2014-06-26 18:43:30

How to fix the automatic route switching script?

At the input: a poorly readable script with automatic switching of interfaces with the Internet does not work out as it should, and, unfortunately, I am not strong in networks.
Everything lies here . The script itself is here .
The script works, except for this case: there is an IP on the first interface, the ping does not work, the whole thing switches to the second interface, but the route remains default. How to fix it? There is an opinion that it is necessary to either increase the metric or delete the route, but I won’t pull it myself, can you help?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Gleb Bogdanov, 2014-06-27
@bogdanov_go

The easiest way to switch from the main Internet provider to the reserve and back when restoring the first one:

#!/bin/sh
if ping -c 15 "ip на первом интерфейсе" | grep "100.0% packet loss"
then
route change default "ip шлюза второго интерфейса"
else
route change default "ip шлюза первого интерфейса"
fi

P
pumamd, 2014-07-07
@pumamd

I would recommend switching from ifconfig, route to iproute2 utilities
In case the eth0 link is down:

ip route del default dev eth0
ip route add default via <IP-второго шлюза> dev eth1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question