Some Bits: Nelson's log

7 posts in October 2016

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.

Hawaiian Homelands: slippy map

I got curious about the details of the Hawaiian Homelands geography so I made a slippy map version. Patience on the first load; the basemap takes awhile. Purple overlay are the homelands (click for name), white lines are the historical Ahupuaʻa divisions. The basemap is Mapzen’s Walkabout style, a nice terrain map.

I’m feeling super ignorant looking at this data without really understanding the history or current situation of the Hawaiian Homelands. A friend recommended the book Hawaiian Blood. As a humble mapmaker I realize really what I need to do is work with an expert on Hawaiʻi, keep myself confined to journeyman geoprogramming.

But anyway I looked around, some interesting sites:

  • Waimanalo on Oʻahu. I love this shape, the terrain map shows how it tracks the ridgeline.
  • Honokawai. Google’s aerial imagery shows the hole is a reservoir. Not sure about the meandering slice out of the middle, it looks like a wooded ravine or river.
  • Waiohinu. Some individual parcels in a golf course development.
  • Airports: Hilo and Kalaeloa. It looks like the airport was dropped on top of the homeland, I have to think there’s some history there.

Production notes

I cobbled this together starting with Mapzen’s excellent one minute map tutorial. They’ve built a Leaflet extension that makes it super easy to add Mapzen’s base maps (vector rendered!) and map search. On top of that I just added a couple of custom GeoJSON layers with Leaflet-AJAX.

As before, data comes from the State of Hawaii Office of Planning. I converted it to GeoJSON like this:

ogr2ogr -f GeoJSON -t_srs crs:84 a.geojson ../ahupuaa.shp/ahupuaa.shp
python liljson.py -p 6 a.geojson ahupuaa.geojson

Hawaiian Homelands

I made a map of Hawaiian Homelands. This Reddit post about a map of American Indian Reservations and Alaska Natives inspired me; it left off anything about Hawai’i. The history of native Hawaiians and land ownership is totally different from the history of American Indians on the mainland. But the Homelands are somewhat analogous to Indian reservations in that they were land set aside by the US government for native people. I don’t believe they have any form of partial sovereignty though, and I think these land are even more sparsely populated than mainland reservations are.

Anyway, really I just wanted a nice picture; this one was the best I could find online. So I spent an hour or two with QGIS and came up with the image below (see full size). Totally unfinished draft, but this here is my secret work blog so up it goes.

pc.png

The data comes from the State of Hawaii Office of Planning which has absolutely awesome GIS data for download. Very well done site.

The green shapes are the Homelands themselves, the point of the map. I drew in major roads in orange to try to give some context to location. I wasted a lot of time trying to draw a few labels for towns but Oʻahu is so densely populated no simple rule works. I’d need to place town labels by hand for it to work right and I got lazy.

I also rendered the historical Ahupuaʻa in very light grey. That’s a fascinating division of the land from historical property rights. They seem to have been designed to give each owning aliʻi a mix of lowlands and highlands, with both farmland and some forest. I’d wondered if the Homelands followed the old ahupuaʻa boundaries but I think mostly not, except for the one large one in South Maui.

I wouldn’t mind spending more time to make this publication-quality. But I’m so ignorant of what the Hawaiian Homelands really are that I don’t feel comfortable doing any interpretive mapping. OTOH the Wikipedia page would benefit from any sort of picture, even this simple one, maybe I should look into what’s required to submit there.

Why are there 86,400 seconds in a day?

Pondering the question of why the second is defined as 1/86,400 of a day. I’d always thought it was because a second was about the length of a heartbeat, and thus measurable with the body. (Just like inches and feet and the like.) But that doesn’t really explain the exact number of 86,400 so I did some reading.

Between Wikipedia and this Scientific American article I have a basic answer.

  • Egyptians used base 12 math for some astronomy related things. Why 12? Either because you can count to 12 with your finger joints or maybe because 12 = 2*2*3. Or maybe because there’s ~12 lunar cycles in a year.
  • Egyptians divided daytime into 12 hours and nighttime into 12 hours. Note these hours were of variable length depending on the season.
  • Sumerians and Babylonians used base 60 math. Why 60? Not sure, but 60 = 2 * 2 * 3 * 5 which makes it convenient for a lot of math.
  • Greeks borrowed the Babylonian math when they did astronomy, so it was natural to divide an hour into 60 minutes and then later to divide a minute into 60 seconds.
  • The etymology of “minute” is from “partes minutae primae”; first small division of the hour. Same word as the adjective “minute”, as in tiny.
  • The etmology of “second” is from “partes minutae secundae”, the second division of the hour.
  • Some languages have a unit of time called the “third”, 1/60 of a second. Polish (tercja) and Turkish (salise).

There’s also a nice StackExchange discussion on the history of decimal time, a sensible 100,000 seconds in a day or what have you. Including this awesome French Revolution clock, my new coveted possession.

yzpyy

 

Documenting obscure bugs helps!

Had a real pleasure today; someone found a description of a League of Legends networking problem I wrote up a year ago and it gave him the clue to fix a problem he was having. (Long story short; specific actions in the game cause bursts of high network traffic, which can trigger lag or disconnects.)

I spend a lot of time writing up details of bugs and software problems. I do this partly for clarity, writing it up is a way to make sure I really understand the problem. I also do it so I can find my notes later in case I have a similar problem. And finally I put those descriptions online in case they help other people. And about once a year, they do!

 

Windows 7 update fixes

I dusted off the old Bootcamp partition to run Windows to play Civilization VI, impatient for the Mac release. Every time I do this I’m reminded how bad Windows is. This time around it was 90 minutes spent trying to install and run the game and failing. I gave up and went to bed, then fixed it in the morning.

The symptom was the installer would hang while installing the Microsoft VC 2015 redist. Cancelling the installer didn’t help. Manually killing the wuas.exe process that was hung did allow the install to complete. But then the game wouldn’t run; you’d launch it and it’d quit immediately with no error. Launching the program manually (bypassing Steam) revealed the error, “api-ms-win-crt-runtime-l1-1-0.dll is missing”.

So then begins the cargo cult debugging. Googling for answers and trying various incantations to fix the mysterious problem.

The first thing I tried was manually installing the VC redists. These installers have always sucked. The end result is it’s copying 20MB worth of shared DLLs into a system directory. Why does it take five minutes? Why does it hang entirely? Running by hand (as opposed to via the game installer) sometimes helps. It didn’t this time, it kept hanging.

So the second thing I tried was fixing that error about the crt-runtime. There’s a consensus in the cargo cult about how to fix this; run Windows Update. But Windows Update wasn’t working for me. This is the moment I confess my copy of Windows 7 isn’t registered with a valid license, I’ve been using the grace period for the very rare times I want to run Windows. My bad. So is it the lack of activation that’s causing the problem? Windows is popping up a nag when I try to run the installers. But there’s no explicit error, the installer just hangs. Trying to install it manually didn’t work either, same hanging on Windows Update stuff.

And then the scales fell from my eyes. Windows Update is broken. A fix was released in April 2015; or maybe not until July 2016. Not sure. Anyway the first step in installing that fix is to stop the Windows Update service. Once I did that the crt-runtime installer worked, copying it’s 800kb file successfully without hanging. Congratulations, l’il fella! And that was enough to fix the problem.

So let me rant and describe all the failure-by-design, from top down:

  • The game crashes on startup with no message.
  • The game installer hangs with no explanation. You can quit the install, but then it’s broken.
  • The underlying VC distributable installers hang with no explanation. Its job is to copy 20MB of files, but it can’t do this.
  • The underlying underlying CRT runtime installer is hanging with no explanation. Its job is to copy 800KB of files, but it can’t do this.
  • The root cause is Microsoft screwed up Windows Update somehow and fixing it is awkward, because it requires Windows Update to install the Windows Update update.
  • And worming its tendrils through all this is Windows Activation DRM, which may or may not be interfering and causing problems. With no explanation.

It really is an awful system.

 

certbot bug and fix (NoInstallationError)

I’ve got a Let’s Encrypt SSL certificate on http://www.somebits.com. They expire every three months, so I set up certbot to renew the certificate. It wasn’t working though, the cron job got the error

NoInstallationError()

I think this bug is now fixed in certbot. But if you follow common instructions, the cron job runs certbot with “--no-self-upgrade” so you won’t get the update. Running certbot by hand will have it upgrade itself with the fix.

The underlying bug was that certbot couldn’t find the apache2 command in the PATH, because it’s in /usr/sbin and that’s not in root’s path. (:facepalm:). The committed fix has certbot checking a couple of extra directories in addition to PATH.