Close Menu
Rob FaulsRob Fauls
    What's Hot

    Odoo 17- Change default email address

    March 10, 2024

    Odoo 17- Automated Install on Debian 12

    December 26, 2023

    Odoo 17- Manual Install on Debian 10/Debian 11/Debian 12

    November 8, 2023
    Facebook X (Twitter) LinkedIn
    • Home
    • VMware
      • Storage
    • Odoo
    • Linux
    • About
      • About Me
      • Privacy Policy
    Rob FaulsRob Fauls
    Home » Edit hosts file in Windows and Linux
    General

    Edit hosts file in Windows and Linux

    Rob FaulsBy Rob FaulsAugust 21, 2023Updated:August 21, 2023No Comments
    Facebook Twitter LinkedIn Email Reddit Telegram
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Table of Contents

    Preface

    There are times that your DNS server will not return the correct IP address for a particular web or other type of server. While this can be frustrating, it’s often by design. Many times, you’re in the process of migrating a website from one host to the other and need to stage the site, make sure everything is working, then “cut over” to the new host. In this article, I’ll go over this process for Windows and Linux. If you’re using Windows and would rather watch a video, you’re in luck!

    Windows

    Step1: Open Notepad in Administrator Mode

    Let’s start by opening the Start Menu and typing “Notepad”. You’ll need to right-click on the Notepad icon then select “Run as administrator”. When prompted, allow the app to make changes to your device (Click “Yes”)

    Step 2: Open Hosts file

    Now that Notepad is opened in Administrator mode, let’s open our hosts file. Select File –> Open.

    You’ll need to type “C:\Windows\System32\Drivers\etc” into the Address bar and hit enter. Next, ensure you’ve got “All Files” selected as your view. Finally, select “hosts” and click “Open” :

    Step 3: Edit the file

    Your host should have provided you with an IP address and hostname to use. In this example, I’ve used “123.123.123.123” as the IP address and “yourhostname.com” as the hostname.

    Step 4: Save your new hosts file

    Now that our changes are in place, we can save the file and open your favorite browser to make sure everything is working.
    NOTE: SSL certificates will fail, since the SSL certificates expect to be running on the “live” site, and you’re tricking your computer into looking at a different server. 

     

    Linux

    In Linux, editing the hosts file is much more straightforward than in Windows. Please open /etc/hosts using your favorite text editor. For this job, I like the simplicity of nano.

    Step 1: Open Terminal

    First, open your favorite terminal and type “sudo nano /etc/hosts”, then press enter.

    You’ll get a prompt to enter your password. Enter it then hit enter again.

    Step 2: Edit Hosts file

    Now that we’ve got the file open, we need to add the new IP Address and hostname. I’ve used 123.123.123.123 as the IP address and “yourhostname.com” as the host name:

    Step 3: Save the file

    Now that we’ve entered our new records, use ctrl+x to bring up the save prompt and then press “y” to “save modified buffer”. It will now ask for the file name to use. Press enter again to save over the old hosts file:

    Test hosts file entries

    Now that we’ve edited our hosts file, we need to make sure that we’re attempting to connect to the correct server.

    Step 1: Open a command prompt:

    Windows- Click start menu, then type “cmd” and hit enter. A box will pop up and you’ll proceed with Step 2.
    Linux- Open Terminal.

    Step 2: Test with ping

    Now that we’ve got our command prompt open, we need to run ping to make sure we’ve entered the information correctly. Using my previous example, we’re expecting the domain name/host “yourhostname.com” to resolve to “123.123.123.123”.  In your cmd/terminal prompt, type “ping yourdomain.com”. 


    NOTE:In my example, I provided a valid domain name, but a bogus IP address. The pings SHOULD fail. If yourdomain.com responds to the pings, you’ve done something wrong. No worries, just try again! If you can’t figure it out, then I’ve been a bad coach and skipped over a step. Please let me know in the comments and I’ll correct my mistake!

    Revert your changes!!!

    Once you’ve finished testing your site, you’ll want to be sure to delete the lines you’ve added in your hosts file OR comment them out by adding “#” at the beginning of the line where you made the changes. This will ensure that your computer is attempting to access the server in the same way another computer would. If you forget to revert your changes, your computer will always and forever look to the specified server and will ignore any changes you make on DNS servers.

    NOTE: I like to comment out the lines for important servers so that I have them around if I ever need them in the future. If you don’t think you’ll need the IP and server name saved in hosts for later, feel free to delete the line!

    edit hosts hosts files linux windows
    Previous ArticleChatGPT On Why It Is “Bad”
    Next Article Migrate from Github to Gitea

    Related Posts

    Odoo 17- Change default email address

    March 10, 2024

    What’s with the photos?

    September 25, 2023
    Leave A Reply Cancel Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Editors Picks
    Latest Posts

    Odoo 17- Change default email address

    March 10, 2024

    Odoo 17- Automated Install on Debian 12

    December 26, 2023

    Odoo 17- Manual Install on Debian 10/Debian 11/Debian 12

    November 8, 2023

    Subscribe to Updates

    Get the latest content from Rob.

    I've worked in IT for over 20 years, servicing Government, Healthcare, and Private Sector customers. This is a relatively new adventure into blogging, mostly out of a realization that I need to organize some of my notes on various subjects. Hopefully the articles posted will help others along the way.

    You can connect with me here:

    LinkedIn X (Twitter) Facebook

    Subscribe to Updates

    Keep up to date with new articles posted about 'stuff and things'.

    © 2025 Rob Fauls. Hosted by Flatiron Networks.
    • Home

    Type above and press Enter to search. Press Esc to cancel.