How to modify and manage Hosts files on Linux
If you need to block web pages or create personalized web shortcuts on Linux, solve these tasks by adding or adjusting a few lines in the hosts file.
There is a single file on the computer that acts as a small port between the user and the web, called the hosts file. If you need to block web pages or create personalized web shortcuts on Linux, solve these tasks by adding or adjusting a few lines in the hosts file.
Learn about the Hosts file on Linux
- What is file hosts on Linux?
- Location of hosts file on Linux
- How to add the site to the hosts file
- Create a shortcut in the hosts file
- The underlying problem with the hosts file
What is file hosts on Linux?
File hosts is a simple plain text file that all operating systems use to translate hostnames (also known as web addresses or URLs) into IP addresses. When entering the hostname, such as quantrimang.com, the system will review the file hosts to obtain the necessary IP address and connect to the appropriate server.
If you open the hosts file, you will quickly notice that there is no directory of the entire Internet in it, but only a few short lines.
Turns out, the system will check the host file before searching for a site on the DNS servers identified in the network settings (usually the ISP's DNS server).
This means that the hosts file can be used to add what the DNS server cannot provide (such as an alias for locations on the local network. This only happens if a DNS server is set up. in the local network) or override the IP addresses that DNS servers normally provide.
For example, if requested by quantrimang.com, DNS servers will return IP Address TipsMake.com to the computer. But if you want to block TipsMake.com on that computer, you can add an item in the hosts file, let the computer know that quantrimang.com points to some IP addresses other than the actual IP address of TipsMake.com .
There are many other things to do with hosts files, but these are just a few basic examples and other uses that depend heavily on the needs of each person.
Location of hosts file on Linux
On Linux, you can find the hosts file in / etc / hosts. Because this is a / etc / hosts file, you can open the hosts file with your favorite text editor.
However, because the hosts file is a file system, it will need admin rights to save the changes. So, to edit the hosts file with a terminal Linux-based text editor, such as nano, first enter sudo to have superuser access (superuser):
sudo nano /etc/hosts
To use a graphical text editor like gedit, you can try gksu instead:
gksu gedit /etc/hosts
You must use the terminal to be able to launch the application in accordance with admin permissions. Just replace nano or gedit with a terminal-based text editor or favorite graphics. With nano, when you've finished editing the file, press Ctrl + X and then press Y to confirm overwriting changes.
How to add the site to the hosts file
In hosts file, each item has its own line. The syntax is very simple. Enter the IP address you want to translate into the hostname, press the Tab key on the keyboard and then enter the hostname.
For example, to block Wikipedia, enter (remember to use the Tab key instead of the spacebar):
127.0.0.1 wikipedia.org
127.0.0.1 is a loopback IP address that will always point to your own system. Since the website is not hosted, the browser will indicate that the site cannot be found. Now, the website has been effectively blocked.
If you do not like to use Terminal, check out Linux Mint's Domain Blocker application (also known as mintnanny). Domain Blocker will add entries to the hosts file pointing to the hostname you specified to 127.0.0.1. But to do anything else, you will still need to change with the text editor.
- Download Domain Blocker (Free)
Create a shortcut in the hosts file
If you have a computer on your home network (assuming your device's IP address is 192.168.1.10 ) and a simple website is useful for you, you can enter the following content into your hosts file:
192.168.1.10 homeserver
Then, if you open the browser and enter http:/// homeserver, it will automatically redirect to 192.168.1.10. Much easier than typing IP addresses each time.
Alternatively, you can use file hosts to create shortcuts to certain websites on the web. Use a command like nslookup to find the site's IP address, then add it to your hosts file with the desired shortcut, just like in the example above. But this only works on websites with dedicated IP addresses and may not work for most websites you visit.
The underlying problem with the hosts file
The article mentioned changes to hosts files, but you may still have problems using Google Chrome. This web browser tends to ignore the hosts file unless you do one of the following:
1. Enter http:/// at the beginning of each address. For example, if you block Wikipedia in the hosts file, then Chrome skips blocking this page, if you enter wikipedia.com into the address bar. If you enter http://wikipedia.com into the address bar, the browser will follow the hosts file.
2. Disable 'Use a web service to help resolve navigation errors' in Chrome settings and then you do not have to enter http:/// at the beginning of the address bar every time you visit the site. This is one of several Google Chrome security tips worth doing.
File hosts provide an easy way to block access to some websites on the computer. Since many versions of Linux do not include parental control software, this can be useful if you decide to start your children using a Linux computer.
You should read it
- How to fix hosts file on Mac
- How to reset HOSTS file on Windows 7/8 / 8.1 and Windows 10
- Block the website by hosts files on Windows 8
- Some tricks for hosts files in the system
- Instructions to restore the hosts file on Windows to default
- How to Edit the Hosts File on a Mac
- How to block websites using hosts file
- How to edit the Host file, how to edit the Host file, read and open the Host file
- How to open the hosts file with Admin rights - Apply to open the file system
- Edit Hosts file to access Facebook 2014
- How to fix the hosts file on Windows 10
- Fix the error that the host file cannot be saved on Windows 7, 8, 10 - How to fix the hosts file
Maybe you are interested
Who made this two meter tall 'devil's corkscrew' millions of years ago? Instructions for installing Hyper-V Attractive extensions on Google Chrome Top tool to create avatar and cover photos 'quality' for Facebook Advanced Twitter account security guide Create the Avatar 'Run Now' in the poster style of Son Tung M-TP