You are not logged in.
I'm currently setting up my machines to be able to connect to each other over the Yggdrasil mesh VPN, so I can remote into my server without port forwarding. Even if I were to port forward and expose my computer to the whole internet, I'd have the same issue.
So far it works great, except that I don't want all my traffic to get sent over the VPN all the time, as that would be kind of wasteful and unnecessary. I'd like to avoid using up Yggdrasil's bandwidth with my Jellyfin video streams. So, when I'm in my home, I'd like my machines to communicate over my local LAN.
So far, I've been connecting to my server by assigning it a static local ID in my router's settings, and using /etc/hosts basically to "alias" the host name to the local IP. This way, I only have to write out the server's name every time I want to establish a connection, instead of writing the local IP. This is somewhat inconvenient, because the mesh VPN creates a second IP address that you use to connect to servers over the VPN.
I could set up two hosts in /etc/hosts, one being "server-local", pointing to the local 198.162.x.x IP address, and the other being "server-remote", pointing to the VPN's IP address. However, I'm trying to find something a bit more elegant, where I just need to tell my main machine to connect to my server, and it figures out what IP address it needs to use.
Is that something that can be done more or less easily? It sounds like an issue that'd only ever come up when using a laptop, which I'm guessing weren't exactly commonplace when we designed all of our networking protocols and infrastructure.
The only path I've established is to write up two valid /etc/hosts files, something like "hosts-home" and "hosts-away", and use something like a systemd service to detect if I'm connected to my home's wifi and switch them based on that. However, I've found over the years that trying to switch system files when the computer is running is kind of a hacky approach. It has often led me to lose a bunch of hours rather than getting the behavior I actually want. Once again, I'm looking for something a bit friendlier, maybe some kind of daemon that can redirect traffic based on the current network connection?
Offline
This sounds like a classic "split brain DNS" case - but probably isn't.
The basic approach is that you set up an DNS server/proxy instance (server/router) in your home network that can "supersede" the DNS resolving of "myserver.bla" to the local home IP address. Away from home the public DNS resolves "myserver.bla" to the externally reachable IP,
But in your case you need to resolve "myserver.bla" to the Yggdrasil IP address when away - and since I don't know anything about this VPN (and which instance resolves DNS names inside it) I can't say if this approach will help you.
Offline
The basic approach is that you set up an DNS server/proxy instance (server/router) in your home network that can "supersede" the DNS resolving of "myserver.bla" to the local home IP address. Away from home the public DNS resolves "myserver.bla" to the externally reachable IP,
So basically, set up a DNS for my home network that redirects the server's Yggdrasil IP address to the server's local IP address, and then edit /etc/hosts so that "myserver" always points to the Yggdrasil IP address? That seems like it could work. I've tried connecting over to the server through Yggdrasil by simply typing the Yggdrasil IP address in firefox, and I got access to my services without issues.
If I'm not home, I don't have access to my home DNS, so "myserver" never gets redirected, and I just connect to my computer over the VPN. Given I've set up the right priority between my network interfaces.
From what I've read, it doesn't really make sense for there to be DNS inside of Yggdrasil. Your "IP" is generated using cryptography or something, and anyone that has your "IP" has enough information to allow anyone that knows it to encrypt a packet so that you can decrypt it, and figure out a path through the network that'll bring it to you.
Offline
So basically, set up a DNS for my home network that redirects the server's Yggdrasil IP address to the server's local IP address, and then edit /etc/hosts so that "myserver" always points to the Yggdrasil IP address? That seems like it could work.
AFAIK "/etc/hosts" entries supersede DNS queries - look at the "hosts" entry in "/etc/nsswitch.conf": "files" precede "dns". That shouldn't work.
I've tried connecting over to the server through Yggdrasil by simply typing the Yggdrasil IP address in firefox, and I got access to my services without issues.
Not sure why you are mentioning this.
If I'm not home, I don't have access to my home DNS, so "myserver" never gets redirected, and I just connect to my computer over the VPN. Given I've set up the right priority between my network interfaces.
I'm not sure what you mean. Where does this ominous "network priority" come from? Do you use several network interfaces?
From what I've read, it doesn't really make sense for there to be DNS inside of Yggdrasil. Your "IP" is generated using cryptography or something, and anyone that has your "IP" has enough information to allow anyone that knows it to encrypt a packet so that you can decrypt it, and figure out a path through the network that'll bring it to you.
If the DNS response "away" doesn't differ from the DNS response "at home" "split brain DNS" doesn't work.
Offline
Therk wrote:So basically, set up a DNS for my home network that redirects the server's Yggdrasil IP address to the server's local IP address, and then edit /etc/hosts so that "myserver" always points to the Yggdrasil IP address? That seems like it could work.
AFAIK "/etc/hosts" entries supersede DNS queries - look at the "hosts" entry in "/etc/nsswitch.conf": "files" precede "dns". That shouldn't work.
Yeah, I think you're right, I slept on it and remembered DNS maps domain names to IP addresses. I don't think it'll do much if you tell your computer to connect to an IP address.
Do you use several network interfaces?
Yes. My laptop has the regular loopback and wlan0 network interfaces, but whenever I'm connected to the VPN, there's a third (virtual) tun0 network interface.
From what I understand, there's a range of IPV6 addresses over which the routing tables give a better score to the tun0 interface. It then uses the data contained in the IPV6 address to encrypt the traffic, and figure out a route to the target over the VPN.
I believe domain names that point inside the yggdrasil network are registered on regular internet DNS, it's just that they resolve to IPV6 addresses inside the specific range used by the VPN. Then they get "caught" by tun0, which does its thing and routes the connection over the VPN.
I'm sorry if that doesn't make sense, I know very little about networking.
I'm thinking I could buy a domain name (let's say again myserver.bla) and point it to my server's Yggdrasil address. I could then reach it whenever I'm not home by heading to myserver.bla. I probably could set up some internal DNS for my home that routes myserver.bla to the server's local 192.168.x.x IPV4 address. Does that make any sense?
I just reread the first reply and that sounds exactly like what you described lol
Last edited by Therk (2026-08-20 18:16:06)
Offline
Though going through all that trouble sounds like a lot more work than having an extra entry in my /etc/hosts that's specifically for the server when I'm not home, and points to the IPV6 address.
Offline
From what I understand, there's a range of IPV6 addresses over which the routing tables give a better score to the tun0 interface. It then uses the data contained in the IPV6 address to encrypt the traffic, and figure out a route to the target over the VPN.
There are three scenarios that I am aware of:
- If the VPN configuration lists only a subnet/range of remote hosts ("split tunnel") the VPN adds just a route for this subnet/range to be routed through the virtual tunnel interface (According to their FAQ Yggdrasil does this with the deprecated IPv6 range "0200::/7")
- If the VPN should route all traffic through the VPN ("full tunnel") it may set a second "default gateway" entry with a routing value for higher priority (OpenVPN does this)
- In a second "full tunnel" scenario all unencrypted traffic is sent to an alternative routing table (via rule based routing) that passes that traffic though the VPN interface and sets a specific mark ("fwmark" with a specific value) on those encrypted packets. They pass the routing table again and now those marked packets are allowed to pass the "normal" routing table with the default gateway to reach the VPN target (WireGuard does this).
Offline
- If the VPN configuration lists only a subnet/range of remote hosts ("split tunnel") the VPN adds just a route for this subnet/range to be routed through the virtual tunnel interface (According to their FAQ Yggdrasil does this with the deprecated IPv6 range "0200::/7")
I'm also pretty sure that's exactly how it works. Though even after rereading the third scenario about 3 times, I only have a vague understanding.
Which kinda brings me back to my first question. Is there a way to set up a hostname so that it point to a 192.168.x.x local IP address when I'm connected to my home's wifi network, but maps to an IP in the "0200::/7" range when I'm away?
I'm only aware of setting up a systemd service that listens to wifi network connection events, and switches the /etc/hosts file based on that. But again, that feels kinda hacky, and everytime I've tried something like that over the years, it's really not entirely been reliable. Maybe there's a way to run a test each time the hostname is invoked and chose an IP address based on the result of said test?
Offline
Is there a way to set up a hostname so that it point to a 192.168.x.x local IP address when I'm connected to my home's wifi network, but maps to an IP in the "0200::/7" range when I'm away?
That would be a kind of "location aware" DNS - I've never heard about something like this.
Offline