/etc/hosts

From Gentoo Wiki
< /etc
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it - how to get started.

The /etc/hosts file is a file associating host names with IP addresses. It can be used to manually specify the IP address of, for example, a named device on a LAN, without having to set up a DNS server:

FILE /etc/hosts
192.168.1.100   larry

It will then be possible to do things like ssh user@larry, rather than ssh user@192.168.1.100.

The /etc/hosts file will only be consulted if the files is specified for the hosts entry in nsswitch.conf(5), e.g.:

FILE /etc/nsswitch.conf
hosts:      files dns

As DNS is not involved, tools like host(1) and dig(1) cannot be used to test whether host name lookup is working; instead, one should use getent(1), e.g.:

user $getent hosts larry

/etc/hosts can be used to do DNS-level blocking of problematic hosts and domains by adding blacklists to it, such as the oisd.nl blacklists and the Ultimate Hosts Blacklist.

To reference hosts and devices on a LAN by name, without having to manually maintain entries in /etc/hosts, set up zero-configuration networking (zeroconf) using Avahi.

See also