I have a linux server connected to a VPN.
At home, I use the same VPN on my laptop, while connected to the server directly through a wireless router.
To do this, I have two entries in my
192.168.1.1 myserver 10.1.1.1 myserver.vpn
This way I can choose how I connect manually by using a different hostname.
My question is: how can I connect dynamically using the same hostname? Ideally, the laptop would know which IP to use based on which network interfaces it's connected through, prioritizing a real interface over a virtual one. And if an address wasn't available, I want it to try another one!
I've attempted to set this up using dnsmasq on the laptop with multiple host records and the
localise-queries option. In my
dnsmasq.conf I have:
When I use
dig myserver +short I get:
the first time around and
the second time, and so on...
But if I change the static address of myserver to
192.168.1.2, and do
ping myserver from the laptop (192.168.1.3), I get:
PING myserver (192.168.1.1) 56(84) bytes of data. From localhost (192.168.1.3) icmp_seq=1 Destination Host Unreachable From localhost (192.168.1.3) icmp_seq=2 Destination Host Unreachable From localhost (192.168.1.3) icmp_seq=3 Destination Host Unreachable ...
So a couple of questions:
(1) why doesn't the laptop try another route, even though dnsmasq is providing one? (2) how can I prioritize routes based on which network connection is being used?
By the way, I tried using NetworkManager and customizing the DNS entries for each connection (e.g. to use my router's DNS server to resolve hostnames on the LAN, and the laptop's local dnsmasq to look for hostnames on the VPN). Well, this seemed like a good idea, but every time I activated an interface, it would override the DNS settings of the other interfaces. That's not what I wanted!
Question (3): Is there a better way of going about this?