Understanding Name Service Switch in Linux
Before moving any further, you should understand a few things about another important file that is /etc/nsswitch.conf. It provides Name Service Switch functionality which controls the order in which services are queried for name service lookups.
The configuration is based on order; if files is before dns it means the system will query the /etc/hosts file before checking DNS for name service requests. But if DNS is before files then the domain lookup process will consult DNS first before any other appropriate services or files.
In this scenario, we want to query the “files” service. To check the order, type.
$ cat /etc/nsswitch.conf OR $ grep hosts /etc/nsswitch.conf
Configure DNS Locally Using /etc/hosts File in Linux
Now open the /etc/hosts file using your editor of choice as follows
$ sudo vi /etc/hosts
Then add the lines below to the end of the file as shown in the screen shot below.
192.168.56.1 ubuntu.tecmint.lan 192.168.56.10 centos.tecmint.lan
Next, test if everything is working well as expected, using the ping command from Host 1, you can ping Host 2 using it domain name like so.
$ ping -c 4 centos.tecmint.lan OR $ ping -c 4 centos