How can I temporarily override a domain name resolution without using the hosts file?

10,075

Solution 1

Editing the hosts file (with notepad.exe) is really the easiest and quickest way in Windows to override hostname resolution. Command line alternatives will be more long-winded and complex.

If you want it to stay temporary just keep the hosts file open and just hit save once you've made changes.

Solution 2

Access it using the ipaddress or use a domain name that is unique. All links within the website should be relative otherwise the Site would also break if hosted on another domain.

Share:
10,075

Related videos on Youtube

Samuel
Author by

Samuel

Updated on September 18, 2022

Comments

  • Samuel
    Samuel over 1 year

    I have 2 versions of the same website located on different IPs -- one is production, and one is staging.

    The production server: is managed completely by Site5. DNS is done so that foo.com resolves to Site5's servers and they take care of the rest.

    The staging server: is an EC2 instance and Apache is set up with a name-based virtual host, foo.com.

    As a developer, when I need to work on the staging version, I change my hosts file so that:

    foo.com    1.2.3.4    # the elastic IP associated with my EC2 instance
    

    so when I am in my browser and I visit foo.com, I see the staging version. I comment out the line when I want to see the production version.

    This is all fine for me, but others on the team are not as tech savvy and are scared of the Terminal.

    Is there a better way of doing this, preferably a method that doesn't require diving into the Terminal or other "scary stuff"?

    Perhaps a proxy server they can choose to use/not use when they want to see/not see the staging version?

  • Samuel
    Samuel about 12 years
    Unfortunately, the website is wordpress and links aren't relative. There are ways to rename the domain name from within wordpress, but it's a big pain and adds to the complexity when migrating between staging and production.
  • Samuel
    Samuel about 12 years
    Yes, I do agree it is easy to change hosts. But I'm looking for a better solution that doesn't change the file, because changing hosts requires admin privileges and is in general, a pain.
  • BloodyIron
    BloodyIron about 12 years
    If you don't have local admin privileges you are unlikely to be able to override local resolution on the system. You will need to "man-in-the-middle" between your computer and what I assume is your corporate network with a router to override resolution per domain. Default router firmware will not provide specific DNS entries, so you will need to look at routing suites such as DD-WRT or PFSense to give you the level of control you need. However your corporate network will likely pick up on the rogue router.
  • Samuel
    Samuel about 12 years
    Right, I was thinking along the same lines - hence, I'm wondering if a proxy server acting as "man-in-the-middle" would suffice instead of a rogue router? Or a reverse proxy of some sort?
  • BloodyIron
    BloodyIron about 12 years
    If you don't have local admin you are unlikely to have the ability to change your local network settings, or install applications such as a proxy or VPN, due to the level of changes they would need to make to the environment. However if you man-in-the-middle with a router, that's something the operating system can't lock you out of unless you have static IP settings, which you can still work around.