How to Edit It
On Linux, you can find the hosts file under
/etc/hosts
. Since it’s a plain text file, you can easily use either a terminal text editor or a graphical text editor. Sadly, there’s only one graphical tool that provides partial control of the hosts file: Linux Mint‘s Domain Blocker application. It works by adding entries into the hosts file that points the hostnames you specify to 127.0.0.1. However, that’s all you can do with the Domain Blocker — any other uses of the hosts file require that you make the changes with a text editor.
Since the hosts file is a system file, you’ll need administrative rights to save changes to the file. Therefore, you can edit it using terminal commands such as
sudo nano /etc/hosts
or gksu gedit /etc/hosts
. You have to use the terminal so you can launch the appropriate application with administrative rights. Just replace nano or gedit with your favorite terminal text editor and graphical text editor, respectively. With nano, once you’re done editing the file, hit Ctrl + X, and then y to confirm overwriting the changes.Understanding Hosts File Syntax
In the hosts file, here, each entry is on its own line. For the purposes of this article, the syntax is very simple: you type the IP address you want the hostname to translate to, then a tab, and then the hostname. For example, to block Facebook, you’d type 127.0.0.1<tab>facebook.com, where <tab> is you pressing the tab key on the keyboard. To double check, you can also check the screenshot and compare it to yours.
In another example, if you have a computer on your home network (say with an IP address of 192.168.1.10) that has a simple website that does something useful for you, can can type the following in your hosts file: 192.168.1.10<tab>homeserver. Now, if you open your browser and just type in
http://homeserver
, it’ll automatically redirect to 192.168.1.10. And that’s much easier than typing in the IP address every time
No hay comentarios:
Publicar un comentario