This repository has been archived by the owner on Apr 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
hosts file format
lennylxx edited this page Apr 10, 2017
·
9 revisions
Hosts file is a plain text file, it's used to combine the IPs to corresponding domains.
According to http://linux.die.net/man/5/hosts, here are the rules of hosts file.
- Only one IP address in each line.
- Format in one line,
These items are separated by one or more
<ip-address> <hostname> [aliases...]
Space
orTab
. -
hostname
can only containalphabet
,number
,hyphen(-)
anddot(.)
. It must begin with alphanumeric and end with alphanumeric. -
alias
is optional, can be many. - The content that begins
hash(#)
ends with line break is regarded as comment. - Empty lines are ignored.
So, we can know that:
- hosts file doesn't support wildcard and regex expression.
123.123.123.123 *.mydomain.com
Lines like this are illegal. - Comments can be placed at the end of line.
123.123.123.123 foo.mydomain.com #comments