I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

How to add a local DNS entry on Linux

Hello, friends. In this short but interesting post, you will learn how to add a local DNS entry on Linux. Let’s get started.

As we all know, DNS servers are responsible for translating IP addresses into a domain name easier to remember by humans. So, we don’t have to learn by heart IP addresses, but only the domain name associated with them.

Although DNS is a decentralized system, the truth is that there are some critical DNS servers, such as those of Google or Cloudfare.

However, on some occasions and sometimes for testing purposes or in very internal environments, it is convenient to add a DNS entry locally. This way, without the need to use one on the Internet, we can resolve names.

Remember that this is for testing purposes and should not be the norm in professional environments.

Let’s go.

How to add a local DNS entry on Linux

On Linux systems, we can make local entries using the /etc/hosts file, which is simple to understand.

If you display it, it will look something like this

Add a local DNS entry on Linux
Add a local DNS entry on Linux

As you can see, there is not much trick with the file since you only have to add the entries with this format

[ip-address] [domain]

Just like that. For example:

Save the file and you are done. Internally for our computer, the IP address will be associated to the domain

What happens then if the specified domain exists on the Internet? Well, the local file will have higher priority. Then you have to make sure that the local domain does not really exist and avoid browsing problems.

Another aspect that is good to keep in mind here, is that I have not added http or https because those protocols do not work in DNS. Keep in mind that DNS encompasses all communication, while those protocols are web-only.

In case you want to revert the changes, you can delete or comment the entry and save the file.


In this short post, you learned how to add a local DNS entry on Linux. The process is simple but allows you to create a simulated DNS environment for testing.


Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook