How to get IP Address in Linux or Unix?

Connect with

Get IP address in LinuxHow to get IP address in Linux is simple and straight forward command either on Linux or Unix operating system (e.g Solaris, Ubuntu, RHEL, debian etc).


When I say, not difficult, it means you know this. There are different way to get or find the 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 ways to get the 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 a sysadmin, sometimes you have to get an IP address from hostname. if you are a developer, you have to find an IP address sometimes. It’s very important to know, how to get an IP address if you know the hostname by using a command. Although there can be another command, I tried to explain in simple terms about getting an IP address from hostname.

hostname -i mongodb1

Here, mongodb1 is the hostname of a server , but don’t know the its IP address.

Output:

[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

console output:

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.

nslookup google.com

console output:

[root@mongodb4 ~]# nslookup google.com
Server:         10.0.10.10
Address:        10.0.10.10#53

Non-authoritative answer:
Name:   google.com
Address: 216.58.197.78

[root@mongodb4 ~]#

On window environment

nslookup mysoftkey.com

console output:

C:\Users\ranjeet>nslookup mysoftkey.com
Server:  UnKnown
Address:  192.168.0.1

Non-authoritative answer:
Name:    mysoftkey.com
Address:  103.1.174.1

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

Or

ifconfig -a | grep inet

Output:

[root@mongodb4 ~]# ifconfig -a | grep 'inet addr'
          inet addr:10.0.8.20  Bcast:11.0.19.255  Mask:255.254.252.0
          inet addr:127.0.0.1  Mask:255.1.0.0
[root@mongodb4 ~]#

Happy learning! 🙂 for how to get IP address in Linux.


Connect with

Leave a Comment

Your email address will not be published. Required fields are marked *