Problem
How to get a list of enabled entries in Linux hosts file?
Sometimes, as system administrators, you need to check the list of enabled entries in a Linux system’s /etc/hosts file. Generally, we check the list of enabled host entries by checking the /etc/hosts file using the cat command and then verify the enabled entries.
[root@dbappweb ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 127.0.0.1 localhost localhost.localdomain localhost6 localhost6.localdomain6 #10.20.2.10 server1.dbappweb.com 10.40.1.11 server2.dbappweb.com #10.40.1.12 server3.dbappweb.com 10.30.2.30 server4.dbappweb.com
Solution
You can list out the only enabled entries in the /etc/hosts file using the getent command as shown below:
[root@dbappweb ~]# getent hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 127.0.0.1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.40.1.11 server2.dbappweb.com 10.30.2.30 server4.dbappweb.com
Related Posts
- Whitelist a Range of IP Addresses in Linux
- chroot SFTP User and Bind Mount in Linux
- Linux: Count number of files inside a directory including its subdirectories
- Disable SSH Weak Algorithms Supported in Linux
Last Updated: September 07, 2023