DNS Location Records
One of the more interesting DNS records that does not see much use is the location record. Defined by RFC 1876, the LOC record allows you to describe a precise latitude, longitude, and altitude linked to a host name. Imagine a trace route tool using LOC records which displays the exact router locations on a map for each hop. If you were so inclined, you could set a detailed LOC record for every computer in the office and then map that data on a 3D building diagram. A bit of overkill, however, it shows you that linking location data to a hostname can have its uses.
LOC Record
Here is an example of what a LOC record looks like. In this example, we are defining the location of the Needles Visitor Center in Canyonlands National Park. I will break this record down into its components and show how to get each value.
Hostname | TTL | Class | RR Type | Lat Degree | Lat Min | Lat Sec | Lat Hemisphere | Lon Degree | Lon Min | Lon Sec | Lon Hemisphere | Alt | Size | VP | HP |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
needles.bananatrunkingprotocol.com. | 3600 | IN | LOC | 38 | 10 | 4.97 | N | 109 | 45 | 33.9 | W | 1m | 40m | 2m | 2m |
Defining a Sphere
The LOC record describes location by first defining a sphere in meters. This sphere acts as the outer bounds of the area we wish to locate. A small sphere can be used for a very precise location such as a computer in an office, or a large sphere can be used to locate a building. This measurement is defined in the record as size. Many mapping programs online such as Google maps will let you measure distance between two points and can be used for the size value.
Degrees / Minutes / Seconds
Now that we have the general area our object will encompass, we must place that sphere at a specific latitude, longitude, and altitude. Latitude and longitude are described in degrees, minutes and seconds. This nomenclature makes sense when you look at Earth as a sphere you are dividing into sections. Lets take a closer look at how this works.
To measure a point on the Earth’s surface we use angles measured in degrees from the Earths center. Measurements North / South are latitude and East / West are longitude. The origin of this system is located where the prime meridian and equator cross, a designation of (0°N,0°E). From here there are 90° of latitude and 180° of longitude.
You might ask, I thought there are 360° in a circle, why do we measure at most to 180°? To make things easier, the Earth is divided into four hemispheres, Northern / Southern for latitude, and Eastern / Western for longitude. If our location is in North America, longitude would specify the Western hemisphere and latitude would specify the Northern. This allows us to use only 90° of latitude and 180° of longitude as we are effectively specifying a quarter of the globe at a time. Google maps and other online mapping tools can be used to find longitude and latitude values. If using Google maps, please see section about decimal degrees.
Altitude
The last measurement we need for our LOC record is the altitude of the center of the sphere we defined earlier. This can specify a location on the ground, one 500 meters in the sky, or one 200 meters underground. Here is where things get a bit complicated as there are many different ways to define altitude based on how you define zero height. This reference is known as the vertical datum. A common vertical datum uses a base of sea level. If you live at an altitude of 2100 ft, that is generally 2100 ft from mean sea level and considered your orthometric height. Mean sea level is used as an approximation of the uneven surface of the planet. The problem with using this base is that its variable nature makes precise measurements hard and possibly wrong over time. The definition also changes based on country. A better vertical datum is included in the standard, World Geodetic System 84 (WGS 84). In a search for a better model, the United States, along with the help of scientists from around the world, developed a standard which would eventually evolve into WGS 84. Instead of the variable mean sea level as base in the vertical datum, WGS 84 uses a mathematically defined ellipsoid centered on Earths center of mass. your height using this vertical datum is called your ellipsoid height. This solid foundation allowed for the development of complex systems on top of it without worry of change. GPS is one such technology which relies on the WGS 84 standard.
Now with that bit of background out of the way, the LOC record defines altitude as height from or below the WGS 84 ellipsoid. So how do we find this information? Most altitude measurements you can find online have a vertical datum based on mean sea level. We will need to convert the orthometric height based on mean sea level to ellipsoid height. Lucky there are a good number of online calculators which can help. Most of these calculators work by taking the location coordinates and returning the geoid height relative to the WGS 84 ellipsoid. All we need to do is take our altitude measurement based on mean sea level (orthometric height) and add it to our geoid height.
Accuracy
Finally, we need to discuss accuracy. In an earlier used case example, I mentioned defining the location of a computer in an office building. This, while possible, is highly improbable. The precision needed for such a pinpoint location would take surveyors equipment and more than a passing understanding of geodesy. The more realistic use case is defining the locations of buildings or general areas. The quest for precision is also thwarted by the accuracy of available datasets. All of the information needed for a LOC record can be found online however, dependent on the dataset, can be less than accurate.
The LOC record actually includes fields to account for less than precise data. The fields Vertical Precision and Horizontal Precision are optional and can be used to express a margin of error in meters. If these fields are not included in the record, the values are assumed to be the default of 10m for vertical and 10000m for horizontal. This may seem like a large area however these defaults are chosen to represent typical ZIP/postal code area sizes, since it is often easy to find approximate geographical location by ZIP/postal code. At the minimum you should include a more precise horizontal value as it is easy to get under 10000m accuracy with current maps and datasets.
Decimal Degrees
One final thing to note is Decimal Degrees. When determining location, the LOC record relies on longitude and latitude expressed as degrees, minutes, and seconds (DMS). This notation works great however is a bit cumbersome. To simplify things, DMS can be converted to a decimal number. This is called decimal degrees (DD). I make this note as many online data sources use DD to define a location instead of DMS. Google maps is one example which uses DD extensively. You can coax out the DMS formatted location however it takes some work. It is therefore useful to be able to convert DD location values into DMS for the LOC record. I am including the formula and some basic Python code that accepts a DD location and spits out a LOC record with DMS values.
\( \Large d \normalsize = int(dd) \)
\( \Large m \normalsize = int((dd-d)* 60) \)
\( \Large s \normalsize = (dd - d - m/60) × 3600 \)
#!/bin/python3
############################################################
# Decimal Degrees -> Degree Minutes Seconds -> LOC record #
############################################################
decimal_degrees = [55.7520233, 37.6174994]
# All values are based on default as defined in RFC
rr_ttl = "3600" # Time to live for record
rr_alt = "1m" # The altitude of the center of the sphere described by the size field
rr_size = "1m" # Diameter of a sphere enclosing the described entity
rr_vp = "10m" # The vertical precision of the data
rr_hp = "10000m" # The horizontal precision of the data
domain_name = "site.example.com." # Domain name set to a location. Must be a FQDN or realative to zone $ORIGIN
lat_dd = decimal_degrees[0]
lon_dd = decimal_degrees[1]
if lat_dd > 0:
ns = "N"
else:
ns = "S"
if lon_dd > 0:
ew = "E"
else:
ew = "W"
def dd_to_dms(dd):
dms = {}
dms["d"] = abs(int(dd))
dms["m"] = int(((abs(dd) - dms["d"]) * 60))
dms["s"] = round(((abs(dd) - dms["d"] - int(dms["m"]) / 60) * 3600), 2)
return dms
lat_dms = dd_to_dms(lat_dd)
lon_dms = dd_to_dms(lon_dd)
print('Decimal Degrees: {}, {}'.format(lat_dd, lon_dd))
print('Degress/Minutes/Seconds: {}\N{DEGREE SIGN}{}\'{}\" {} {}\N{DEGREE SIGN}{}\'{}\" {}'.format(\
lat_dms["d"],
lat_dms["m"],
lat_dms["s"],
ns,
lon_dms["d"],
int(lon_dms["m"]),
lon_dms["s"],
ew))
print('LOC Record: {} {} IN LOC {} {} {} {} {} {} {} {} {} {} {} {}'.format(\
domain_name,
rr_ttl,
lat_dms["d"],
lat_dms["m"],
lat_dms["s"],
ns,
lon_dms["d"],
int(lon_dms["m"]),
lon_dms["s"],
ew,
rr_alt,
rr_size,
rr_hp,
rr_vp))