Whenever you want to establish control on what websites will you visit, it needs to edit the Hosts file. The same things need in Linux or Ubuntu. You can easily edit the Hosts file in Linux or Ubuntu. There was no extra pressure to do it. That means editing or modifying the Hosts file is not a tough work. We will learn in this tutorial, how to edit Hosts File in Linux and Ubuntu.
In general, Hosts File helps you to control accessing the websites on your PC. When you want to give specific permissions for the different users, you need to do it. Not to mention, when you want to control a website you need to add the DNS record and the domain name in the Hosts File. Then it will disallow the machine not to follow the URL. Certainly, it will give you the permission to update it in the future.
So do you want to edit the Hosts File in Linux or Ubuntu? Let’s learn how can you do it.
How to Edit Hosts File in Linux:
For modifying the Hosts File in Linux, you have to know the location of Hosts File in Linux first. Then you have to give the command to the Terminal. I will show you how can you do it.
1) Firstly Open The Terminal Window on Your Linux Computer.
2) You need to open a text editor now. You can use any of the text editors with your needs. Now Paste the code line on the editor.
“sudo nano /etc/hosts”
3) Now Give the Password
4) Now you are in the Hosts File of Linux and you can edit/modify or add anything to your requirements.
5) Press ‘Control+X’ when you have finished editing on the Hosts File. Now Press ‘Y’ when you are done editing.
You have successfully edited the Hosts File in Linux and you can edit it further at the same process.
Note: Remember or note down what changes you are doing in the Hosts file. Otherwise, you may get trouble when going to edit in the future.
How to Edit Hosts File in Ubuntu:
When you want to edit the Hosts File in Ubuntu, you have to work on the Terminal and the process is nearly same as like Linux. Let’s see how to edit Hosts File in Ubuntu. You can also check the Hosts File Location Of Ubuntu.
1) First Open THe Terminal Window on your Ubuntu Computer.
2) You need to work in a text editor. You can use GUI with the command. Now paste the below code to open the Hosts File.
“sudo -i gedit /etc/hosts”
3) Now Give The Password of your system of Ubuntu
4) It is the time to edit the Hosts File for your needs. That means you will add the Domain IP and Name here to block on your PC. When you are done, save the file and exit.
You have successfully edited the Hosts File on Ubuntu. You can do it later also.
Note: Again I’m saying remember the modification or note down, otherwise you may get trouble in the future when you will go to edit the Hosts File on Ubuntu.
Editor’s Note From TechyPi:
At last, I think you have understood the method of editing the Hosts file in Linux and Ubuntu. It will help you to block or control the PC from unwanted browsing or traffic.
If you get the article helpful, express your love by sharing it on the social media. At the same time, if anything seems difficult, you can make a comment. All the best wishes.