NetworkManager possibility to get dns, but ignore default gateway
Ubuntu 18.04, Ubuntu 20.04.
We use OpenVPN for connecting to our organisation network. I installed
sudo apt install network-manager-openvpn-gnome
After that I imported a client.ovpn file to NetworkManager. Connection works good, but I have some problem.
I need to get DNS servers form VPN via DHCP, but not the default gateway. If I don't this checkbox, the NetworkManager get DNS from VPN DHCP and also create a default gateway to network 172.27.0.0/24 (it may be different).
I see it by:
systemd-resolve --status
ip route
If I select this checkbox, then NetworkManager doesn't get both DNS and default gateway. I check configuration file and manual, but doesn't find such functionality.
Now I solve this problem by writing a script and putting it to /etc/network/if-up.d/
It automaticaly starts when tun0 is starting.
if [ "$IFACE" = "tun0" ]; then
#I think it must be a one default gateway.
# get original default gateway. Get default gateways end remove 172.27.*.* from result.
orig_default_gw=$(ip route | grep 'default' | grep -v '172.27')
# delete all default gateways
sudo ip route flush 0/0
# add original default gateway
sudo ip route add $orig_default_gw
fi
It is a workaround. Can you please create functionality to ignore default gateway and take only DNS from DHCP?