Linux etc hosts

Linux /etc/hosts file

With the starting of the machine, some of the hostnames are required to be mapped or translated to IP addresses before DNS is referenced. So, /etc/hosts file are dedicated to store this mapping. If a name server is missing or not there, this file can be consulted by your system's network program to know the IP address which corresponds to a hostname.
Here is a sample of /etc/hosts file
IPAddress Hostname Alias
127.0.0.1 localhost deep.openna.com
208.164.186.1 deep.openna.com deep
208.164.186.2 mail.openna.com mail
208.164.186.3 web.openna.com web
In the given sample, first line begins with IP Address, a left most column needs to be resolved. Middle column is Hostname. Any the last column is Alias for the host given. Now in the second line, IP address 208.164.186.1 is shown for the host deep.openna.com and its alias or its other name given is deep.
When the process of configuring of networking files is finished, network must be restarted so that changes done can be effective.
[root@deep] /# /etc/rc.d/init.d/network restart
Setting network parameters [ OK ] Bringing up interface lo [ OK ] Bringing up interface eth0 [ OK ] Bringing up interface eth1 [ OK ]

Create Linux /etc/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 http://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.

Create the Linux /etc/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,

Create the Linux /etc/ 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
Edit Linux /etc/ hosts file

In Linux, hosts file is available under /etc/hosts. To edit the same, either a terminal text editor or a graphical text editor can be used. Unfortunately, only one graphical tool is available which partially control the hosts file, Linux Mint‘s Domain Blocker application. Need to add those entries in the hosts file by which hostnames specify to 127.0.0.1 is pointed out. Although all this can be done with the Domain Blocker also.
As said above, hosts file is a system file, if any changes are done in it, they need to save and for this administrative rights are required. Thus, a file can be edit by using terminal commands like Sudo nano /etc/hosts or gksu gedit /etc/hosts. A terminal needs to be used so appropriate application with administrative rights can be launched. Only replace gedit or nano with all time favorite graphical text editor and terminal text editor respectively. In nano, once editing is done in the file, press Ctrl + X on the keyboard, and then overwrite the changes.
Customize the Linux /etc/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.
Create the Linux /etc/ 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,

Create the Linux /etc/ 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

Save time and money by making the right web hosting decision the first time.

WordPress.com

Nexcess Hosting

Visit nexcess

Inmotion Hosting

Visit Inmotionhosting

Namecheap Hosting

Visit Namecheap

iThemes Hosting

Visit ithemes

Data-Driven Reviews

  • Current & accurate reviews are based on data and supported by real user experiences.
  • The goal is to deliver the most accurate information possible based on the needs of the majority of website owners and developers, and Ananova reports deliver the most reliable indicators of web host performance.

Save time and money by making the right web hosting decision the first time.

WordPress.com

Nexcess Hosting

Visit nexcess

Inmotion Hosting

Visit Inmotionhosting

Namecheap Hosting

Visit Namecheap

iThemes Hosting

Visit ithemes

Data-Driven Reviews

  • Current & accurate reviews are based on data and supported by real user experiences.
  • The goal is to deliver the most accurate information possible based on the needs of the majority of website owners and developers, and Ananova reports deliver the most reliable indicators of web host performance.
%d bloggers like this: