1

Good time-of-the-day everybody!
I have such problem: I need to configure access to subnet via DHCP configured non-permanent network using NetworkManager on my laptop with Debian Buster. So I can add route in connection's IPv4 Settings -> Routes. I don't know gateway and its changed any connection, so I can't add any in field Gateway. But if I keep Gateway empty, connection created to device, without gateway and with link scope

хх.хх.0.0/16 dev wwp0s20f0u5u6i3 proto static scope link metric 1

What I need to paste to Gateway field to get route with connection's DHCP assigned gateway? Like this

хх.хх.0.0/16 via yy.yy.yy.yy dev wwp0s20f0u5u6i3

Tanks!

2 Answers 2

0

OpenVPN supports special gateways, like "net_gateway", which OpenVPN substitutes dynamically.

NetworkManager does not support that. It's a missing feature.

If the connection is a point-to-point link, like a VPN, then 0.0.0.0 might work for you (the gateway wouldn't really matter).

As a workaround you could place a dispatcher script to /etc/NetworkManager/dispatcher.d, see man NetworkManager amd the "pre-up" event. The script could add the route via ip route add.

In general, if you want to configure manual routes, you indeed know the parameters of the network you connect to. You would hence have different connection profiles in NetworkManager, and activate the right one depending on where you are.

0

Tanks to Thaller; you made us discovering treasure of NetworkManager. Without your suggestion I probably never take the time to READ the man, and this workaroung. So now to avoid wasting your time with obsolete informartion in this man, be aware that envireonment variable IP4_GATEWAY , proposed in the man is NEVER valuated, what ever you do in /etc/NetworkManager/dispatcher.d/ subdirectories. Fortunately when these script are running, for example at pre-up mode, the interface is already up, and the gateway provided by DHCP server is already there too. So a concrete solution is:

1] put your extra route in let's say: /etc/NetworkManager/DHCP_additional_routes example:

8.8.4.4 32  enp6s18
8.8.8.8 32  enp6s19  

(target mask interface)

2] in the a script let's say manage_additional_route under /etc/NetworkManager/dispatcher.d/pre-up.d/ You will be able to get a value for IP4_GATEWAY:

#!/bin/bash 
INTERFACE="$1"
ACTION="$2"
DEFROUTE=`ip route show | grep $INTERFACE | grep default`
IP4_GATEWAY=`echo $DEFROUTE | awk '{print $3}'`
grep "$INTERFACE" /etc/NetworkManager/DHCP_additional_routes| while read LINE0
do
    P1=`echo $LINE0| awk '{print $1}'`
    P2=`echo $LINE0| awk '{print $2}'`
    P3=`echo $LINE0| awk '{print $3}'`
    ip route add $P1/$P2 via $IP4_GATEWAY
done

I needed that to manage failover between 2 wan interfaces getting address from DHCP server. With the method "canary" : you test a ping on the target described in DHCP_additionnal_route, which can be routed exclusively by the interface given above, so you know if an interface is up or down

You must log in to answer this question.

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