The getting IP address either on Linux or Unix operating system (e.g Solaris, Ubuntu, RHEL, debian etc) is not much difficult. When I say, not difficult, it means you know this. There are different way to get or find IP address in any operating system, whether it is UNIX or Linux or windows, I’m working here on Linux operating system, that is why, will demonstrate on LINUX OS (Operating System). Following are the different way to get IP Address of your hostname or computer name, or domain name or sub-domain name.
1. How to get IP Address from hostname in Linux Or Unix?
If you are sysadmin , most of the time you have to get ipaddress from hostname. if you are developer, you have to find IP address sometimes. Its very important to know , how to get IP address if you know hostname by using command. Although, there can be another command I tried to explain in simple term about getting of IP address from
hostname -i mongodb1
Here, mongodb1 is the hostname of a server , but don’t know the its IP address.
[root@mongodb4 ~]# hostname -i mongodb1 10.0.7.62 [root@mongodb4 ~]#
2. How to get IP address using using ping command in UNIX/Linux?
Usually, ping command is used to check whether host is alive or not. If you know hostname or computername or domain name you can get IP address in the output of ping command.
PING mongodb1 (10.0.7.62) 56(84) bytes of data. 64 bytes from mongodb1 (10.0.7.62): icmp_seq=1 ttl=64 time=0.910 ms 64 bytes from mongodb1 (10.0.7.62): icmp_seq=2 ttl=64 time=0.197 ms 64 bytes from mongodb1 (10.0.7.62): icmp_seq=3 ttl=64 time=0.200 ms 64 bytes from mongodb1 (10.0.7.62): icmp_seq=4 ttl=64 time=0.202 ms 64 bytes from mongodb1 (10.0.7.62): icmp_seq=5 ttl=64 time=0.204 ms 64 bytes from mongodb1 (10.0.7.62): icmp_seq=6 ttl=64 time=0.208 ms 64 bytes from mongodb1 (10.0.7.62): icmp_seq=7 ttl=64 time=0.202 ms 64 bytes from mongodb1 (10.0.7.62): icmp_seq=8 ttl=64 time=0.213 ms ^C --- mongodb1 ping statistics --- 8 packets transmitted, 8 received, 0% packet loss, time 7086ms rtt min/avg/max/mdev = 0.197/0.292/0.910/0.233 ms [root@mongodb4 ~]# ^C [root@mongodb4 ~]#
3. How to get IP address using nslookup command in UNIX/Linux?
nslookup is utility tool in the UNIX or Linux environment which is basically used to get IP address for the host. This works in all UNIX Operating system: Linux, Ubunto, RHEL, Solaris etc. The beauty of this nslookup command is, you can get hostname from IP address and IP address fron hostname vice-versa.
[root@mongodb4 ~]# nslookup google.com Server: 10.0.10.10 Address: 10.0.10.10#53 Non-authoritative answer: Name: google.com Address: 18.104.22.168 [root@mongodb4 ~]#
On window environment
C:\Users\ranjeet>nslookup mysoftkey.com Server: UnKnown Address: 192.168.0.1 Non-authoritative answer: Name: mysoftkey.com Address: 22.214.171.124
4. How to get IP address using ifconfig command?
ifconfig is a utility command in the UNIX or Linux environment which is basically provide IP address of system.
/sbin/ifconfig -a | grep inet
ifconfig -a | grep inet
[root@mongodb4 ~]# ifconfig -a | grep 'inet addr' inet addr:10.0.8.20 Bcast:126.96.36.199 Mask:255.254.252.0 inet addr:127.0.0.1 Mask:255.1.0.0 [root@mongodb4 ~]#