On occasion you will need to edit the host file in windows machine. Sometimes because of an attack or prank, and others so that you can simply and freely control access to websites and network traffic (host file in windows).
hosts files have been in use since ARPANET. They were used to resolve host names before DNS. hosts files would be massive documents used to aide the network name resolution (host file in windows).
Microsoft kept the hosts file alive in Windows networking which is why it varies very little whether used in Windows, macOS, or Linux. The syntax stays mostly the same across all platforms. Most hosts files will have several entries for loopback. We can use that for the basic example for the typical syntax (host file in windows).
The first part will be the location to redirect the address to, the second part will be the address that you will want to redirect, and the third part is the comment. They can be separated by a space, but for ease of reading are typically separated by one or two tabs (host file in windows).
127.0.0.1 localhosts #loopback
Now let’s look at accessing the hosts files in the different operating systems…
Windows 8 or 8.1 or 10
Unfortunately Windows 8 or 10 makes it annoying to open apps as administrator — but it’s not too difficult. Just search for Notepad, then right-click on Notepad in the search results list, and choose to run it as administrator. If you’re using Windows 10 this will be on the Start Menu (host file in windows).
If you’re using Windows 10, it’ll look more like this:
Once you’ve done so, open up the following file using the File -> Open feature (host file in windows).
Then you can edit as normal.
To access the hosts file in Windows 7 you can use the following command in the Run Line to open notepad and the file (host file in windows).
Once notepad is open you can edit the file. In this example we will block Facebook. To do this just enter in the following after the # mark (host file in windows).
Now that you have edited your Hosts file make sure to save it(host file in windows).
Now notice if we try to access Facebook in IE we can’t get to the page (host file in windows).
We also were not able to get to it in Google Chrome… (check notes at the end). Also for more info on editing your Hosts file, check out The Geek’s article on how to create a shortcut to quickly edit your Hosts file.
In Ubuntu 10.04 and most Linux distro’s you can edit the hosts file directly in the terminal. You can use your favorite editor or even open your favorite GUI text editor. (host file in windows) For this example we will use VIM. Like Windows 7, Ubuntu’s hosts file is located in the /etc/ folder, though here it is in the root of the drive. In order to edit the file you will need to open it as root which is why we use sudo here (host file in windows).
Now that it is open we can edit it to redirect Facebook into nothing. You will notice that with Ubuntu there is also a section for IP6. (host file in windows) For most needs you will only need to edit it the top section and ignore the IP6 (host file in windows).
Now we can save the file and try to go to Facebook.com. Just like in windows we will see that we are now redirected to a site that does not exist.
macOS (Any Version)
In macOS, accessing the hosts file is very similar to Ubuntu. Begin in terminal and use your favorite editor, even is you wish to call a GUI text editor, it is easier to do so from terminal (host file in windows).
The file will look a bit more like Windows, only with a little less explanation. Again we are going to redirect Facebook (host file in windows).
This time it seems that 0.0.0.0 is a loopback and will direct you to the computers Apache test page (host file in windows).
There are some things to note from this walkthrough that we did notice. When tested it, Chrome did not use the hosts file in any operating system but we were able to block Facebook in Chrome by adding www.facebook.com. Also, make sure to place and extra line after the last entry for the section (host file in windows).
This should get you started in understanding the Hosts file and how it can help protect your computer. You can use it to block sites that you don’t want a PC to be able to access. If you have more suggestions for any of the operating systems we coved, then leave a comment and let us know! (host file in windows)
- › Microsoft Will Merge UWP and Win32 Apps With Project Reunion
- › Windows 10 Is Getting Graphical Linux Apps With GPU Support
- › Windows 10’s PowerToys Get a Launcher and Keyboard Remapper
- › Microsoft Edge Is Getting a Web Search Sidebar
- › The New Windows Terminal Is Ready; Here’s Why It’s Amazing
How to Edit Your Hosts File in Windows 10 Step Second
Reading Time: < 1 minute
Editing your \etc\hosts file is a common task for troubleshooting issues or for developing a site that you aren’t quite ready to launch. By editing this file, you’ll be able to bypass DNS to view a site at a declared IP address.
In Windows 10, your hosts’ file is located at: C:\Windows\System32\drivers\etc\hosts. You will need to edit the file with administrative privileges.
- Click the Windows button and type Notepad in the search bar.
- Right click on Notepad and then Run as Administrator.
- You’ll be asked, “Do you want to allow this app to make changes to your device?”.
- In Notepad, choose File then Open
- Navigate to C:\Windows\System32\drivers\etc\hosts or click the address bar at the top and paste in the path and choose Enter. If you don’t readily see the host file in the /etc directory then select All files from the File name: drop-down list, then click on the hosts file.
- Add the appropriate IP and hostname at the end of your hosts’ file, select save and close the file.
- Finally, you will want to flush your DNS cache for your computer to recognize changes to the file. Click the Windows button and search command prompt.
- Right-click on Notepad and then Run as Administrator.
- You’ll be asked, “Do you want to allow this app to make changes to your device?”.
- Type the following command in the terminal and press Enter
- Managing File Permissions in Cloud Sites File Manager
- How to Configure Apache Virtual Hosts on CentOS 7
- RDP File Transfer
- Create a Robots.txt File
- Introducing Cloud Sites File Manager
- How to Sync Two CentOS 8 Servers Using File Replication
How to use the “hosts” file?
The hosts file is used to map hostnames (in other words domains) to IP addresses. With the hosts file you can change the IP address that you resolve a given domain name to. This change only affects your own computer without affecting how the domain is resolved worldwide.
This is particularly useful when you wish to see how a website will look like when hosted on a different server without making any DNS changes to your domain.
The location of the hosts file, depending on the operating system that you are using, is:
- Windows – SystemRoot > system32 > drivers > etc > hosts
By default the system root is C:\Windows, so if you are using Windows, your hosts file is most probably: C:\Windows\System32\drivers\etc\hosts)
- Linux – /etc/hosts
- Mac OS X – /private/etc/hosts
Let’s say that you wish to resolve yourdomain.com to the IP address 22.214.171.124. In this case you would need to open up the hosts file with a text editor and append the following line:
|1||126.96.36.199 yourdomain.com www.yourdomain.com|
(Note: Make sure that you don’t have any # signs in front of the IP address as they will deactivate this entry)
This will “tell” your computer to resolve yourdomain.com to 188.8.131.52. Once you do that you may need to clear your web browser’s cache, afterwards, if you try to reach your domain http://yourdomain.com in a browser it should take you to the site hosted on the server with IP 184.108.40.206.
More detailed instructions on how to locate and edit the hosts file on different operating systems are available below:
Windows 8 and 10
- Press the Windows key (previously Start menu).
- Use the Search option and search for Notepad.
- Right-click Notepad and select Run as administrator.
- From Notepad, open the hosts file at: C:\Windows\System32\Drivers\etc\hosts
- Add the line and save your changes.
- Open up the Terminal.
- Use the nano command line text editor, or a different one you have available to open up the hosts file. The command with nano is as follows (the command will require your Linux user’s password):
1sudo nano /etc/hosts
- Add the appropriate changes in the hosts file.
- Use the Control and X key combination to save the changes
Mac OS X 10.6 through 10.12
You should be logged in with a user with administrator privileges on your MAC.
- Open Applications -> Utilities -> Terminal.
- Edit the hosts file with a command line text editor such as nano by typing the following line in the terminal (the command will require your Mac user’s password):
1sudo nano /private/etc/hosts
- Add your changes at the bottom of the file.
- Save the changes with the Control and X key combination.
What is the Hosts file and how to use it?
Juraj Ondrus — May 17, 2011apiapi and internalsinternalsIn this article we will explain what the Hosts file is and how to use it so you can run your web site(s) in Kentico CMS under different domain names (e.g. www.yourdomainname.com and yourdomainname.com).
What is hosts file and how to edit it
The hosts file is a computer file used in an operating system to map hostnames to IP addresses. The hosts file is a plain-text file and is traditionally named hosts.
For various reasons it may be necessary to update the hosts file on your computer to properly resolve a web site by its domain name. The most common reason for this is to allow people to view or publish web content immediately after purchasing a new domain name or transferring an existing domain name to another ISP (Internet Service Provider).
New and transferred domain names have a delay period that can be anywhere from a few hours to a few days. During this period of time the new or transferred domain information propagates around the internet, and is generally unavailable.
If you need to update your site immediately and cannot wait for the propagation of domain information around the internet, you can edit a file on your computer as a temporary work around.
Please note: this work around is only valid on the computer/server on which the change was made. It will not make the web site available to anyone on the internet.
Windows operating systems contain a file called ‘hosts’ that will force resolution of your domain name.
1. Open the hosts file
1. Go to the Start menu and choose Run. Type the following in the Run dialog box:a. For Windows NT and Windows 2000:
C:\winnt\system32\drivers\etcb. Windows XP, Windows Vista or Windows 7
C:\Windows\System32\drivers\etc2. Click the OK button (This should open a window with several files in it.)3. Find the file called ‘hosts’ and double–click it. If prompted, specify that you would like to choose a program to open the file with from a list of programs.a. Choose ‘Notepad’ from the list of available programs.2. Edit and save the hosts file
1. Start typing on a new line at the bottom of the file.
To do so, place your cursor at the very end of the last line and hit ‘Enter’ to start a new line.2. Type these two lines of text like this example:
(use your server IP address and your site domain in–place of the defaults below)
a. 220.127.116.11 yourdomainname.com
b. 18.104.22.168 www.yourdomainname.com3. Close the hosts file and save it when prompted.3. Please note: At this point you should be able to view and publish to your web site using your domain name on the computer where this change was made.
How to run multiple web sites in Kentico CMS using different domains (from hosts file)
How to run multiple web sites in Kentico CMS using domains from hosts file
In some cases you may want to run several web sites on your local computer or server on different domain names, so you do not have to switch the site off in Site Manager – for example you want to run your e-commerce site on http://myecommercesite and at the same time a community site on http://mycommunitysite.
In this case add following to the hosts file and save the change:
Now, please go to Site Manager -> Licenses tab and add license keys for the domain names you want to use for your sites (those added to the hosts file).
Next and last step is to add the domain name to the site settings in Site Manager -> Sites tab -> edit your site and add the domain name as the main “Site domain name” or on “Domain aliases” tab as a site domain alias.
After this, you can run the sites at the same time and access them under different domain names on your local computer or server (host file in windows).
Easily Edit the Hosts File in Windows 10
Most operating systems, including Microsoft Windows versions, use the hosts file to translate computer names. Also known as “host names” to numerical IP addresses, the hosts file is similar to using a phone book to find the matching phone number of a specific person’s name(host file in windows).
Note: This article was written at the time when Windows 10 was at Technical Preview build phase.
While Domain Name System – or DNS – is mostly used for this function (being a centralized and half-automatically managed name resolution system), the HOSTS file can be used as a local name resolution mechanism, and when used in conjunction with other name resolution mechanisms such as DNS, the HOSTS file takes precedence over them(host file in windows).
This is why many users still edit the HOSTS file and add names and IP addresses of servers, websites and other computers they frequently access to it (host file in windows).
Location of the Hosts File
In Microsoft operating systems, the HOSTS file is located in the following location:
How the Hosts File Works
The HOSTS file is a text file, one that does not have a file extension. It contains lines of text that are made of IP addresses followed by one or more host names or fully qualified domain names (FQDNs). Each field is separated by white space (blanks or tabulation characters) (host file in windows).
For example, if you wanted to use the HOSTS file to translate a host name of a computer called “printserver” into the IP address of 192.168.0.1, you would add this line:
You can add more than one host name to the same IP address. For example, if the computer called “printserver” also acts as a scanner called “scanserver”, you could use this line:
|1||192.168.0.1 printserver scanserver|
If you ping either “printserver” or “scanserver”, you’d get to the same IP address:
The HOSTS file can also translate Fully Qualified Domain Names (or FQDNs) of computers, such as ones used on the Internet (host file in windows).
For example, if you wanted to add a manual line to translate a FQDN of a computer called “webserver.domain.com” into the IP address of 22.214.171.124 (this is just an example, actually 126.96.36.199 is the IP address used by Google’s DNS servers), you would add this line:
When you ping it, your computer will resolve the name to the correct IP address:
You can also include comment lines by placing a hash character (#) at the beginning of the line (host file in windows).
This is how the HOSTS file looks on a Windows 10 Technical Preview build machine:
The HOSTS file may sometimes be used by malicious software such as adware, computer viruses, or trojan horses etc. (host file in windows) These applications may use it to redirect traffic from the intended destination to sites hosting malicious or unwanted content. That is why some Anti-Virus programs may monitor changes to the HOSTS file, preventing malicious software from modifying it. So does Windows, and unless you use elevated permissions to edit the file, you will be prevented from saving it (host file in windows).
How to Edit the Windows 10 Hosts File
To edit the HOSTS file we need to use a method that allows us to save the file to it’s original location, which is:
1. To do so, copy the HOSTS file to your Desktop.
2. Open the copy from your Desktop in Notepad.
3. Make all necessary changes. For example, adding a line that translates 192.168.1.1 to “kuku”. Save the copy.
4. Next, copy and paste the file to its original location.
5. You will be asked if you want to overwrite the file. Choose Replace the file in the destination.
6. Windows will ask for Administrator permissions. Click Continue.
7. The changed HOSTS file will replace successfully the original, and now, if you ping “kuku” you will get the corresponding IP address.
Published by Eric Kloeckner
Read More : Authentic Business School Overview in 2020
Read More : What is Full Stack Developer?