IP mapping to DNS on your local machine

Recommended for hackathon projects

You probably ran into scenarios where you set up a web app on cloud (AWS, Azure, GCP, Digital Ocean etc.,) and you get an IP address to access it from browser. For the most part you dont need to worry about Domain name routing until you figure out actual idea implementation. Presenting it to judges with IP number is pretty lame. The easiest hack to make it look better is to make local domain name point it to your IP. (This works only on your machine, and that is fine for a hackathon :) )

Background: Here is what happens when you hit enter after copying IP address on the address bar.

  1. The browser even before hitting the web reaches out to hosts file which is at ‘/etc/hosts’ in Unix and in @C:\Windows\System32\drivers\etc\hosts in Windows.
  2. It checks if there are any IP mappings defined to domain names.(This is where we hack)
  3. If IP mappings are not defined, the browser will then hit the web.

Lets see how we can accomplish this on windows. In order to do that you should have admin access on your machine.

Open CMD and open ‘notepad’

navigate to this file location @C:\Windows\System32\drivers\etc\hosts

Open file @C:\Windows\System32\drivers\etc\hosts and add a line at the bottom as seen in the screen shot below.

That’s it. Go to the browser and type the dummy URL you mapped to an IP address and see the magic.

Learner, thinker and Doer.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store