Skip to main content
59 votes
Accepted

What is the /etc/hosts size limit?

Problematical effects include slow hostname resolution (unless the OS somehow converts the linear list into a faster-to-search structure?) and the potential for surprising interaction with shell tab ...
thrig's user avatar
  • 35.8k
43 votes
Accepted

How do I modify my hosts file in Nixos?

Modify the nixos config (usually in /etc/nixos/configuration.nix) with: networking.extraHosts = '' 127.0.0.2 other-localhost 10.0.0.1 server ''; This is documented at NixOS Wiki and ...
Chris Stryczynski's user avatar
34 votes
Accepted

How do `/etc/hosts` and DNS work together to resolve hostnames to IP addresses?

This is dictated by the NSS (Name Service Switch) configuration i.e. /etc/nsswitch.conf file's hosts directive. For example, on my system: hosts: files mdns4_minimal [NOTFOUND=return] dns Here, ...
heemayl's user avatar
  • 58.1k
23 votes

What is the /etc/hosts size limit?

I don't think it has a size limit in terms of number of lines. Before DNS (which was brought into use in 1985), it was this file that served as the only means for doing host name lookups, so I ...
Kusalananda's user avatar
  • 356k
18 votes

Understand hostname and /etc/hosts

/etc/hostname and /etc/hosts are simple, but also not so simple... How to quickly setup Debian /etc/hostname and /etc/hosts 1) Edit /etc/hostname. There are 2 valid ways to set this up. Either ...
Elliptical view's user avatar
14 votes

What is the /etc/hosts size limit?

How can I determine the size limit of /etc/hosts? It is a regular file, so the limit would correspond to the underlying filesystem's limits (which would itself be capped by the number of disks behind ...
Jeff Schaller's user avatar
  • 68.8k
14 votes
Accepted

Ubuntu /etc/hosts addresses in the form *.*.*.*

No. The hosts file doesn't affect any routing. It only affects name lookups. Since 216.58.212.68 is an IP address, the system won't look it up in the hosts table. Read here for more info on the ...
Tim Kennedy's user avatar
  • 20.2k
14 votes
Accepted

bash like autocompletion for ssh command in zsh shell with /etc/hosts file?

Zsh won't offer you host completions until you enable its full completion system. You can do so by adding the following to your .zshrc file: autoload -Uz compinit compinit Once initialized, Zsh's ...
Marlon Richert's user avatar
13 votes
Accepted

alias fake hostname via /etc/hosts

The /etc/hosts file does not alias a hostname to another hostname the way you're trying to do. It associates a hostname to an IP address, period. The IP address appears in the first (left-most) ...
Sotto Voce's user avatar
  • 7,211
11 votes

What is the /etc/hosts size limit?

Size limits only apply when allocating static buffers. gethostbyname(3), which parses the entries in /etc/hosts, does not allocate static buffers - and never has. The original 1983 release of BSD 4.3 ...
bishop's user avatar
  • 3,249
11 votes

What is the proper way to display IPv6 Addresses in /etc/hosts

The hosts file format consists of lines, each of which contains the IP address, followed by whitespace, then one or more hostnames, also separated by whitespace. Nothing changes when the address is ...
Michael Hampton's user avatar
9 votes

Why do changes to /etc/hosts take effect immediately?

Name resolution, amongst other things, is managed by /etc/nsswitch.conf. Here is an excerpt: passwd: files sss shadow: files sss group: files sss hosts: files dns myhostname (...) ...
dr_'s user avatar
  • 32.4k
8 votes

Creating alias to domain name with /etc/hosts

As stated, /etc/hosts was not intended to provide alias (CNAME) ability for name to IP lookups. While setting up a proper DNS server and configuring the CNAME there would definitely be an always-...
Nab Eng's user avatar
  • 91
6 votes

What is the proper way to display IPv6 Addresses in /etc/hosts

IPv6 addresses have their own formatting system because they represent an 128-bit addressing space: that's 16 octets, which would be extremely unwieldly! As well, at this time there are a lot of runs ...
ErikF's user avatar
  • 4,207
6 votes
Accepted

How to map an IP address to localhost

/etc/hosts can be used if you want to map a specific DNS name to a different IP address than it really has, but if the IP address is already specified by the application, that and any other techniques ...
telcoM's user avatar
  • 114k
6 votes
Accepted

Understanding why hostname -i returns strange IP address

Unlike the hostname -I command, which just lists all configured IP addresses on all network interfaces, the hostname -i command performs name resolution (see the hostname man page). Since your newly ...
ozzy's user avatar
  • 865
6 votes
Accepted

/etc/hosts and aliases

From man hosts: This manual page describes the format of the /etc/hosts file. This file is a simple text file that associates IP addresses with hostnames, one line per IP address. ...
James John's user avatar
6 votes

How can I fix? Systems says "Host is down" and will not boot

RIP systemd. Use service instead. type in # service --status-all and see if it is functional. Then do all of your above commands using service syntax and you should be functional. Once you are ...
SwArMD's user avatar
  • 71
5 votes

What is the purpose of /etc/hosts?

Using the /etc/hosts file to give a human readable name to a local system within a desktop environment is perfectly reasonable. The hosts file is great to use in a home network or even in a small ...
francois P's user avatar
  • 1,299
5 votes
Accepted

/etc/hosts not blocking anything

macOS has a DNS cache, and if the IP addresses of the problem sites are already in your DNS cache, editing /etc/hosts won't have an immediate effect. The procedure for flushing the DNS cache is ...
telcoM's user avatar
  • 114k
5 votes
Accepted

Only use /etc/hosts for resolving hostnames on Linux

Remove dns from hosts field in /etc/nsswitch.conf: hosts: files You might also want to remove the DNS servers from /etc/resolv.conf.
sebasth's user avatar
  • 15.8k
5 votes

How to test /etc/hosts

You can use the 'ping' command to check the values added in /etc/hosts are working fine or not. echo "1.1.1.1 abc.com" >> /etc/hosts ping abc.com
Harley's user avatar
  • 151
5 votes
Accepted

How to ignore hosts file?

I do not know if there is browser based utility to do this. But you can do it for the entire OS. The key file is /etc/nsswitch.conf. To support only DNS records you should have record inside like: ...
Romeo Ninov's user avatar
  • 19.5k
5 votes
Accepted

Is it ok to combine machines with DNS server management and machines that do host lookups through a hosts file?

On one level this is a policy decision and nothing to do with the technology. On another level you should be asking yourselves why you don't want this second cluster properly supported by your ...
Chris Davies's user avatar
5 votes
Accepted

Why does localhost resolve to ::1 but not 127.0.0.1

Finding this wasn't easy (but fun :)). Short answer gethostbyname2(), which uses __lookup_name(), has some hard-coded values for the loopback ('lo') interface. When you specify 'localhost' to the '...
Tgilgul's user avatar
  • 498
5 votes
Accepted

Why is bash listing the effective content of /etc/hosts if I press Super_L+Space?

It's Konsole-specific feature introduced in commit 5ba34471 back in 2012. Reference: this Super User question A short summary of the mechanism as originally described in the linked Super User ...
Arkadiusz Drabczyk's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible