What are file hosts? Application hosts file to build Website without hosting & domain | Fun Learning Web-Sharing knowledge and IT resources

You have probably heard many times the phrase "edit file hosts" but not many people understand the role of file hosts, as well as how to use it.

In the last Topic of the Automatic Backup Topic - Restore & Clone - Migrate Website, we will understand what is the hosts file? where is it on the operating system and how to use it.

first. What are file hosts?

The hosts file is a text file (.txt) on the operating system - directly resolving the domain name for the operating system - without sending a query through the Domain Name System (DNS).

More precisely, the job of the hosts file is to redirect a hostname (domain name, website link) to any specified IP address.

Editing the hosts file is rarely found by normal users, but with webmasters, IT professionals, ‘crack’ software… editing hosts files is very familiar.

Let's dig a little deeper to understand why the hosts file is 'so useful'!

2. Power of File Hosts

The common operating systems Windows, Mac OS, Linux all have hosts file, normally this file is undeclared, it also does not work (because no one ordered it).

But, when necessary - it has immense power: assigning hostnames to IPs - bypassing the query from DNS - the server system resolving domain names on the Internet (of network operators + dns of domain - hosting - or intermediate dns like CloudFlare).

Learn how DNS works

Normally, the hosts file still exists but does not work, because on it there are only lines of instructions - instructions but no ‘redirect’ command has been declared.

The original hosts file of the operating system - only instructions & comments with #
The original hosts file of the operating system - only the comments with a # bullet

So when we go to any link - all the activity goes 'normal' in the way described below. When you open a browser (for example Chrome) and type the domain funnyhocweb.com into the browser, the process will look like this:

  1. Firstly, the information will be sent to the server's domain name resolution server system (for example, if you use FPT network, it is FPT's DNS system.
  2. If the data of FTP DNS does not have information about hostname vuihocweb.com, it will send queries to the DNS system connected worldwide, and thus link to the DNS system of Namecheap - domain provider vuihocweb.com .
  3. Because vuihocweb.com domain was pointed to HawkHost by declaring the IP of hosting with Namecheap DNS. Should Namecheap DNS respond to HawkHost hosting IP
  4. Finally, the browser has the Hawkhost IP hosting address - where the website funnyhocweb.com is located, the browser will send queries to that IP to load the Website.
How DNS works
How DNS works

So from The browser -> a series of DNS systems -> returns the IP of the Hosting , thanks to the IP should Browser <-> Hosting to load the website.

By default, if you type in a web address (hostname) - the query information will be sent to the DNS system and then the system will respond to the correct IP address of the hosting where the website is stored for browsing. Load content from there.

But - if we declare this line to the hosts file:

113.114.115 vuihocweb.com

Then: When typing vuihocweb.com on the browser, the information will not be sent via the DNS system to query the hosting IP anymore, but the browser immediately loads the content from IP 113.114.115, no matter what DNS says.

The hosts file is like the traffic police officer at Hang Xanh intersection - when I go in any direction, I go in that direction - no need to worry about the green light or the red light (DNS).

The best thing is that you have 'hosts' on the computer, only the power on that computer (otherwise it is chaotic). So we can 'redirect' a domain name to any IP we like - and this redirection only applies on our computer.

Now you probably understand why the domain funnyhocweb.com is pointing to HawkHost, people type happyhocweb.com into Hawkhost, and ‘ta’ type funnyhocweb.com, then visit the site on AZDIGI.

We do this by declaring this line in the hosts file on the operating system:

a2b2c2 vuihocweb.com

a2b2c2 is the IP of the AZDIGI hosting package that we are setting up site happyhocweb.com to migrate site to!

Where is the hosts file on the operating system?

Each operating system - path of the hosts file is different, namely:

  • On the computer used Windows, the hosts file is located in the directory: Windows / system32 / drivers / etc /
  • On the computer used Linux, the hosts file is located in the etc directory according to the path / etc /
  • On Mac OS, the hosts file is also located in the directory / etc / - To find quickly you press the key combination command + shift + G then enter / etc and press Go to go to the directory containing the hosts file
File hosts on Windows
File hosts on Windows

3. How to add information to the hosts file

To edit the hosts file, you need to open it with administrator privileges Administrator (or admin rights root / sudo in Linux).

However, even if opened with administrator rights, it is unlikely that you can edit and save the information of the hosts file, as the operating system may block access to it (It's like preventing viruses from adding millions of commands to hosts files to redirect millions of domain names to IPs of malicious websites.)

But, there is a pretty sure way to fix the hosts file information and save it successfully:

Step 1 - Copy the hosts file to another directory (desktop for example)

Copy the hosts file to the desktop to edit it

Step 2 - Open the copy file with the default text editor of the operating system (Notepad on Windows, Vi / Nano editor on Linux ...)

Declare the redirect commands you want (For example a2b2c2 vuihocweb.com) and save, because it is a copy file, you should save OK.

Copy the hosts file to the desktop to edit it

Step 3 - Copy the file just edited in step 2 - Paste (overwrite - replace) the original hosts file.
Overwrite the old hosts file with the edited hosts file

Accomplished!

4. Other applications of hosts file

In addition to the benefits of migrating websites, the hosts file is also widely applied in many situations, such as:

File Hosts application when need Migrate Website (hosting transfer)

Configuring the hosts file to set up the website is essential when you migrate - move your website from hosting to hosting without interrupting ‘up-time’:

For example, it is necessary to transfer vuihocweb.com from HawkHost (IP - a1b1c1) to AZDIGI (IP - a2b2c2)

  1. Users accessing the web still go to the version running on the old hosting (HawkHost) - because the domain funnyhocweb.com is still pointing to IP - a1b1c1 by HawkHost
  2. Go to cPanel of AZDIGI, create a new website - also called funnyhocweb.com (through the function of adding addons domain - if the primary domain of AZDIGI is another domain).
  3. Creating a site on AZDIGI with the domain funnyhocweb.com helps New website Configurable information - links ... The same website is running on HawkHost, but the new website does not yet exist on the Internet for public access - of course - because the domain funnyhocweb.com does not point to its IP, The domain name is still pointing to the IP of the old site (HawkHost)
  4. We configured the hosts file on the operating system of my computer By adding this line and saving: a2b2c2 vuihocweb.com . When adding this line, we type happyhocweb.com into the browser on the computer, the hosts file will automatically redirect us to IP a2b2c2 to access the new site (the user is still on the old site)
  5. We perform the installation - configuration - import site ... on the new site - When satisfied, we point the domain happyhocweb.com to the new site on AZDIGI via IP a2b2c2
  6. When the domain pointer is finished - Everyone on the internet will visit the new site when it is available on Funnyhocweb.com. Everything is not interrupted at all, does not affect the user experience at all.

Use the hosts file to block the software update - check the copyright

This app seems 'inferior' but almost every IT novice has used it.

Because the hosts file can redirect a domain name on the computer to any IP, we can use it to redirect access to software, to prevent it from checking and downloading updates - or checking for copyright if we use it. contraband goods.

For example, you install the TechSmith Screen Capture software - but it's cracked, to prevent it from sending requests to the TechSmith server (activation.cloud.techsmith.com) to check the copyright, we add the following lines to the file hosts:

  • 127.0.0.1 activation.cloud.techsmith.com
  • 127.0.0.1 activation.cloud.techsmith.com
  • 127.0.0.1 oscount.techsmith.com

127.0.0.1 is the IP address of localhost on the computer, ie if the software sends a query to activation.cloud.techsmith.com, oscount.techsmith.com, the query will be redirected back to their computer. Thanks to that, we can sleep well (- -).

Block users (or themselves) from accessing bad Web sites

The feature is extremely valuable in an age when the Internet is like a polluted sea, where you may encounter shrimp or fish waste and toxic waste.

For example, if you have children in your home, you can declare redirect to all websites danger go back to localhost, for example:

  • 127.0.0.1 thiendia.com
  • 127.0.0.1 kenh14.com
  • 127.0.0.1 soha.com
  • 127.0.0.1 zing.vn (full of hot boy hot girl news)
  • 127.0.0.1 bongda.com.vn (Vietnam's No. 1 football tabloid page)

Block the game guys

127.0.0.1 www.youtube.com/c/OnlineGameVn

If you take too much time for Facebook, Youtube, or have a hobby of slashing on Delicate's Cu, ... then:

  • 127.0.0.1 tinhte.vn
  • 127.0.0.1 facebook.com
  • 127.0.0.1 youtube.com

You can configure the hosts file on your phone very easily with the application Hosts Go. Configure to block access to any website on your phone, instead of redirecting to localhost (127.0.0.1) you can redirect to an IP or domain name of any website you want.

On SmartPhone, both Android and iOS have applications that help filter - block malicious websites, you can find more information on Google!

The redirection of these websites to localhost helps everyone in the family enjoy every moment of life, care about listening to each other instead of wasting time and let the mind worry about the work & thoughts of others. .

Used to set up Website without a domain

Similar to Migrate, if you want to set up a website - for example, wpsweetlady.com, but you have not purchased this domain, or you have a website wpsweetlady.com but want to completely redesign AZ (instead of clone to edit - upgrade)…. then you can use the hosts file to set up the website with that domain name without having to have a domain.

For example, if you want to setup wpsweetlady.com site on VPS Vultr - have an IP of 113.114.115, then just add this line to the hosts file on your computer:

113.114.115 wpsweetlady.com

And you have a ‘live’ site if you access it from your computer!

Build a Professional Website without Hosting - Domain?

Thanks to the redirect feature of the hosts file, you can completely set up on your computer a website with full hosting + domain:

  1. Hosting: you will use localhost with the software Xampp (or Wamp), this is software that helps you create a hosting package on Localhost (ie your computer). This hosting will use your computer's resources (RAM - CPU - At Hard). Of course, this hosting is only accessible on your computer, cannot be accessed from the internet.
  2. Configure the hosts file so that the domain you want to be directed to localhost, for example you add this line to the hosts file: 127.0.0.1 wpsweetlady.com, then type that domain, you will be redirected to localhost.

This application is extremely useful - help you learn to build a web completely free, as well as help you design web, coder ... deploy building - developing websites, webapps on your computer without paying penny for domain or hosting.

Website setup on localhost with Xampp will be presented in a new Topic!

Wish success!

0 Comments

×