How to visit same domain on different IP when migrating

Last edited:
October 29, 2023
Reading time:
6 mins
Topic:
Migration

/

Blog

/

Development

/

How to visit same domain ...

đź’ˇWe may earn a commision if you subscribe to a service from a link on this page.

Migrating a website from one server to another is a common occurrence for website administrators, developers, and IT professionals. However, during this migration process, there is often a period of time when the website is not yet accessible to the audience due to DNS propagation delays or other reasons. In such scenarios, you may want to access the migrated website on the new server to test, troubleshoot, or ensure everything is functioning correctly before the public can access it. This can be achieved by editing your computer’s hosts file, which allows you to associate a domain with a specific IP address. In this comprehensive guide, we will walk you through the process of editing the hosts file on Windows, macOS, and Linux, enabling you to visit a domain that is not yet pointed to the domain’s nameservers.

Why Edit the Hosts File?

Before delving into the details of how to edit the hosts file, let’s understand why it’s necessary in certain scenarios:

1. DNS Propagation Delays after WordPress migration:

When you migrate your website to a new server or change your hosting provider, DNS propagation can take some time. During this period, some users may still be directed to the old server, while others reach the new one. Editing the hosts file allows you to bypass DNS and visit the new server directly.

2. Staging and Testing:

Web developers often use staging or testing environments to make changes to a website before deploying them to the live server. Accessing the staging site via the hosts file ensures that you are testing on the correct server.

3. Previewing New Features:

If you’re rolling out new features or changes to your website, editing the hosts file lets you preview these changes without affecting the live site until you’re ready.

4. Troubleshooting:

In the event of website issues after migration, being able to access the new server via the hosts file can help diagnose and fix problems more efficiently.

Now that we understand the importance of editing the hosts file, let’s proceed with step-by-step instructions for Windows, macOS, and Linux.

Editing the Hosts File on Windows:

1. Open Notepad as an Administrator:

  • To open Notepad as an administrator, search for “Notepad” in the Windows Start menu, right-click on it, and choose “Run as administrator.” This is essential for editing system files.

2. Access the Hosts File:

  • In Notepad, go to File > Open and navigate to C:\Windows\System32\drivers\etc. In the “File name” field, enter hosts (without quotes) and click “Open.”

3. Edit the Hosts File:

  • Add a new line at the end of the file, following this format:
    IP_Address Domain_Name
    IP_Address Domain_Alias
    

    Replace IP_Address with the IP address of your new server and Domain_Name with the domain you want to visit.

4. Save the File:

  • After making the necessary changes, save the hosts file by going to File > Save.

5. Flush DNS Cache:

  • To ensure your changes take effect immediately, open the Command Prompt as an administrator and run the following command:
    ipconfig /flushdns

Now, you should be able to access the website associated with the new server’s IP address, even if DNS propagation is still in progress.

Editing the Hosts File on macOS:

1. Open Terminal:

  • To open Terminal, you can search for it in Spotlight or find it in the Utilities folder within the Applications folder.

2. Access the Hosts File:

  • In Terminal, enter the following command to open the hosts file in the nano text editor:
    sudo nano /etc/hosts
  • You’ll be prompted to enter your password.

3. Edit the Hosts File:

  • Similar to Windows, add a new line at the end of the file with the format:
    IP_Address Domain_Name
    IP_Address Domain_Alias
    

    Replace IP_Address with the new server’s IP address and Domain_Name with the domain you want to visit. Make sure you include the proper format and the domain alias:

4. Save and Exit:

  • To save your changes in nano, press Ctrl + O, then press Enter. To exit, press Ctrl + X.

5. Clear DNS Cache:

  • To clear macOS’s DNS cache and apply your changes immediately, run the following command in Terminal:
    sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Now, you should be able to access the website on the new server using the specified domain.

Editing the Hosts File on Linux:

1. Open Terminal:

  • Access Terminal on your Linux distribution. The process may vary slightly depending on your distribution (e.g., Ubuntu, CentOS, etc.).

2. Access the Hosts File:

  • In the Terminal, open the hosts file using a text editor with superuser privileges. The location of the hosts file may vary, but it’s usually found in /etc/hosts. You can use a command like this:
    sudo nano /etc/hosts

3. Edit the Hosts File:

  • As with Windows and macOS, add a new line at the end of the file, following this format:
    IP_Address Domain_Name
    IP_Address Domain_Alias
    

    Replace IP_Address with your new server’s IP address and Domain_Name with the domain you want to access. Remember to include the domain alias:

4. Save and Exit:

  • In nano, to save your changes, press Ctrl + O, then press Enter. To exit, press Ctrl + X.

5. Clear DNS Cache (if needed):

  • Some Linux distributions don’t require manual DNS cache flushing. However, you can restart your networking service or your computer to ensure the changes take effect.

Restart your router if anything else does not work

if you’ve edited your computer’s hosts file to access a specific IP address for a domain, but you’re still unable to reach the desired website, restarting your router can be an additional troubleshooting step. Sometimes, routers can cache DNS information, and a reboot can help clear this cache and apply the hosts file changes more effectively.

Here are the steps to restart your router:

  1. Find Your Router: Locate your router physically. It’s typically a small device connected to your internet modem. It may have antennas and indicator lights.
  2. Turn Off the Router: Usually, there’s a power button on the back or side of the router. Press it to turn off the router. Wait for about 10-15 seconds.
  3. Unplug the Router: If there’s no power button, or if the router has an external power adapter, unplug it from the power source.
  4. Wait: Leave the router unplugged or powered off for at least 30 seconds to ensure that it fully resets.
  5. Turn On/Plug In the Router: Reapply power to the router by either pressing the power button again or plugging it back in. Wait for it to fully restart, which may take a few minutes. You’ll typically see the indicator lights stabilize when the router is ready.
  6. Test Access: After the router has restarted, try accessing the website using the modified hosts file again. This time, the changes should take effect without any issues.

Remember that restarting the router should be one of the final troubleshooting steps after editing the hosts file, as it may briefly interrupt your internet connection for all devices connected to the router. Additionally, ensure that you’ve correctly edited the hosts file and that your computer’s DNS cache has been flushed before resorting to router restarts.

Visit your domain on different IPs!

By following the above steps, you can edit the hosts file on your Windows, macOS, or Linux system and temporarily associate a domain with a specific IP address. This allows you to access your website on a new server or staging environment, even before DNS propagation is complete. Remember to remove or comment out the entry from the hosts file once DNS propagation is finished and the website is accessible to everyone. Stay safe and keep pointing to the right IP addresses!

Leave a Reply

Your email address will not be published. Required fields are marked *