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 ...
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 ...
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, ...
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 ...
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 ...
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 ...
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 ...
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 ...
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) ...
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 ...
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 ...
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
(...)
...
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-...
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 ...
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 ...
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 ...
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. ...
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 ...
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 ...
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 ...
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.
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
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:
...
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 ...
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 '...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
hosts × 230networking × 48
dns × 48
hostname × 42
linux × 31
ip × 20
ubuntu × 15
ssh × 14
bash × 10
centos × 10
debian × 9
etc × 9
ipv6 × 8
domain × 8
shell-script × 7
macos × 7
ping × 7
browser × 7
apache-httpd × 5
firewall × 5
dnsmasq × 5
iptables × 4
internet × 4
host-name-resolution × 4
shell × 3