How to add additional dns host mapping to localhost

Why we need additional dns host mapping?

In enterprise environments, some applications can serve into multiple domains. For example, same running instance(s) can be mapped for guest.example.com and customer.example.com and the functionality of the application could vary based on the domain being used by the user. Lets say, customer.example.com will need authentication, authorization and may contain premium features for customers, whereas guest.example.com will contain limited features.

To test this type of application in local, which contains domain aware functionalities, we need to map additional routes in the OS host file to map these domains to localhost. And then the tests can make use of these domains to test the application running in local development machine.

For Mac:

Add the following lines to /private/etc/hosts file using vi or nano or any text editor application. Might need to use sudo if required.

127.0.0.1       local.example.com
127.0.0.1       local.example.org

Refresh the cache by executing the command in Terminal

dscacheutil -flushcache

Test the changes using ping

ping local.example.com
ping local.example.org

For Windows:


Run notepad with administrator privileges and add the following lines to C:\\Windows\System32\Drivers\etc\hosts file.

127.0.0.1       local.example.com
127.0.0.1       local.example.org

Test the changes using ping from command prompt

ping local.example.com
ping local.example.org

For Ubuntu (Linux):


Add the following lines to /etc/hosts file using vi or nano or any text editor application. Might need to use sudo if required.

127.0.0.1       local.example.com
127.0.0.1       local.example.org

Refresh the cache by executing the command in Terminal

service networking restart

Test the changes using ping

ping local.example.com
ping local.example.org

Comments

Popular posts from this blog

JSON with curl and jq

Import self signed in Linux for Chrome / Chromium headless testing

Colima - Drop In replacement for Docker Desktop for Mac and Linux