Enumerate the hosts database.
Display hosts database.
$ cat /etc/hosts
127.0.0.1 localhost 127.0.1.1 milosz-IdeaCentre-5-14IOB6 172.16.0.200 dell 172.16.254.254 desktop desk 192.168.56.4 example.org
Enumerate hosts database.
$ getent hosts
127.0.0.1 localhost 127.0.1.1 milosz-IdeaCentre-5-14IOB6 172.16.0.200 dell 172.16.254.254 desktop desk 192.168.56.4 example.org
Display specific host.
$ getent hosts desk
172.16.254.254 desktop desk
Check exit code to determine if host is already defined.
$ getent hosts desk >/dev/null; echo $?
0
$ getent hosts nonexistentdesktop >/dev/null; echo $?
2