Several DNS lookup utilities provide name and IP address resolution from the command line. The host and nslookup commands are two commonly installed utilities.
The host command lists all of the IP addresses attached to a domain name:
$ host google.com google.com has address 64.233.181.105 google.com has address 64.233.181.99 google.com has address 64.233.181.147 google.com has address 64.233.181.106 google.com has address 64.233.181.103 google.com has address 64.233.181.104
The nslookup command maps names to IP addresses and will also map IP addresses to names:
$ nslookup google.com Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: Name: google.com Address: 64.233.181.105 Name: google.com Address: 64.233.181.99 Name: google.com Address: 64.233.181.147 Name: google.com Address: 64.233.181.106 Name: google.com Address: 64.233.181.103 Name: google.com Address: 64.233.181.104 Server: 8.8.8.8
The last line in the preceding command-line snippet corresponds to the default name server used for resolution.
It is possible to add a symbolic name to the IP address resolution by adding entries into the /etc/hosts file.
Entries in /etc/hosts follow this format:
IP_ADDRESS name1 name2 ...
You can update /etc/hosts like this:
# echo IP_ADDRESS symbolic_name>> /etc/hosts
Consider this example:
# echo 192.168.0.9 backupserver>> /etc/hosts
After adding this entry, whenever resolution to backupserver occurs, it will resolve to 192.168.0.9.
If backupserver has multiple names, you can include them on the same line:
# echo 192.168.0.9 backupserver backupserver.example.com >> /etc/hosts