Perspectivesfrequal.com

Fixing Hostname Resolution for Non-Root Users

The Problem

Recently I found myself unable to connect to hosts by hostname. Ping, telnet, applications, all failed to resolve hostnames. Attempts resulted in errors like:
  • Unable to resolve host: XYZ
  • Unknown host XYZ
I checked the usual places:
  • My DNS servers were listed correctly in /etc/resolv.conf
  • DNS was listed in the "hosts: files dns" line of /etc/nsswitch.conf
Everything looked right but I couldn't resolve hostnames.

Next I tried resolving hostnames as root. It worked! That led me to research problems affecting only non-root users. The answer, it turned out, was file permissions on /etc/resolv.conf.

The Solution

For non-root users to resolve hostnames, /etc/resolv.conf and /etc/nsswitch.conf must be world-readable.

So, as root, run these commands:

chmod a+r /etc/resolv.conf
chmod a+r /etc/nsswitch.conf

Now try pinging by hostname from a regular user. It should work.


Last modified on 16 Sep 2009 by AO

Copyright © 2016 Andrew Oliver