Question:
Beeline's dhcp server provides local addresses 10 …, a default route and several local routes for its servers. The default route gives only limited access to dns and some of their servers. To get the Internet, you need to raise an L2TP connection over the Ethernet. At the same time, in order to preserve the old default route and so that it does not interfere with the new one, the metric 1 is set for the first connection.
/ etc / config / network:
config interface 'wan'
option _orig_ifname 'eth1'
option _orig_bridge 'false'
option ifname 'eth1'
option proto 'dhcp'
option hostname 'dlink'
option rebind_domain 'beeline.ru'
option metric '1'
config interface 'beeline'
option proto 'l2tp'
option server 'tp.internet.beeline.ru'
The problem is that for additional routes the metric also becomes = 1, and they are interrupted by a new default route with a metric of 0.
0.0.0.0 194.186.120.19 0.0.0.0 UG 0 0 0 l2tp-beeline
0.0.0.0 10.119.49.1 0.0.0.0 UG 1 0 0 eth1
10.119.49.0 0.0.0.0 255.255.254.0 U 1 0 0 eth1
10.255.255.250 10.119.49.1 255.255.255.255 UGH 1 0 0 eth1
10.255.255.253 10.119.49.1 255.255.255.255 UGH 1 0 0 eth1
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 br-lan
194.186.120.19 0.0.0.0 255.255.255.255 UH 0 0 0 l2tp-beeline
As a result, the Beeline servers are unavailable when the Internet is up.
The question is how to assign a metric only to the first default route without touching additional 10 for the grid?
Answer:
Set the same metrics to the wan
and beeline
interfaces 1
. As a result, the default route in wan
is erased when l2tp
raised, other routes have priority over the new interface with the same metric, since they are more specific. To keep the old default route, I corrected /lib/netifd/dhcp.script
adding lines at the end of the setup_interface()
function:
setup_interface () {
proto_init_update "*" 1
proto_add_ipv4_address "$ip" "${subnet:-255.255.255.0}"
# TODO: apply $broadcast
local i j
for i in $router; do
proto_add_ipv4_route 0.0.0.0 0 "$i"
done
# CIDR STATIC ROUTES (rfc3442)
[ -n "$staticroutes" ] && set_classless_routes $staticroutes
[ -n "$msstaticroutes" ] && set_classless_routes $msstaticroutes
for i in $dns; do # здесь было for dns in $dns -
proto_add_dns_server "$i" # заменил на i, чтобы сохранить переменную
done
for domain in $domain; do
proto_add_dns_search "$domain"
done
proto_send_update "$INTERFACE"
# TODO
# [ -n "$ntpsrv" ] && change_state network "$ifc" lease_ntpsrv "$ntpsrv"
# [ -n "$timesvr" ] && change_state network "$ifc" lease_timesrv "$timesvr"
# [ -n "$hostname" ] && change_state network "$ifc" lease_hostname "$hostname"
# [ -n "$timezone" ] && change_state network "$ifc" lease_timezone "$timezone"
for i in $router ; do
ip route add default via "$i" dev eth1 proto static metric 2
for j in $dns ; do
ip route add "$j" via "$i" dev eth1 proto static metric 0
done
done
}
I immediately added direct routes for dns servers. It is important that the ip
commands proto_send_update
after proto_send_update
, since the interface has not yet been raised before it.