TL;DR
I've got a strange situation where I can do DNS lookups on some hosts but not others. This seems to be related to resolv.conf having one nameserver entry pointing to my nameserver and another that is presumably to do with docker, but I'm not sure how to fix it.
The problem
I've been reading Stéphane Graber's excellent introduction to LXD and wanted to try it out. Therefore, I did:
$ sudo usermod -a -G lxd <myusername>
$ newgrp lxd
$ sudo lxd init
I configured it with all of the default settings. I then typed:
$ lxc image list images:
error: Get https://images.linuxcontainers.org/streams/v1/index.json: lookup images.linuxcontainers.org: no such host
Some tests
I tried accessing that address from a web browser on another PC and it worked fine. So I figured something must be wrong with the DNS set-up, but:
$ host images.linuxcontainers.org
images.linuxcontainers.org is an alias for canonical.images.linuxcontainers.org.
canonical.images.linuxcontainers.org has address 91.189.91.21
canonical.images.linuxcontainers.org has address 91.189.88.37
canonical.images.linuxcontainers.org has IPv6 address 2001:67c:1560:8001::21
canonical.images.linuxcontainers.org has IPv6 address 2001:67c:1562::41
So I tried wget:
$ wget https://images.linuxcontainers.org/streams/v1/index.json
--2016-11-10 15:56:22-- https://images.linuxcontainers.org/streams/v1/index.json
Resolving images.linuxcontainers.org (images.linuxcontainers.org)... failed: Name or service not known.
wget: unable to resolve host address "images.linuxcontainers.org"
which made me think that there was a problem with my internet connection, but if I use us.images.linuxcontainers.org (which I saw mention of somewhere on the web):
$ wget https://us.images.linuxcontainers.org/streams/v1/index.json
--2016-11-10 15:57:26-- https://us.images.linuxcontainers.org/streams/v1/index.json
Resolving us.images.linuxcontainers.org (us.images.linuxcontainers.org)... 91.189.91.21, 2001:67c:1562::41
Connecting to us.images.linuxcontainers.org (us.images.linuxcontainers.org)|91.189.91.21|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3086 (3.0K) [application/json]
Saving to: "index.json"
index.json 100%[==================================================================================>] 3.01K --.-KB/s in 0s
2016-11-10 15:57:26 (8.36 MB/s) - "index.json" saved [3086/3086]
I also tried canonical.images.linuxcontainers.org, which (according to host above) is what images.linuxcontainers.org is an alias of and that worked too, so it looks like host can lookup images.linuxcontainers.org, while wget and lxc cannot, but wget can access canonical.images.linuxcontainers.org and most other sites I've tried.
$ wget https://canonical.images.linuxcontainers.org/streams/v1/index.json
--2016-11-10 16:02:28-- https://canonical.images.linuxcontainers.org/streams/v1/index.json
Resolving canonical.images.linuxcontainers.org (canonical.images.linuxcontainers.org)... 91.189.91.21, 91.189.88.37
Connecting to canonical.images.linuxcontainers.org (canonical.images.linuxcontainers.org)|91.189.91.21|:443... connected.
ERROR: no certificate subject alternative name matches
requested host name "canonical.images.linuxcontainers.org".
To connect to canonical.images.linuxcontainers.org insecurely, use `--no-check-certificate'.
$ wget --no-check-certificate https://canonical.images.linuxcontainers.org/streams/v1/index.json
--2016-11-10 16:02:37-- https://canonical.images.linuxcontainers.org/streams/v1/index.json
Resolving canonical.images.linuxcontainers.org (canonical.images.linuxcontainers.org)... 91.189.88.37, 91.189.91.21
Connecting to canonical.images.linuxcontainers.org (canonical.images.linuxcontainers.org)|91.189.88.37|:443... connected.
WARNING: no certificate subject alternative name matches
requested host name "canonical.images.linuxcontainers.org".
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://uk.images.linuxcontainers.org/streams/v1/index.json [following]
--2016-11-10 16:02:37-- https://uk.images.linuxcontainers.org/streams/v1/index.json
Resolving uk.images.linuxcontainers.org (uk.images.linuxcontainers.org)... 91.189.88.37, 2001:67c:1560:8001::21
Connecting to uk.images.linuxcontainers.org (uk.images.linuxcontainers.org)|91.189.88.37|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3086 (3.0K) [application/json]
Saving to: "index.json.1"
index.json.1 100%[==================================================================================>] 3.01K --.-KB/s in 0s
2016-11-10 16:02:38 (96.5 MB/s) - "index.json.1" saved [3086/3086]
I've also tried wget -4 and wget -6 to rule out IPv6 issues, but results were the same either way. Finally I tried some other programs like w3m but no difference there either.
I'm obviously missing something; can anyone offer any advice on why I can't get lxc to download the image list?
The PC
The PC is a relatively new install running Ubuntu Server 16.10 with very few additional packages installed in the main host. Docker is installed and running but no containers are up. Interestingly, I recently rebooted into kernel 4.8.6 to test another problem I was having and with that kernel I could access images.linuxcontainers.org, but docker wouldn't start, so I'm wondering if this might be to do with docker.
Configuration
/etc/resolv.conf looks like this (but for some reason I'm not aware of, is actually a symlink to /run/resolvconf/resolv.conf):
# 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
nameserver 192.168.1.254
nameserver 127.0.0.53
search lan
If I do query the first listed nameserver I get the same result as if I don't append the nameserver address:
$ host images.linuxcontainers.org 192.168.1.254
images.linuxcontainers.org is an alias for canonical.images.linuxcontainers.org.
canonical.images.linuxcontainers.org has address 91.189.91.21
canonical.images.linuxcontainers.org has address 91.189.88.37
canonical.images.linuxcontainers.org has IPv6 address 2001:67c:1560:8001::21
canonical.images.linuxcontainers.org has IPv6 address 2001:67c:1562::41
If I do query the second, it times out without reaching a server:
$ host images.linuxcontainers.org 127.0.0.53
;; connection timed out; no servers could be reached
If I query the second but use the canonical name it works and then times out???
$ host canonical.images.linuxcontainers.org 127.0.0.53
Using domain server:
Name: 127.0.0.53
Address: 127.0.0.53#53
Aliases:
canonical.images.linuxcontainers.org has address 91.189.88.37
canonical.images.linuxcontainers.org has address 91.189.91.21
;; connection timed out; no servers could be reached
;; connection timed out; no servers could be reached
Edit 1:
/etc/nsswitch.conf looks like this:
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.
passwd: compat
group: compat
shadow: compat
gshadow: files
hosts: files resolve [!UNAVAIL=return] dns
networks: files
protocols: db files
services: db files
ethers: db files
rpc: db files
netgroup: nis
Edit 2
The modified nsswitch.conf now looks like this:
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.
passwd: compat
group: compat
shadow: compat
gshadow: files
hosts: files resolve dns
networks: files
protocols: db files
services: db files
ethers: db files
rpc: db files
netgroup: nis
Edit 3
Contents of /etc/systemd/resolved.conf:
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details
[Resolve]
#DNS=
#FallbackDNS=8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844
#Domains=
#LLMNR=yes
#DNSSEC=no
#Cache=yes
/etc/resolv.confis usually a symlink on Ubuntu, that's normal. What does/etc/nsswitch.confcontain?lxc image listandlxc launchto use this instead of the built-in address.resolvehosts keyword, it seems wrong. You should have something likehosts: files dns [!UNAVAIL=return]or if you have mDNS installedfiles dns mdns4_minimal [NOTFOUND=return] mdns4. you can remove[NOTFOUND=return]or[!UNAVAIL=return], it's the default action anyway if nothing left to query.