Some Bits: Nelson's log

24 posts about dns

Death to Tailscale MagicDNS

It took several years but I finally disabled Tailscale MagicDNS. It just caused too many problems. It broke Proxmox containers. It broke private DNS on my Android phone. It broke all sorts of stuff. I don’t want tailscale to mess with DNS.

I’ve replaced it with tailscale-cloudflare-dnssync. This is a simple Python program that uses Tailscale and Cloudflare APIs to read your entire tailnet’s list of hostnames and create DNS records. There’s a zillion versions of this kind of script, including some that support other DNS services. This one works fine for me. I’ve set it up to run daily but since the Tailscape IP assignments are static, the DNS records aren’t going to change much.

I also set up my local resolver to search the subdomain I put all the tailnet hosts in. So I can use short hostnames like sfrouter instead of FQDNs like sfrouter.tailscale.example.com.

The downside of this new setup is now all my tailnet hostnames are out there in a public DNS list somewhere. They all point to private unroutable IP addresses, so there’s very little someone can do with that info. But now someone could figure out with some DNS queries that I have, say, a PiKVM and then try to attack it somehow. Then again I remember when AXFR was still a supported DNS query, and a very useful one at that! It just doesn’t seem that big a worry for me.

MagicDNS was always a kludge. Tailscale would basically try to intercept your system’s DNS resolvers and insert its own at 100.100.100.100. Its primary feature I used was to serve address records for hostname.your-tailnet.ts.net. (These aren’t real DNS records, they were only visible to you from their special nameserver). Over time it has grown a lot of other complex features, none of which I want. And it caused all sorts of problems. Good riddance.

As a bonus I think this will make it easier for me to get working SSL certificates for my tailscale names. There’s some way to do that with MagicDNS but I never figured it out.

Easy Porkbun DDNS

I’m liking Porkbun as my registar. One nice thing: they have an API and formal DDNS support. And good docs. However their recommended DNS client is some absurd persistent process which runs a web server. Give me a break! I’m using mietzen’s porkbun-ddns instead. It’s a simple Python client that you can easily run from cron. Seems to work fine. The configuration is a bit of a PITA but once it’s set up it runs with no hassle.

New registrar, DNS transfer notes

I’m working towards establishing one of my domain names as my new primary email address. As part of that, I decided to finally move all my domain names from Hover over to a new registrar. Hover is OK but not great and hasn’t modernized their platforms in the way I’d like.

I’m testing out Porkbun as my new registar. Namecheap is also in consideration. I asked on Mastodon and these two seemed the most popular. Gandi used to be more popular but got bought and their prices were jacked way up.

Porkbun has a nice documentation page on transferring DNS without downtime. The challenge is if your domain’s whois records use your old registrar (Hover) as your DNS server. The transfer takes some unknown time to go through, several days. But the moment it goes through the old registrar will probably stop serving DNS queries, so your domain stops working until the new registrar can get in there and publish new info.

Anyway, the key is to do all the transfer on Porkbun except the authorization key part. Then set up DNS records at Porkbun. Then edit the whois records on the old registrar (Hover) to point to Porkbun’s nameservers. Then finally unlock the domain and give Porkbun the authorization key to let it go through.

I neglected to do these steps in this order and by the time I went to edit the whois at Hover I got “Registry error, domain’s nameservers not updated [Object status prohibits operation] (Code 405)”. ChatGPT claims this error is actually from Verisign, presumably a lock put in place while the transfer is underway.

Fortunately the domain I’m trying this on isn’t really used so it’s no big deal if it breaks for a bit.

I pretty much immediately got email from Hover saying that a transfer was requested and that I didn’t have to do anything to allow it, just wait five days. Notably absent is any button to press to expedite the transfer faster.

Update

The transfer went through 5 days and about 6 hours later. Hover still shows I own it in their list, but Porkbun has it in their system. The whois record is updated to Porkbun. The domain registration was extended another year.

The whois still points to Hover’s DNS servers. Happily those still work, they didn’t turn off service immediately when the domain transferred. I just updated to use Porkbun instead. That change was visible immediately on whois.com’s web interface and within a few minutes in my Linux CLI whois tool. dig +trace shows the new nameservers are being queried. I’m sure something is going to end up cached for awhile, it really would be better to change the DNS servers first. But at least it wasn’t an instant disaster because I forgot to do that before the transfer.

I was able to add a TXT record to my Porkbun DNS with a 60 second TTL. It was visible immediately from a DNS query. After I deleted it the deletion was visible immediately on a host without a cache. It did expire after a few minutes on my local Linux box where I had it cached but it may have taken longer than 60 seconds, I didn’t test fully. Anyway, I’ll say Porkbun DNS works, at least for the simple case.

Porkbun’s web whois has a form for contacting a domain owner. It actually works! Here’s the message I eventually got.

First, we are very sorry to bother you but someone has managed to jump through all of the required hoops in order to send you a message. As required by ICANN, we must allow someone to send a message to domain contacts via a web form. The person contacting you has validated their email address and passed a CAPTCHA proving that they are more than likely not a robot

WSL2, DNS tunneling, and .local names

Just copying the text of a post I made to Reddit. Long story short: if you want .local domain names to work in WSL2, you may have to turn off DNS tunneling.

Query

I’ve got several Linux boxes on my LAN running avahi-daemon. I can connect to machine.local fine on most of my LAN, including my Windows desktop in a web browser or DOS shell. However, my WSL2 system cannot connect to machine.local, it seems unable to resolve mDNS at all.

I tried finding an answer and found several years’ worth of advice, some conflicting. The root cause seems to be WSL2’s complicated networking setup interfering with multicast. Unfortunately I don’t really understand WSL2’s network setup. Is there some easy way to get mDNS resolving working?

Comment I wrote with solution

Setting dnsTunneling to false makes .local names work. I had to restart the WSL2 system as well.

DNS tunneling is described here and the configuration file is described here. There’s also this bug report on GitHub.

Before the change my WSL2 had 10.255.255.254 as the nameserver in the resolv.conf, now it has 172.31.0.1. DNS tunneling is relatively new (from Windows 11 22H2) and “is aimed to improve compatibility with VPNs, and other complex networking set ups”. So maybe turning it off causes other problems. But basic DNS and Tailscale’s Magic DNS are both still working for me and now .local names work too, so I’m happy.

tailscale, Magic DNS, proxmox, and LXC

Frustrating interaction. tailscale MagicDNS breaks LXC under Proxmox. The solution is to start tailscale with --accept-dns=false on the Proxmox server. This is well documented by Tailscale but I missed it. In detail...

I have tailscale installed on the Proxmox hypervisor host, with MagicDNS enabled. If I start an LXC container then DNS doesn’t work at all in the container’s guest operating system.

The underlying issue is how tailscale does MagicDNS, how it answers DNS queries to supply its own answers for your hosts at *.*.ts.net. On Linux it does this by rewriting /etc/resolv.conf setting nameserver 100.100.100.100. The details of how it does this are complex because so many other things on a modern Linux box are also trying to overwrite that file. (Yes, systemd is involved). But it seems to work fine on the Proxmox server.

What doesn’t work is MagicDNS inside an LXC container. When you launch LXC it seems to start with a copy of whatever /etc/resolv.conf is in the Proxmox host. (Every time; if you reboot the container it gets a new copy.) So if tailscale is running it can pick up that 100.100.100.100 nameserver. Unfortunately the LXC guest operating system does not have access to that IP address (nor to any of your tailnet, it shouldn’t!) So DNS doesn’t work.

The simple fix is to turn off tailscale on the proxmox server: tailscale down. But it’s nice to have tailscale to access the server! If you run tailscale up --accept-dns=false then there’s no MagicDNS on the Proxmox server and /etc/resolv.conf is left alone. This setting seems to be sticky, it’s persisting even though I didn’t edit any config files.

Another option the docs mention is writing a /etc/.pve-ignore.resolv.conf file in the LXC container’s filesystem. That’s part of a general mechanism to have Proxmox not overwrite files in LXC guests.

underscore DNS queries

Wanted to document this learning as more than some tweets.

The amazing Julia Evans launched Mess with DNS, a little sandbox where you can register some domain names and then see what queries their DNS server of record gets. Great tool for learning.

I learned something! When I did a single A query at home on Sonic.net using their DHCP servers, Mess With DNS sees six queries all at once

That seems like an awful lot. There’s several mysteries here, but the one I focussed on was that query for _.lily6.messwithdns.com. Underscores are generally understood to not be valid in domain names, although the underlying DNS protocols do seem to allow them in some places. But why would a query for a normal subdomain also produce a query for _?

A simple way to reproduce this is
$ dig @50.0.1.1 nelson.lily6.messwithdns.com a
That’s a different Sonic resolver than I use. It only results in two queries, not six, but it still generates that underscore query.

I put the question out on Twitter and on Hacker News and got two useful replies.

First, a reply from a product manager at Cloudflare who very kindly looked in his logs for similar queries and reported.

Over the last ~5 minutes I see ~12 queries per second on average (globally) to 1.1.1.1 for _.www.google.com and ~3 QPS for _.www.cloudflare.com - which is effectively noise.

So that’s interesting. Those queries do exist but they are not very common.

As for what causes them, the Hacker News discussion came through. Several folks all pointed out this is something Bind9 does with the “QNAME optimization” option turned on. One Sonic engineer even explicitly confirmed that was the DNS server they use and the source of the queries.

So what do they mean? QNAME Minimization is a privacy thing in recursive resolvers. If you’re querying foo.bar.example.com at some point you end up asking the .com root server for information. But there’s no need for them to see the whole domain name, so you just send the minimum you need (example.com, I believe.)

That still doesn’t explain the underscore. TBH I don’t really understand it. The Bind9 code is here but there’s few comments. However I was able to find the commit that added it and the comment says

qname minimization, even in relaxed mode, can fail on some very broken domains. In relaxed mode, instead of asking for “foo.bar NS” ask for “_.foo.bar A” to either get a delegation or NXDOMAIN. It will require more queries than regular mode for proper NXDOMAINs.

So that seems to be the answer. It’s not great that this workaround for “some very broken domains” ends up doubling the name server traffic for the rest of the Internet, but here we are.

For completeness, several people pointed to RFC 2782 or RFC 8552. (It’s one of first Google search results for “underscore dns”.) That RFC is about using _ to mangle some other tokens to not collide with domain names; they are used when querying things like _tcp or _udp. I’m pretty sure that’s not what’s going on here.

I’m grateful to have gotten replies from someone at CloudFlare, my ISP, and the author of the QNAME Minimization RFC. It’s nice to be able to get an answer from actual experts.

Android DNS queries on an idle phone

My phone is a Pixel 3 running the latest Android. It mostly sits idle at home on wifi, I use it maybe 30 minutes to an hour a day at most. A couple of days ago I set it up on NextDNS, an ad blocking DNS provider. One nice thing about NextDNS is it gives you stats about the DNS queries. Here’s some data after about 45 hours.

It’s a lot of total queries! 6000, or about 130 an hour. It gets much quieter at night; the lull in the graph below is between 9pm and 7am. My phone has DND enabled from 10pm to 6am, I suspect that has more to do with the pattern than my actual usage.

31% of the queries were blocked as ads or trackers. Google is by far the biggest surveillance on my phone: Analytics, Ads, and Doubleclick. Urban Airship is second, then Crashlytics. I don’t know if that’s because I’m running Android, own a Google-built phone, or if I just mostly use Google services. Probably some of each, also Google’s monopoly power.

Outside ads the biggest source of DNS queries is still Google; Federated ML is top, Google Play (for the store?), and www itself. The other players are Yelp (geolocated to Japan), something called Rainbow API from the Washington Post (Germany), and Syncthing (India!). No idea why the geographic scattering. These are all services I use regularly, although it’d be nice if they weren’t quite so spammy with DNS. 5 queries an hour for something I don’t directly use seems strange. then again these DNS entries are all set up to expire in 1-5 minutes. And hey, DNS is cheap.

All in all not a lot of huge insights other than the magnitude of DNS traffic. But it’s an interesting view into something I’ve never looked at before.

BTW I like NextDNS. It’s more or less the same as AdGuard’s DNS. But it feels more like a real product. You can also customize exactly what’s blocked with some granularity, there’s a lot of OpenDNS-like features too for safe browsing, parental controls, etc. Blocking Parked Domains is a particularly provocative feature. The free tier gives you 300,000 queries / month which I think is enough for two phones at my current activity level. Unlimited usage for a personal account is only $20/year.

Updating nameservers in Ubuntu 19, Pi Hole edition

For some reason, every time I reboot my Ubuntu 19 box had /etc/resolv.conf configured to point the name server at 127.0.0.1. There’s no nameserver running there, so it fails. I want it set to 192.168.0.1. Where is this coming from? Is it related to having had Pi Hole installed at one time? systemd? What?

tl;dr: there’s like 5 things in an Ubuntu 19 system that might be modifying your name server, and tracking it down is really terrible.

In the old days you edited /etc/resolv.conf and were done. (libc knows to read this file and use it when resolving names. Crazy, huh?) That works transiently but is undone if you reboot. If you look at the file there’s a dire notice

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.

nameserver 127.0.0.1

OK, so systemd is a DNS resolver too now? Awesome. Don’t let the 127.0.0.53 surprise you; that’s basically another name for 127.0.0.1, localhost. Only they’re being sorta clever. But my system is broken; it’s not set to .53, it’s set to .1.

Then you go down the rabbit hole. That command systemd-resolve --status is giving you systemd’s idea of how to resolv names. That in turn seems to be configured by files in /etc/netplan, something you may have created if you configured static networking. Changing those will (presumably) alter the behavior of systemd’s DNS server.

But my problem is my /etc/resolv.conf was being regenerated at boot time to point to 127.0.0.1, not 127.0.0.53. systemd’s resolver is never involved. How to fix that? Second rabbit hole; there’s a system called resolvconf that might be overwriting it with information in /etc/resolvconf. Only what’s on my system isn’t the real (old) resolvconf, it’s actually systemd’s resolvectl running in a resolvconf-compatibility mode. I fiddled with it for awhile and I still don’t understand how this stuff works, but it seems to not be writing this entry.

I finally did a grep and found even though I’d uninstalled Pi Hole, it left behind a /etc/init.d/pihole-FTL script. Which is running resolvconf at boot time to re-set the nameserver to 127.0.0.1. This script shouldn’t still be on my system, and removing it should stop the clobbering. So I removed and rebooted.

Hah, joke’s on me! Every reboot, the 127.0.0.1 entry gets rewritten. Where is it coming from? I found it in /run/resolvconf/interface/enp3s0.dhcp. I’m not using DHCP, I have a static IP address. But that encouraged me to pay attention to /etc/dhcpcd.conf which, yes, is the actual source of the text overriding resolv.conf. I changed it from “static domain_name_servers=127.0.0.1” to 192.168.0.1 and name service works on reboot! Who knows why this matters.. dhcpcd is still running; it appears to be used to configure interfaces with static addresses even if DHCP isn’t involved.

But systemd still has one joke left on me. Now when I cat /etc/resolv.conf there are two name servers.

nameserver 192.168.0.1
nameserver 127.0.0.53

I have no idea why systemd decided to inject its .53 in there. It didn’t when the DHCP wrote 127.0.0.1 in there, but change that number to 192.168.0.1 and now systemd’s all in a hurry to put itself there. It may be coming from files I’m afraid to edit in /run. Anyway now half the queries go directly to my name server, half are looped through systemd first.

Fortunately the systemd loop seems to be working. I can’t dig @127.0.0.53 but no ordinary query ever hangs in a way consistent with a broken nameserver. systemd-resolve --status suggests that resolver is configured usefully (forwarding all requests to 192.168.0.1). So I’m just gonna leave it alone since it’s working, even if it’s not what I want.

The problem with systemd isn’t just that it’s a giant beast that tries to do everything. It’s that it’s also magic and poorly documented.

Update (DHCP edition)

I went through this ordeal again on another Ubuntu 18.10 box that I’d installed PiHole on. It took me forever to figure out where the bogus entry in /etc/resolv.conf was coming from. I finally found it in /etc/dhcpcd.conf

Ubuntu’s network configuration is a serious dog’s breakfast of competing files overwriting each other. AFAICT, any of these subsystems might be responsible for configuring /etc/resolv.conf:

I have not found this documented clearly anywhere. The way things overwrite config files quietly is really awful.

Pi-Hole problem with dnsmasqd, LXD

This is for the search engines. Installing Pi-Hole on an Ubuntu 18.10 system it wouldn’t start the DNS server. Looking at “service pi-hole status” I see this error:

May 31 15:00:05 gvl pihole-FTL[30005]: dnsmasq: cannot access /etc/dnsmasq.d/lxd: No such file or directory

For once Googling the error didn’t get me anywhere useful. I finally looked and found this symlink:

# ll /etc/dnsmasq.d/lxd
lrwxrwxrwx 1 root root 28 Apr 26 2018 lxd -> /etc/dnsmasq.d-available/lxd

However the entire directory /etc/dnsmasq.d-available/ doesn’t exist. So it’s a dangling symlink. Apparently dnsmasq.d refuses to start if it finds one of those, doesn’t just skip it. Removing that dangling symlink fixed the problem and now Pi-Hole starts.

No idea where the file came in. I tinkered with LXD on this machine in the past, maybe that’s a remnant of something I installed and then removed.

Ubuntu, DNS, and sudo

I’m confused about something in Ubuntu 18.10. Why does sudo require DNS to be working? And is that appropriate in the face of Ubuntu’s default network configuration?

First, the fun part. If DNS is broken on an Ubuntu host then you can’t sudo.

$ sudo bash
sudo: unable to resolve host gvl: Resource temporarily unavailable
[sudo] password for nelson:
hostname: Temporary failure in name resolution

I’ve seen discussions of this problem going back to 2006 and vaguely recall it being even older than that. It’s not clear if it’s even a bug; /etc/sudoers does have network-based restrictions. But it sure makes it hard to fix a system with a broken network if you can’t become room in the first place.

The usual advice / workaround for this problem is to add your system’s hostname to /etc/hosts. That way you can always resolve the name via the file even if networking / DNS is down. The dumb advice suggests adding it as an alias for 127.0.0.1, the smarter ones have you using the real IP address. However Ubuntu 18.10 doesn’t seem to have any way of adding that hostname for you, neither at install time nor at boot time via netplan. I’ve added this manually, is it a bad idea? I do worry it could get out of sync if I renumber my network some day.

Confounding this problem is DNS is kind of complicated on Ubuntu 18.10. My 18.10 system has an /etc/resolv.conf that lists “nameserver 127.0.0.53”. (Which is sort of equivalent to localhost, 127.0.0.1, but a different number.) systemd has grabbed this port and is providing DNS service via systemd-resolved. That’s a name service daemon that mostly just forwards requests to an upstream name server. The configuration for that is confusing because a lot of files in /etc get rewritten at boot time by Netplan, but in my case it boils down to “we get our DNS servers from DHCP”. All well and good and I think systemd-resolved may even be answering the host’s own name internally, not forwarding it to the DNS server.

The problem is I stopped systemd-resolved via systemctl (while I was experimenting with Pi-Hole DNS). Then I had no way to sudo to start it again. Oops.


DNS ad blocking, Pi-Hole

I’m fooling around with Pi-Hole, the DNS server that also blocks ads by refusing to answer DNS requests for ad servers on various black lists. It was originally designed to run on a standalone Raspberry Pi server but it runs fine on any Ubuntu box. (Beware, the install script is a bit aggressive and will reconfigure your network if you let it.) Unforunately running Pi-Hole on a hacker-friendly router is not easy.

Anyway, Pi-Hole seems to work OK for me. I’m using it as the DNS server for my Windows desktop and for the Linux box itself. The funny thing is I have enough ad blockers installed in clients on Windows (uBlock Origin, Privacy Badger) that very few ad DNS requests get through to Pi-Hole.

The real reason I’m interested in using this is for various devices that can’t easily block ads. Like my iPad; Apple added some support for ad blockers but it’s not very good. Or my Roku, or my PS4, or... I like the idea my whole home network is a black hole for advertising.

The huge drawback here is that DNS is really the wrong place to be injecting policy like this in a network. DNS should be a simple caching service that does its one thing very directly. I’ve never been a fan of policy DNS systems like OpenDNS because they add so much complication. I’m looking with dread at the first thing in my house that doesn’t work in a confusing way because it can’t connect to something that Pi-Hole thinks is an ad server. I’ll never figure it out.

The other drawback is redundancy; what happens if my Pi-Hole server goes down? You can configure secondary DNS for most operating systems as a backup (including via DHCP) but it turns out most systems treat that second server as an alternative server, not just a backup, so it’ll get half the requests. I guess I could run two Pi-Hole servers? Lol, no.

Pi-Hole as a software package also feels a bit like overkill. At it’s core is pihole-FTL, a daemon based on dnsmasq plus extra code. dnsmasq is fine but that extra code implements a bunch of weird stuff. Maintaining the blocklists, OK. Logging every DNS query to a world readable file? Not a great idea (albeit configurable). There’s also a fancy web interface implemented in PHP which is nice, but more surface area. It also listens on localhost:4711 for its own API. It’s just doing a lot of things on top of being a DNS server. I think it’s reasonable, but it is a lot.

(To be fair, Pi-Hole is very well documented. Also the default install seems to be smart, like running as its own user, etc. Whoever built this distribution made an effort to do a good job. It also seems to autoupdate its own binaries, which sure offers an exciting new attack vector to my Linux box.)

One limitation of Pi-Hole is it only works if you can configure the DNS servers of your device. A lot of Internet-of-Crap devices apparently just hardcode a DNS server; see Paul Vixie’s recent rant against Google Chromecast. One solution is to capture and redirect DNS requests back inside. Yes, you can act like your own hostile wifi network! I’m anxious about the complexity this introduces.

I imagine this is only going to get worse with DNS-over-TLS or DNS-over-HTTPS. The Pi-Hole can make its own upstream DNS requests via Cloudflare’s DNS-over-HTTPS, but I’m not sure there’s a way to have the Pi-Hole work as a secured DNS server itself. Not an issue now, there are precious few secure DNS clients, but maybe in a year or so.

Another drawback of Pi-Hole is there’s no good way to temporarily disable it. I mean you can via the admin interface, but it disables ad blocking for everyone. Also it requires a separate web page. I like the way uBlock has a simple UI in the browser for me to temporarily turn it off.

Ubiquiti EdgeMAX / EdgeOS local DNS

Ubiquiti makes nice routers with good firmware. But one missing feature; it doesn’t generate local hostnames in DNS for clients on DHCP. Ie, my Linux server registers itself with the name “gvl”. But I can’t then “ssh gvl” on my network because gvl isn’t a valid DNS name, not even in the Ubiquiti.

The right solution for this is to enable dnsmasq to be your DHCP server. dnsmasq is already running as a DNS server in the router; all this does is let it also be the DHCP server. As a side effect you now have nice DNS service. The downside here is it requires some slight tomfoolery to enable and then you end up with a less-than-standard router. See the discussion here.

Another possible solution is to enable the “hostfile-update” option. This tells the stock DHCP server to write entries in /etc/hosts. There’s some possible bugs with this.

The hacky solution for this is to leave DHCP alone and just create a static IP address and DNS name for your host. I’m too lazy to post screenshots, but basically...

  1. Boot your DHCP client that you want to give a DNS name to. Let it take an automatic address.
  2. In the web GUI for the router, go to Services / DHCP Server. Click the little “Actions” dropdown button and select “View Leases”.
  3. Find your DHCP client and click “Map Static IP”. This computer (well, MAC address) will now get a static IP every time it boots.
  4. Go to Config Tree. Open system / static-host-mapping / host-name.
  5. Click “Add”. Type a hostname. Click update list.
  6. In the config tree look under host-name for your new name. Click it, then under “inet” add a field which is the IP address you set up in step 3.
  7. Click “Preview” to verify the config is right. It should be something like this. If it looks right, Apply it.
    set system static-host-mapping host-name gvl inet 192.168.3.75
  8. Test DNS on another system. dig @192.168.0.1 gvl any

Steps 4-8 can also be done via the command line configurator, which is probably less clumsy than the config-tree GUI.

Now that I’ve typed all this out I think perhaps switching to dnsmasq for DHCP is the better solution. But this works as a one-off.

Ubiquiti EdgeMAX EdgeOS router notes

I’m setting up a new Ubiquiti router, an EdgeRouter X SFP using firmware v1.9.7+hotfix.4. Some notes on doing this:

Out of the box the router only works on ethernet port 0 (eth0). It does not run DHCP. You have to manually configure a computer to talk to it on 192.168.1.1.

The router will redirect you to HTTPS when you connect. However they of course don’t have an SSL certificate for 192.168.1.1 so your browser will refuse to connect. You can override this in Chrome and Firefox by looking for “Advanced” mode on the error screen.

The first thing to do with a new Ubiquiti router is upgrade the firmware. The stock firmware is old and missing important features. (My memory is upgrading UniFi access points is also necessary, the shipping version had a crippling bug.)

Once you flash it the first thing to do is run the “Basic Setup” Wizard. (Note, this is not available in the shipping firmware.) This will set the router up to do What You Expect from a consumer router; NAT routing for eth0 (the WAN port) and DHCP for the rest. For a simple home network that is probably all you need to do.

1.9.7 and other versions have a bug where if you manually configure some static IP addresses along with DHCP, then dhcpd won’t start when you reboot the router. The fix for this is to remove all static entries. I was able to add one static entry later via the DHCP control panel and rebooting still works. Not sure if I can manually add an entry or not. This is all probably a bug in vyatta, their GUI config system.

DNS is not enabled for DHCP entries or static hosts. That’s a thing the dnsmasq used by many routers does for you. I can’t figure out how hard this would be to enable. The obvious wizard reportedly only adds your entries to /etc/hosts on the router itself which is not propagated by its DNS server. I didn’t try very hard.

UPnP is not enabled by default. You can add it via a feature wizard; internal is “switch0” and external is “eth0” (or whatever your WAN port is).

For my own notes, a network setup idiosyncratic to me, I added a static interface route to 192.168.1.0/24 going out eth0. Hoping to reach my invisible wireless ethernet bridge boxes on 192.168.1.110 and .111. No luck, but I think that may be because they’re configured to think the network is 192.168.0.0/23 and so can’t talk to my 192.168.3.* addresses. Oops.

 

Ubuntu name lookup: DNS vs NSS

Usually when I want to look up a domain name, I use the “dig” or “host” command. This issues a live DNS request to the configured DNS servers and you get a response from DNS. Sometimes I use “whois” on the domain first to find the domain authority, then do a “dig @server name” to find the actual live authoritative response, bypassing whatever cache my usual resolver (Google DNS) has.

But client programs on Ubuntu don’t issue DNS queries directly. They use NSS, the Name Service Switch, as configured in /etc/nsswitch.com. (In the long long ago a similar system was named YP, for Yellow Page). NSS often ends up using DNS to resolve a hostname. But it also uses local files like /etc/hosts. I’ve always had some fear it did its own caching too, although I don’t think my system does. There’s a daemon called nscd that would do caching, but I don’t have it installed.

Anyway, ordinary programs like “ssh” or “ping” don’t use DNS directly, they use NSS to look up IP addresses. So how do you query what NSS would do? The getent program.

$ getent ahosts google.com
216.58.194.142 STREAM google.com
216.58.194.142 DGRAM
216.58.194.142 RAW
2607:f8b0:4000:80d::200e STREAM
2607:f8b0:4000:80d::200e DGRAM
2607:f8b0:4000:80d::200e RAW

That’s returning a lot of data! “getent hosts google.com” returns a single address, which is generally what you mean. But for Google that gives you an IPv6 address. The “ahosts” command prints all possible matches, which is useful for debugging.

I’m digging into all this because of a frustrating problem with a freedns dynamic DNS name I use for my home machine. Every six months they decide I’m inactive and change the address to some domain parking page. In theory they email me a warning but it never gets through. So it breaks scripts I have that use the name to access to my home network. And I dutifully log in an re-enable my account, but it takes awhile for the changes to propagate.

After I re-enabled my account, “host” and “dig” would show the right address but “ping” or “ssh” would use the wrong address. Turns out if a domain is disabled freedns sets its A records to both 127.0.0.1 and 87.98.255.18, their parking web server. So that’s confusing. On top of that they set a TTL for one hour, which is kind of awful for something you’re trying to update. But I think my real problem was that one Google name server had cached the old bad address but another had cached the good new address, so queries were giving me random ones.

I’m going to just add a manual entry to /etc/hosts for now until that hour period is up.

DNS ANY requests are deprecated?

Saw something new in DNS recently

$ dig reddit.com any
reddit.com.    		3788   	IN     	HINFO  	"Please stop asking for ANY" "See draft-ietf-dnsop-refuse-any"

Huh. Turns out there’s an effort afoot to refuse ANY requests. CloudFlare’s post on their reasoning is instructive. Long story short ANY was mostly only used for debugging, not in real applications. But it’s also expensive to serve and easy to abuse, particularly in DNS amplification attacks. So out it goes.

Too bad, but I see the dismal logic of it. Chalk it up along with AXFR DNS queries and NTP’s monlist command for “why we can’t have nice things that use UDP”.

freedns annoyance

I’ve been using freedns.afraid.org for years for dynamic DNS, to access my home machines on dynamic IP addresses. Nice little service, valuable but not quite valuable enough to be paying money for.

Or so I thought. They have a thing where my domain name gets marked “dormant” and they change the DNS records to point to a static advertising site. I have to log in again to say “no I’m really using this still”, then wait for the one hour TTL expiration for things to work again. Ugh. Shades of DynDNS, the slow decline from being a useful free service to being crap.

I get it, they want to make money on me, OK. But their business goals are so modest it seems odd to inconvenience 2,500,000 free users in hopes of signing up 1000. Verification is useful; maybe they need to somehow clear out old unused names. Just wish there were some better way than “we broke your name good luck!”. Like a reminder email or something. The news page from 4 years ago says he’s working on a graceful notification. Guess that didn’t work out. (They seem to have been sending emails at one time but I’ve never seen one.)

The other DNS host I use is Hover, as part of their domain registry. They still don’t support any dynamic IP option.

DNS glue records

Had a bit of DNS I didn’t understand today. The whois records for google.com say the name server is ns1.google.com. So how do you look up the address for ns1.google.com? That’s a circular dependency!

Turns out the answer is glue records; there’s a good explanation in the first two answers on Stack Exchange, or enjoy this comic strip. Long story short, the same TLD server that tells you that the name server for google.com is ns1.google.com also provides an “additional” non-authoritative A record for ns1.google.com. That short-circuits the circular dependency. You can see this reply yourself with dig +additional. Here’s a (heavily shortened) transcript where I only show the lines along the actual resolution chain:

$ dig +trace +additional google.com SOA

.			13529	IN	NS	g.root-servers.net.
;; Received 397 bytes from 192.168.0.1#53(192.168.0.1) in 31 ms

com.			172800	IN	NS	k.gtld-servers.net.
h.gtld-servers.net.	172800	IN	A	192.54.112.30
;; Received 734 bytes from 192.112.36.4#53(g.root-servers.net) in 279 ms

google.com.		172800	IN	NS	ns4.google.com.
ns4.google.com.		172800	IN	A	216.239.38.10
;; Received 660 bytes from 192.54.112.30#53(h.gtld-servers.net) in 361 ms

google.com.		60	IN	SOA	ns3.google.com. dns-admin.google.com. 117627770 900 900 1800 60
;; Received 210 bytes from 216.239.38.10#53(ns4.google.com) in 36 ms

The key thing there is the third segment. My computer asked h.gtld-servers.net who the name server for google.com was, and it gave me an NS record naming ns4.google.com. But then it also volunteered a non-authoritative A record for that name, 216.239.38.10. That’s the “additional” response that serves the glue record.

The other question is how glue records are administered; who told gtld-servers.net the address for ns4.google.com? How do we keep that IP address updated? I’m not sure. My registrar Hover just lets you fill in a glue record but doesn’t explain how that gets sent to the TLD servers. Gandi’s docs have a good explanation too. My guess is it’s part of the protocol that registrars use to communicate with the companies that maintain the TLDs. You don’t just give them NS records for each domain, but you can give them an A record too. I wonder if they auto-update? I’m guessing not.

Glue records are old: they are explained in RFC 1033, complete with an example at SRI.com. This DNS book notes that glue records can also be an optimization; it’s basically providing the answer to the next question the resolver is about to ask. At the cost of being non-authoritative.

(Reading this whole chain I realize I’m still a bit confused about how DNS works. My computer asks my name server 192.168.0.1 who the name server is for “.”, the root, and is told g.root-servers.net. Note it gets no additional A record. But then my computer already knows that g.root-servers.net is 192.112.36.4, how did it know that? Maybe a cache? Then it asks that root server for the name server for .com and is told k.gtld-servers.net, along with an additional A record. From there it can ask about Google.)

Hat Tip to Andy Fowler for giving me the magic keyword “glue records”.

CNAMEs at a DNS root

It’s common wisdom that you can’t use a CNAME at the root of your domain. http://www.example.com can be a CNAME pointing to something, but example.com can’t. That makes hosting websites on naked domains awkward. Only confusingly you actually can do this, it’s just a bad idea. And some DNS services make it look like you’re doing it in a good way, but really they’re faking it. It’s all pretty confusing but I think I understand what’s going on in detail. This post was motivated by this Hacker News thread.

A reading from the holy text, RFC 1034

A CNAME RR identifies its owner name as an alias, and specifies the corresponding canonical name in the RDATA section of the RR. If a CNAME RR is present at a node, no other data should be present; this ensures that the data for a canonical name and its aliases cannot be different. This rule also insures that a cached CNAME can be used without checking with an authoritative server for other RR types.

So if you make example.com a CNAME, you can’t put any other DNS records on it. AFAIK you can actually do this and it will work as well as a CNAME will. The problem is you often want other DNS entries at the apex domain. You want an MX entry so you can redirect mail at example.com. You want a TXT entry to verify you own the domain name to various services. You might want special funky records for DNSSEC or other stuff. It really doesn’t work to make your apex domain an alias for some other domain.

Confusingly, a lot of the big DNS providers do let you set up a CNAME at the apex domain. But behind the scenes they aren’t really serving it as a CNAME; it’s more of a synthetic alias implemented by their DNS server. Typically it looks up the destination host address and quickly substitutes that IP in with an A record for your apex domain. That breaks the end-to-end principle of the DNS lookups, which causes problems for geographic load balancing, fast cache expiry, and probably DNSSEC. But it’s not a terrible solution.

Here’s a list of some of the DNS vendors’ aliasing technology

Long story short, if you want to serve a website from an apex domain it requires compromises and/or protocol fiddling.

Looking at all this I wonder if the world would be well served with a special DNS entry just for web servers. It’s weird to put something application specific in DNS, but there’s a strong precedent in MX entries, for mail delivery. Probably a bad idea to extend that to the web, but maybe it’d all some useful tricks?

 

DNSSEC examination

I was curious what was up with DNSSEC these days. A little bit of a dive on deployment and the way it all works in practice.

Bottom line: use a DNSSEC-aware nameserver like Google Public DNS and you will be protected from DNS records that were signed but tampered with. However very few DNS names are signed.

You can see quick DNSSEC tests in a browser. This page displays a DNSSEC Secured!” if you are secure. This site should fail to load entirely (name won’t resolve) in a secured system.

Deployment

My main question is how widely DNSSEC is deployed. This little name-and-shame site gives a pretty depressing answer, the top 25 sites according to Alexa all don’t support it. Particularly curious why Google doesn’t publish DNSSEC records. They’re not dumb or lazy, they take security very seriously, I imagine they think it isn’t important or useful for some good reason.

Verisign’s DNS Scoreboard says some 625,000 domains are DNSSEC secured. That’s like 0.4%, although it is growing.

percent-trace.png

 

Example DNSSEC records

The Verisign Labs DNSSEC debugger is the best web tool I’ve seen for examining DNSSEC records. Note the little “more/less” buttons in the display, if you click “more” enough you get to see the full response like dig gives you. You can also use dig to check things with “dig +dnssec”, then look for the extra records and the “AD” flag in the response.

Here are some test domains and their properties. Note I wrote this in Dec 2015, things may change afterwards.

  • google.com: no DNSSEC on the domain.
  • ietf.org: working DNSSEC, a simple signed domain.
  • www.ietf.org: working DNSSEC that’s a CNAME to CloudFlare, which also has DNSSEC (since last month).
  • www.paypal.com: working DNSSEC at PayPal, but www is a CNAME to Akamai, which does not have DNSSEC enabled.
  • dnssec-failed.org: a deliberately broken DNSSEC record. Most tools and nameservers I use won’t even give you any data from this record, presumably because it’s broken. I had to view the web page via archive.org, which apparently isn’t verifying DNSSEC. Neither is Googlebot unless they special-cased it.
  • rhybar.cz: another deliberately broken DNSSEC record.

Screen Shot 2015-12-20 at 10.13.32 AM.png

DNS server behavior

How do various public DNS servers handle DNSSEC records?

  • Google: supports DNSSEC, doesn’t return records for broken DNSSEC.
    dig @8.8.8.8 dnssec-failed.org +dnssec
  • UltraDNS: supports DNSSEC, doesn’t return records for broken DNSSEC.
    dig @156.154.70.1 dnssec-failed.org +dnssec
  • OpenDNS: does not support DNSSEC at all. Will return records even if DNSSEC is bad.
    dig @208.67.222.222 dnssec-failed.org +dnssec
  • Verizon / Level3: does not support DNSSEC at all, returns bad records. (The list I’m working with says this service is “DNSSEC aware”, but that’s not the same as “validating” apparently.)
    dig @4.2.2.1 dnssec-failed.org +dnssec

Bottom line it looks like there’s two types of servers. Those that do support DNSSEC and won’t return any data if a declared DNSSEC record is broken, and those that are ignorant of DNSSEC entirely. That’s to be expected.

I’ve long been a skeptic of OpenDNS, and their lack of DNSSEC support is another reason to not like them. Back in 2010 they proudly announced they were going to back DNSCurve instead. No one else has supported it since then, so I assume it’s basically a dead end. Their arguments for DNSCurve was that no one was using DNSSEC and that DNSSEC’s choice of crypto algorithms was weak. Adoption is still a problem for DNSSEC, but it supports many different crypto algorithms now so I assume that’s less of a problem.

I’d like to note that my OpenWRT DNS server seems to not pass on the AD flags. I’ve got it configured to use Google DNS upstream, so I get the benefit of the protection since Google simply won’t return records for broken domains, but clients won’t get to see if the records are properly signed or not. I think this is fixable, either by changing to a different DNS resolver in OpenWRT or maybe just telling dnsmasq to add DNSSEC.

Client support

The whole point of DNSSEC is to authenticate the DNS record all the way to the client. But I don’t think many (any?) consumer clients are validating DNSSEC themselves. Instead they are trusting their DNS server to validate for them. That violates the end-to-end principle.

On testing, I believe MacOS 10.9 does nothing with DNSSEC. If I manually set my DNS server to 4.2.2.1 (a Verizon server that does not do DNSSEC), Chrome can load the test pages with broken DNSSEC signatures. I suspect MacOS is just assuming you should trust your DNS server.

I didn’t test it, but I think stock Ubuntu does not do DNSSEC either. The glibc resolver doesn’t seem to have it. I did run across some libraries that do DNSSEC; libval, ldns, and knot. And if you’re running bind or dnsmasq you can enable DNSSEC on those.

I found one Chrome extension that verifies DNSSEC itself. Neat! But it requires a native binary plugin and that was more than I felt like dealing with.

Final thoughts

DNSSEC seems to mostly work, just adoption is slow. On the server side, the root DNS servers didn’t support it until July 2010; before then it would have been very awkward to use. For clients, Google DNS started doing DNSSEC in May 2013, so that’s been a good long while now. But end user clients aren’t doing anything themselves.

One question I didn’t explore is overhead. All those extra DNS records take memory and bandwidth to serve. And verifying signatures takes CPU time. I don’t think that’s prohibitive at the edges given all the room for caching, but the big DNS server operators may be worried.

 

OpenWRT: persistent DNS entries

One wrinkle with OpenWRT: if the router reboots, it loses the DNS entries it was giving based on DHCP leases. Even the ones you’ve configured as static DHCP leases, they don’t show up until the client host renews its DHCP lease. Forum discussion suggests this is because dnsmasq is reading from the dhcp.leases file which is stored on tmpfs, not permanent storage.

The simple workaround is just to manually add the host in /etc/hosts and restart dnsmasq. It will serve those entries to DNS clients. That means the client’s IP address is now stored in two different places, which is not ideal, but I can live with it. There’s some discussion of other solutions for this like moving the DHCP lease file to permanent storage or changing the configuration tool to manage parallel entries in both DHCP and dnsmasq. As of 15.05, none of that seems to be happening.

I’m liking OpenWRT now. It’s comforting working with a router that’s a full and proper Linux distribution. It’s also sort of overkill, but on the balance I like it.

Testing DNS without cacheing

Helping a friend figure out a DNS problem, passing on some ancient wisdom about how to test if your DNS is right. The key thing is to avoid all the caches, make direct queries to the servers of authority.

$ whois somebits.com

Ask the Internet name authority about the domain somebits.com. Lots of crap is returned there, what you care about is the name servers.

$ whois somebits.com | grep 'Name Server'

Name Server: NS1.HOVER.COM
Name Server: NS2.HOVER.COM
Name Server: NS3.HOVER.COM

So now we know that there are three authoritative DNS servers for the domain. Let’s ask one of them for information (and strip out comments, lines starting with semicolon)

$ dig @NS1.HOVER.COM somebits.com any | grep -v '^;'

somebits.com. 900 IN NS ns1.hover.com.
somebits.com. 900 IN A 107.150.51.74
somebits.com. 900 IN SOA ns1.hover.com. dnsmaster.hover.com. 1394118405 10800 3600 604800 900
somebits.com. 900 IN NS ns2.hover.com.

ns1.hover.com. 900 IN A 216.40.47.26
ns2.hover.com. 900 IN A 64.98.148.13

The important thing here is learning the A record for somebits.com, pointing to 107.150.51.74. That’s the DNS record for my server.

If you’re debugging a DNS problem, start with this type of query. Go straight to the Name Server of authority. If those records are wrong then it’s hopeless. If they look right then something else can still have gone wrong. Particularly cached data, whether cached in DNS or else cached by client software. Google Chrome seems overaggressive about caching DNS info, for instance. Java used to be awful.

ASUS RT-AC66U bug

My fancy new ASUS RT-AC66U has pretty good firmware; it seems based on the Tomato core, even the QoS. And unfortunately the built in DNS server, the one it advertises in DHCP. It has some bug that occasionally causes it to fail to respond to any requests for awhile, I think blocking on some other connection. I just had a failure where I couldn’t resolve names for about 45 seconds and it went away the moment an active HTTP download of a 60 megabyte file completed. The network was up the whole time (downloading the file), as was the router web interface, but DNS requests failed.

I should probably stop using the router DNS. Or else install Merlin’s patches.

Ubuntu resolv.conf

In the old days setting up DNS was easy. You edited /etc/resolv.conf, put your nameservers in there, and you were done. Sadly it’s gotten more complicated as time goes on; DHCP provides nameservers, computers have multiple network interfaces, you want different DNS servers on a laptop depending on where you are.

But the resolvconf(8) system in Ubuntu is impenetrably complex to configure. I’ve found a bunch of random places where name servers are stored or written. I thought that /etc/network/interfaces is canonical. But there’s stuff in /etc/resolvconf/ too, and things cached in /run/resolvconf/, and I have no idea how to just add a name server. Various “obvious” things fail with old configs coming from some cache.

AskUbuntu has a decent answer that while it may not be correct, works. Edit /etc/resolvconf/resolv.conf.d/head (ignoring the warning about autogeneration), add your entry, then run resolvconf -u. I just tried it and it worked, even put my entries first in the list.

My real goal was to replace my ISP’s flaky DNS server with Google’s 8.8.8.8. It’s stupid in the modern era that DNS is still a sequential operation with a 5 second timeout. This Ask Ubuntu answer suggests installing a fancy caching DNS server like pdns.

Tomato (Toastman) router config

Here’s some of the config I give my Tomato (Toastman flavor) router:

Basic / Network: DHCP is 192.168.0.2 - 192.168.0.63. Lease 1440. Wireless is WPA2 Personal security, Encryption is TKIP/AES. Wifi is currently auto channel, 20MHz wide. 40MHz is an interesting 802.11n option I’ll play with later.

Advanced / DHCP/DNS: I have “Use internal DNS” checked on. Not sure if this is wise, particularly since I can’t figure out how to override what DNS servers the router uses (presumably the ISP’s advertised on DHCP?) I mostly tell my computers to use Google DNS anyway, so maybe this doesn’t matter.

Advanced / Firewall: respond to ICMP ping. Not responding to ping is just stupid; it offers no meaningful security and makes diagnostics harder.

Port Forwarding / UPnP/NAT-PMP: enable both UPnP and NAT-PMP

QoS: enable QoS, this is the best feature of all of Tomato. It makes things work well if you can estimate your bandwidth limits. Note that “Outbound” refers to upload speed, packets leaving your house and going to the Internet. That’s the slow side on a DSL line. Also I turn on prioritize ACK packets (why isn’t this on by default?!)

Administration / Admin Access: enable SSH at startup. (No remote access, of course.) Save my SSH key.

Administration / Bandwidth Monitoring: enable, save to JFFS every 24 hours. Screw it if it’s not recommended.

Administration / IP Traffic Monitoring: enable, save to JFFS every 24 hours.

Administration / JFFS: enable, format.

Some settings to do once the router is installed:

Basic / Network: is 40Mhz channels wise?

Basic / DDNS: this is very useful, I’ve been using dyndns.com for years and it works great via Tomato.

Basic / DHCP/ARP/BW: another useful option, give static IP addresses to known computers.

Advanced / Conntrack: the default Toastman timeouts for NAT tracking seem awfully short, we’ll see how that works.

Advanced / Wireless: Transmit power was only 17 mW on this router. My old WRT54GL defaulted to 42mW. These may or may not be directly comparable numbers. Some discussion on this setting is here and here, no one seems to have any idea what they’re talking about.

Update I tried changing this from 17mW to 100mW and saw no measurable difference in RSSI on my laptop, or throughput, or anything. I only tested with a laptop very near the router already enjoying -55dBm (as measured via the Mac’s Wi-Fi diagnostics). So if the setting is most useful for distance I wouldn’t notice it. I left it back at 17mW. I am a bit peeved that my 802.11n laptop can only do 10mbits/sec to an 802.11g Mac Mini, despite a theoretical 54mbits/sec connection. Update 2: getting 22mbits/sec now, after rebooting the Mac Mini. Now it’s in 802.11n mode as well. But all on a mixed mode 2.4GHz network and with 20MHz wide bands.

Port Forwarding / Basic: haven’t set this up yet. I’m discouraged that it’s displaying an error “iptables-restore: line 39 failed”

QoS: check caps for the live network and set in place

QOS / Classification: Toastman has enabled a bunch of service classes. Would be nice to check if they are reasonable.

USB and NAS / FTP server: enable on LAN only. (Geez!)

Administration / Logging: remote log to syslog, particularly DHCP traffic. Big help for narrowing down problems.

Update 2: someone named “vibe666” commented “I saw your post about your router and that you are using TKIP/AES.  drop TKIP and just use AES on it’s own as TKIP is both a) not very secure, and b) pretty much obsolete anyway, and c) likely to be slowing down your wifi speeds overall to keep (potential) backwards compatibility with stuff almost nobody has anyway. :)”