How To Edit Hosts File (Local Point) In Linux, Windows, Or Mac

How To Edit Hosts File (Local Point) In Linux, Windows, Or Mac

Introduction

The hosts file in Windows, Mac, or Linux maps hostnames to IP addresses. For example, an intranet, like a corporate office that has servers for users to access, or it could be domain names for servers on the internet.

Editing your hosts file can be useful if you are running tests on your network. By mapping an IP address to a server name (or domain name), you can skip the process where a web browser uses a Domain Name Server(DNS) lookup to translate the domain name to the IP address.

In this tutorial, learn how to edit hosts file on Linux, Windows, or Mac.

How to Edit Linux Hosts File

Step 1: Open a Terminal Window (Command Line)

Most Linux distributions have an applications > utilities > terminal feature, or an option to right-click the desktop and click Open Terminal.

Step 2: Open the Linux Hosts File

To open the Linux hosts file, type the command:

sudo vim /etc/hosts

Instead of Vim, you can use any other text editor, like nano.

The system should prompt for your password – enter it, and the Hosts file should open.

Step 3: Modify the File

The hosts file in Linux is formatted so that the IP address is first, and the server name is second.

0.0.0.0 server.domain.com

Add any entries you wish to the end of the file. If you make a mistake or need to tell your operating system to ignore a line, add the ‘#’ sign at the beginning of that line.


Make sure you save the file by using shift+z+z key combination before you exit.


How to Edit Hosts File in Windows

Step 1: Open Notepad as an Administrator

You’ll need administrator privileges for this operation.

  1. Click the Windows button and type “notepad.” Let the search feature find the Notepad application.

  2. Right-click the Notepad app, then click Run as administrator.

  3. Windows User Account Control should pop up asking, “Do you want to allow this app to make changes to your device?” Click Yes.

Step 2: Open the Windows Hosts File

  1. In Notepad, click File> Open

  2. Navigate to c:\windows\system32\drivers\etc

  3. In the lower-right corner, just above the Open button, click the drop-down menu to change the file type to All Files.

  4. Select “hosts” and click Open.

 

Image of opening the Windows hosts file in Notepad.

Step 3: Edit the File

The Windows hosts file is that it gives you a brief explanation of how to write a new line. Here’s a brief breakdown:

0.0.0.0 server.domain.com

The first set of four (4) digits is the IP address you’re mapping. This could be the internal IP address of a server on the network, or it could be the IP address of a website.

The second label is the name you want to be able to type in a browser to access the server at the IP address you just specified.

Image of the Windows hosts file.

Once you’re finished making your changes, save the file (File > Save) and exit.

If you make an edit to the hosts file and something stops working, you can tell Windows to ignore any line by putting a # sign at the beginning of that line.

It would look like:

# 0.0.0.0 server.domain.com

How to Edit Mac Hosts File

Step 1: Open the Mac Terminal

Open the Finder, and go to Applications > Utilities > Terminal

Type the following in the terminal window:

sudo nano /private/etc/hosts

The system should prompt you to enter your password – this is the same password you use to log in to the system. Type it in, and hit Enter.

Step 2: Edit Mac Hosts File

The IP address is first, and the server name comes second. Comments are indicated with a ‘#’ sign. Consider the example below:

0.0.0.0 server.domain.com

Enter the IP address you want to refer to first, hit space, and then the server name (or domain name) that you want to associate with it.

MacOS hosts file opened in nano.

If you make a mistake, you can tell Mac OS to ignore a line by typing a # at the beginning of that line.

Save your changes by pressing Command + O, then exit by pressing Command + X.


After that open the terminal and run the following command for the changes to take effect:

dscacheutil -flushcache



 



    • Related Articles

    • Clearing the known_hosts ssh file

      Sometimes when connecting to a computer with SSH, things can get jumbled up and an error can occur that looks like this: The purpose of the known_hosts file is for the client to authenticate the server they are connecting to. This error will occur ...
    • How to Connect to an SSH Server from Windows, macOS, or Linux

      An SSH client allows you to connect to a remote computer running an SSH server. 1. Windows The most popular and widely recommended solution for connecting to SSH servers is an open source, third-party application called PuTTY. But now with windows 10 ...
    • How to setup and install SoftEther VPN client in your windows system?

      Follow the steps below, in order to install SoftEther vpn client :  Go to the above link to download VPN-client - https://www.softether-download.com/en.aspx?product=softether From the drop down list, select software as  Soft ether VPN, component as ...
    • How to connect to ftp/sftp using filezilla?

      What is filezilla? Filezilla is a free and open source SFTP(secure FTP)/FTP client which is built on modern standards. It is available cross-platform (Mac, Windows and Linux) and is actively maintained. First you will need to download and install the ...
    • Using traceroute to troubleshoot network issues

      When you connect to a website, the traffic has to go through several intermediaries like your local router, your Internet service provider’s routers, onto larger networks, and so on. Traceroute shows us the path traffic takes to reach the website. It ...