Linux Hosts File
People who are interested in knowing various aspects about Hosts file of Linux, like how Linux hosts files are created, how editing is done in these files or how these files can be customized etc. are at the right place. In this article, we will study about Linux Hosts file. However, before that, a concept of hosts file needs to be cleared, as most of us may be not aware of the same.
About Hosts File
A Hosts file is a file of a computer system, using by an operating system for mapping the hostnames to IP addresses. Like other text files, it is also a simple and plain text file.
Hosts File, originally named as HOSTS.TXT, manually created, maintained and offered through file sharing by Stanford Research Institute for the ARPANET membership. It possesses the host names as well as host addresses to include the same by member organizations.
Hosts file is one of the facility of system which assists in addressing the network nodes in a computer network. It is a common component in implementing Internet Protocol (IP) in operating system and plays an important role in the translation of user-friendly hostnames to IP addresses, by whom host is identified and located in an IP network.
How to Create Linux Hosts File
When network card needs to be configured, first decide the IP address, then FQDN, and aliases which are maximum used in the hosts file.
The syntax is:
<IP address> myhost.example.org aliases
For ensuring security, IP Address must be kept in the range of private network IP Addresses, until and unless computer becomes visible to the web. Ranges which are valid are:
Class Networks
A 10.0.0.0
B 172.16.0.0 through 172.31.0.255
C 192.168.0.0 through 192.168.255.255
192.168.1.1. could be a valid IP address and a valid FQDN for this IP address could be www.linuxfromscratch.org
FQDN is always required, whether user is making use of a network card or not. In order to run or operate some programs in a correct manner, FQDN plays a vital role.
How to Create the Linux hosts file by running
cat > /etc/hosts << “EOF”
# Begin /etc/hosts (network card version)
127.0.0.1 localhost
[192.168.1.1] [<HOSTNAME>.example.org] [HOSTNAME]
# End /etc/hosts (network card version)
EOF
IP Address 192.168.1.1 and <HOSTNAME>.example.org values are required to change according to the specific needs of the users. If IP address is assigned by a network/system administrator, machine always connects to an existing network.
If network card is not configured,
How to Create the Linux hosts file by running
cat > /etc/hosts << “EOF”
# Begin /etc/hosts (no network card version)
127.0.0.1 [<HOSTNAME>.example.org] [HOSTNAME] localhost
# End /etc/hosts (no network card version)
EOF
How to Customize the Linux Hosts File
After creating the Linux hosts file, when they need to customize, process is given
If a network card is required to be configured, first decide the IP address, then fully-qualified domain name (FQDN), and then aliases which are mostly used in the hosts file.
The syntax is:
IP_address myhost.example.org aliases
For ensuring security, IP Address must be kept in the range of private network IP Addresses, until and unless computer becomes visible to the web. Ranges which are valid are:
Private Network Address Range Normal Prefix
10.0.0.1 – 10.255.255.254 8
172.x.0.1 – 172.x.255.254 16
192.168.y.1 – 192.168.y.254 24
x is any number which ranges between 16-31 and y comes under the range of 0-255.
192.168.1.1. could be a valid private IP address and a valid FQDN for this IP can be lfs.example.org.
A network card, if not in use, requires a valid FQDN. It is also essential for certain programs operation in a right way.
How to Create the Linux hosts file by running
cat > /etc/hosts << “EOF”
# Begin /etc/hosts (network card version)
127.0.0.1 localhost
<192.168.1.1> <HOSTNAME.example.org> [alias1] [alias2 …]
# End /etc/hosts (network card version)
EOF
IP Address 192.168.1.1 and <HOSTNAME>.example.org values are required to change according to the specific needs of the users. Alias name(s) are optional thus, can be omitted.
If a network card will not be configured,
How to Create the Linux Hosts file by running
cat > /etc/hosts << “EOF”
# Begin /etc/hosts (no network card version)
127.0.0.1 <HOSTNAME.example.org> <HOSTNAME> localhost
# End /etc/hosts (no network card version)
EOF