"#" = hash is used to escape the code and renders it as text. So, if you copy paste the code in linux in the terminal (CRTL + T to open) just be aware that:
to past = SHIFT+ CTRL + V;
never ever use code you do not comprehend, you are the sovereign of your daily-driver-box;
use it as a test on a live-cd or virtual environment before committing it to real life.
keyboard-buttons to hit are CAPITALIZED & BOLD.
If you want to know what is inside that file:
#cat /etc/hosts
First, we are going to back a backup copy. Should things go sour, you can always go back to square one. And no, no messing around because it is quicker. You want to work clean. Take this in, always backup! No compromises.
#cd /etc
So, what is in this directory? It is called the list-command.
#ls
That is quite a bunch. So let's cut that somewhat:
#ls host*
At this point I want to call attention to two things. WHO calls the shots and WHO has to do something.
Shouting HELP as a command is a general call for help. DONALD HELP is more specific as it addresses the WHO is called upon. And that is what Linux requires. So far, we only used the regular user rights.
sudo = super user do. This is the basic identification of WHO is calling the shots.
To copy, paste and rename the hosts file:
#mv hosts hosts.old
Yes. You probably noticed by now that your system refuses to work for you, as it responds: mv: cannot move 'hosts' to 'hosts.old': Permission denied
This is where you superuser rights come in.
#sudo mv hosts hosts.old
You are now required to provide your superuser authentication: a password. Usually that is your user-password, Unless you had someone else setup your box and this person thought it wise to cut you out of messing around outside of your documents, pictures, video and download folders.
#ls host*
Now you see a new file added to the list. hosts.old
MAKING YOUR LIFE EVEN COOLER:
To append the host-file, make sure you have vim or neovim installed. if you have not installed it, you can install it with the following command if you are using a debian style-distro. AUR and others use a different packagemanager, so the only difference is the call to that package-manager to do something.
#apt search neovim
It gives you a list of packages that answer to that name.
#sudo apt install neovim
Now this is out of the way:
#sudo nvim /etc/hosts
Invoke insert command: Either via the keyboard-button: INSERT or FN+F12:
127.0.0.1 google.com
This entry is better not copy-paste-d. Enter it by hand. Make sure to use a TAB between the IP of the local-host and the host-name.
Hit the escape keyboard-button: ESCAPE, then keyboard button: COLON followed by QW!. Note here you should enter small-caps and not capitals.
check the entry:
#cat /etc/hosts
You should now see the google.com entry with the mapping to the local-host in your file.
Open your browser.
Enter into the addressfield: google.com and watch what happens. If the setup is right, your browser will display your local-host-page with the message: Unable to connect.
If not, and you see the google.com page, it means that your browser ignores the host-file.
REMEDY:
There are a couple of ways to go about it. One is at this point more likely than the other. It may be that your linux distro has the lookup-order mixed up. That is with the current state of affairs unlikely.
The more likely issue is your browser settings. Depending on the browser, you may need to tweak a thing or two.
For Firefox users this is quite easy.
Open a tab en enter into the address field: about:config
there is a search-field. Enter into the search-field: network.dns.offline-local
Take note of the STATUS. This is either TRUE or FALSE. Most probably this is set to TRUE. On the right side of the page there is a toggle button. Hit it. You will notice the STATUS going from TRUE to FALSE. Exit the page.
Now you can try your test again with your browser. Enter into the address-field: google.com and watch what happens. You should be seeing the local-host page with the message: Unable to connect.
If you are using a Browser not based on Firefox, this search strong can help you on: {browser-name} ignores host-file.
If you are on windows ... why are you still on windows ....
SPECIAL NOTE:
For those who use as a daily driver: TAILS or have Tor-deamon installed. Take special care about this changing of the host-file. Messing up is easy.
This crash-course is brought to you by: anon-growth-path.
MORE:
If this tasted good for you, then you might want to try a few things:
#dig superuser.com A superuser.com AAAA +short
With this command you can discover the IPV4-address AND the IPv6 address.
All you have to do is change: superuser.com into any host-name. No https:// required.
There is a simple test you can do on Linux.
the host file is located at: /etc/hosts
CONVENTION:
"#" = hash is used to escape the code and renders it as text. So, if you copy paste the code in linux in the terminal (CRTL + T to open) just be aware that:
If you want to know what is inside that file:
#cat /etc/hosts
First, we are going to back a backup copy. Should things go sour, you can always go back to square one. And no, no messing around because it is quicker. You want to work clean. Take this in, always backup! No compromises.
#cd /etc
So, what is in this directory? It is called the list-command.
#ls
That is quite a bunch. So let's cut that somewhat:
#ls host*
At this point I want to call attention to two things. WHO calls the shots and WHO has to do something. Shouting HELP as a command is a general call for help. DONALD HELP is more specific as it addresses the WHO is called upon. And that is what Linux requires. So far, we only used the regular user rights.
sudo = super user do. This is the basic identification of WHO is calling the shots.
To copy, paste and rename the hosts file:
#mv hosts hosts.old
Yes. You probably noticed by now that your system refuses to work for you, as it responds: mv: cannot move 'hosts' to 'hosts.old': Permission denied
This is where you superuser rights come in.
#sudo mv hosts hosts.old
You are now required to provide your superuser authentication: a password. Usually that is your user-password, Unless you had someone else setup your box and this person thought it wise to cut you out of messing around outside of your documents, pictures, video and download folders.
#ls host*
Now you see a new file added to the list. hosts.old
MAKING YOUR LIFE EVEN COOLER:
To append the host-file, make sure you have vim or neovim installed. if you have not installed it, you can install it with the following command if you are using a debian style-distro. AUR and others use a different packagemanager, so the only difference is the call to that package-manager to do something.
#apt search neovim
It gives you a list of packages that answer to that name.
#sudo apt install neovim
Now this is out of the way:
#sudo nvim /etc/hosts
Invoke insert command: Either via the keyboard-button: INSERT or FN+F12:
127.0.0.1 google.com
This entry is better not copy-paste-d. Enter it by hand. Make sure to use a TAB between the IP of the local-host and the host-name.
Hit the escape keyboard-button: ESCAPE, then keyboard button: COLON followed by QW!. Note here you should enter small-caps and not capitals.
check the entry:
#cat /etc/hosts
You should now see the google.com entry with the mapping to the local-host in your file.
Open your browser.
Enter into the addressfield: google.com and watch what happens. If the setup is right, your browser will display your local-host-page with the message: Unable to connect.
If not, and you see the google.com page, it means that your browser ignores the host-file.
REMEDY:
There are a couple of ways to go about it. One is at this point more likely than the other. It may be that your linux distro has the lookup-order mixed up. That is with the current state of affairs unlikely.
The more likely issue is your browser settings. Depending on the browser, you may need to tweak a thing or two.
For Firefox users this is quite easy.
Open a tab en enter into the address field: about:config
there is a search-field. Enter into the search-field: network.dns.offline-local
Take note of the STATUS. This is either TRUE or FALSE. Most probably this is set to TRUE. On the right side of the page there is a toggle button. Hit it. You will notice the STATUS going from TRUE to FALSE. Exit the page.
Now you can try your test again with your browser. Enter into the address-field: google.com and watch what happens. You should be seeing the local-host page with the message: Unable to connect.
If you are using a Browser not based on Firefox, this search strong can help you on: {browser-name} ignores host-file.
If you are on windows ... why are you still on windows ....
SPECIAL NOTE:
For those who use as a daily driver: TAILS or have Tor-deamon installed. Take special care about this changing of the host-file. Messing up is easy.
This crash-course is brought to you by: anon-growth-path.
MORE:
If this tasted good for you, then you might want to try a few things:
#dig superuser.com A superuser.com AAAA +short
With this command you can discover the IPV4-address AND the IPv6 address. All you have to do is change: superuser.com into any host-name. No https:// required.
Test:
#dig openstreetmap.org A openstreetmap.org AAAA +short
184.104.179.139
184.104.179.140
184.104.179.141
2001:470:1:fa1::d
2001:470:1:fa1::c
2001:470:1:fa1::b