Hello everyone, I have I guess a bit tricky situation on hand
I have 4 devices (2 computers, 2 cellphones) on my home network, they’re all connected on the same LAN, and additionally, all are also running Tailscale (rather out of the box configuration except specific IPv4 addresses given by me)
When going out of home, I normally take up to 2 devices with me and connect to the ones at home through the Tailscale IP
Usually I do this by typing the IP address manually on either scenario, if I’m home I connect typing the LAN IP Addresses for the devices, otherwise I manually type the Tailscale IP addresses
I would like to now optimize this process using Host Names; I would like to type in say, SSH pc1 and that connect via LAN IP if available, and otherwise fallback to Tailscale IP if not
Result being I can just type the one singular host name, and connect successfully regardless if I’m home or not, also using the best possible connection (LAN preferred over Tailscale)
I am aware Tailscale has a feature that it does this out of the box using the Tailscale IP on the same LAN, but this doesn’t seem to work on all devices (the phones) and additionally that generates some noticeable overhead given their age too
I have been reading about Avahi and thinking of using it on each device, advertising the same host name with both it’s IPs, which I am yet to try but figured I could use more input on solutions if anyone has experience with it, I’d appreciate any
Thanks for reading, and I hope you have a nice day
I do exactly this by using DNS. You’ll want DNS on your home network to report back just the internal IP addresses for each host, but not the Tailscale IP addresses (that is, if you want the hostnames to work outside of Tailscale too).
Then for Tailscale’s DNS you’d set up records for the same hostnames but return either just the Tailscale IP addresses or both. I generally do both but it’s probably better to do the former to avoid leaks outside the WireGuard tunnels (though with a subnet router that probably won’t happen anyway).
This is much like traditional split DNS where your internal network’s DNS server is probably going to give internal IP addresses for a local web server’s hostname but a public DNS server would return a publicly routable IP address.
Avahi is going to be a huge pain because it relies on multicast. It won’t work over Tailscale (or traditional VPN tunnels other than an OpenVPN TAP interface) without lots of fighting.
I’m a bit conflicted with your answer, I suppose for a DNS server my best go-to should be my router, but I don’t have access to it, next option would be DNS servers on each device and make localhost the primary server, then my router the secondary? Assuming that’s the case I think that would break when I take a device off the local network as outside it would still assume things work like in the LAN. I could see it working if I had access to my router and primary server was DHCP provided (in LAN that would be my router with it’s DNS configured to point to my devices with hostnames, outside it wouldn’t have any and use the secondary) and secondary Tailscale’s (which supports mDNS so with the same names it would hit my device’s IPs from the tailnet) but I don’t think I can get that router access…
Unless I misunderstood something of the solution, if so can I ask for clarification?
My comment was kind of high level because I wasn’t sure how much you knew technically already.
But yeah, you would unfortunately need access to the DNS server on your router and be able to add custom records. You’d additionally need a DNS server somewhere for Tailscale clients whether that’s on a Tailscale node or just on the public internet (and configure Tailscale to use it).
I suppose a last-ditch effort would be to buy a domain and create records pointing to both the Tailscale and internal LAN IP addresses. The downside is that you’re basically making the map to your network public but at least people wouldn’t actually be able to access those internal (LAN, Tailscale) IP addresses. The benefit would be only needing to manage one set of records in one place.
I’m really rusty on my OSI model but Avahi, NETBEUI and friends won’t work over WireGuard tunnels because those are layer 2 protocols whereas WireGuard operates at layer 3 (if I remember correctly).
I think I understand why Avahi wouldn’t work with that explanation, I keep digging and now my router is not exactly inaccessible, it’s managed by my ISP instead which is annoying but I supposedly can still ask them to tweak things for me so I may have a chance
Tailscale already has DNS servers working on Tailnets (they call it mDNS, or magicDNS) which is I believe 100.100.100.100… actually, the documentation states that every tailscale-running device is a DNS server on itself too but either way that IP is private on every tailnet, remains accessible and host names are configurable on the Tailnet too
If I’m not mistaken on the functioning of DNS, I should be able to do it with that primary-router secondary-tailscale DNS setup I hypothesized and on LAN that will yield perfect connectivity, while out from home there would be no such records and it’ll fall back to Tailscale’s DNS which is already private (worst concern is just sending a request for a hostname on public network but that shouldn’t be that big of a deal)
At this point I might have this solved, but of course, more input is nice too, It’ll take some time for my ISP to work for me on this
mDNS refers to multicast DNS (.local), while similar you should not mix it up with Tailscale’s MagicDNS, which is entirely a Tailscale thing, dependent on their APIs.
mDNS also seems to be what you’re after too. For the hostname-only resolution to work, you need to have Avahi or equivalent mDNS daemon running on the hosts, and add
.local
to the search domains. Setting search domains can be done manually on each host or via DHCP network-wide.With mDNS and
.local
in the search domains, when you try e.g.http://myhost/
in the browser, the browser first triesmyhost
, then adds each search domain, e.g.myhost.local
. Since .local is reserved for mDNS, querying it results in an mDNS query in your network, and if there’s a device with a matching name, it will respond with it’s IP address.Note that if you have Tailscale and MagicDNS active, your tailnet’s domain will (or should) be the first one on the search domains list, and your DNS server is set to 100.100.100.100, which is a dummy address on which the tailscale daemon runs the internal DNS server for Tailscale, including MagicDNS.
Multicast DNS / Avahi is a little bit error prone in my experience, but when nothing goes wrong, this would give you what you’re looking for.
There are other options, like your router automatically registering DNS entries for DHCP hosts, or running a separate DNS server anf manually adding records for the hosts you need this for.