Modifying hosts file on Debian and Windows

By jeffmackinnon


If you are self-hosting apps on your local network, that you also want to access from the external world, like I do with my webarchive then you may have challenges getting your DNS to work properly.

One way to do this is to host your own DNS server and point everything internally to that, but it can be a pain, especially when you are mixing local and external on the same root domain.

The easier way, that works for desktops and servers, is to manually adjust your hosts file.

Debian hosts file

The debian hosts file lives at /etc/hosts.

To get started you need to open the file with superuser privledges with your favourite text editor. For this example I will use nano

sudo nano /etc/hosts

Then in that file update with the IP and URL that you are trying to re-direct

If you have multiple domains on the same IP you can either add them to multiple lines, or add them to the same line with a Q-Space

Windows hosts file

It is the exact same for windows, except the file location is different.

The windows hosts file is located at c:\Windows\System32\Drivers\etc\hosts

I typically will typically open Notepad as administrator (right click and then click "Run as Administrator") and then open the file.

Add the same information as above, and reset your network connection. Sometimes it will take a restart and a cache clearing to work properly.