How to Edit Linux Hosts File

In this article we will try to teach you how to edit Linux hosts file. Occasionally you may need to edit the hosts file on your computer. Your hosts file may have been maliciously modified in an attack or prank. Alternatively, you may only want to control access to specific websites or network traffic. Computers have had hosts files since the ARPANET days. The hosts files were used to resolve hostnames for decades before the DNS system was implemented. Because they were used to support network name resolution, hosts files grew into huge documents. Microsoft, Apple, and other OS developers have kept the hosts file, so it varies very little between Windows, macOS, and Linux. The syntax remains largely the same on all platforms. Most hosts files have multiple entries for loopback.

In the /etc/hosts file, your system stores an internal map of IP addresses -> hostnames. This does not require a DNS server as it is stored locally on your computer. This is a great way to manage things like internal servers or other devices on your network that normally require you to enter an IP address. Below we have mention the steps to edit host file in Lonix.

How to Edit Linux Hosts File

Open a Terminal Window (Command Line)

Most Linux distributions have an applications > utilities > terminal feature, or an option to right-click the desktop and click Open Terminal.

Open the Linux Hosts File

To open the Linux hosts file, type the command:

sudo vim /etc/hosts

The system should prompt for your password – enter it, and the Hosts file should open.

Modify the File

The hosts file in Linux is formatted so that the IP address is first, and the server name is second.

0.0.0.0 server.domain.com

Add any entries you wish to the end of the file. If you make a mistake or need to tell your operating system to ignore a line, add the ‘#’ sign at the beginning of that line.

Name Service Switch

The hosts file bypasses the standard Domain Name Server lookup. In Linux, there’s another file that tells the operating system what order to look for the IP address translations. The file is nsswitch.conf, and if it’s configured to look at DNS first, then it’ll skip your hosts file and go straight to DNS lookup.

To check the configuration, in your terminal window type:

cat /etc/nsswitch.conf

About halfway down, there should be an entry labeled “hosts”. Make sure that the right-hand column lists files first. If for some reason DNS is listed first, open the file in your text editor:

sudo vim /etc/nsswitch.conf

It should open the nsswitch.conf file. For the hosts: setting, change the entry so that files is at the beginning of the entry, and dns is at the end.

Final Words

We hope our article on how to Edit Linux Hosts File will help you and resolve all your problems. Linux is an open source operating system (OS). An operating system is the software that directly manages a system’s hardware and resources such as CPU, memory, and storage. The operating system sits between applications and hardware, making the connections between all your software and the physical resources that do the work.

I hope you understand this article, How to Edit Linux Hosts File.

Editorial Staff
Editorial Staffhttps://www.bollyinside.com
The Bollyinside editorial staff is made up of tech experts with more than 10 years of experience Led by Sumit Chauhan. We started in 2014 and now Bollyinside is a leading tech resource, offering everything from product reviews and tech guides to marketing tips. Think of us as your go-to tech encyclopedia!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related Articles

Best Telemedicine Software: for your healthcare practice

Telemedicine software has transformed my healthcare visits. It's fantastic for patients and doctors since they can obtain aid quickly. I...
Read more
I love microlearning Platforms in today's fast-paced world. Short, focused teachings that engage me are key. Microlearning platforms are great...
Think of a notebook on your computer or tablet that can be changed to fit whatever you want to write...
As of late, Homeschool Apps has gained a lot of popularity, which means that an increasing number of...
From what I've seen, HelpDesk software is essential for modern businesses to run easily. It's especially useful for improving customer...
For all of our important pictures, stories, and drawings, Google Drive is like a big toy box. But sometimes the...