IP Address from hostname in Windows and Linux
How many times in a day you have a hostname and you want to know the IP address? Host name to IP address and IP address to hostname conversion is one of frequent thing which we need to do for many things when dealing with networking command in unix. For one command we need IP address for other we need hostname even from bash script some time we require hostname and some time we look for IP address. networking commands are not as popular as find command or grep command but they are equally important and if you working in Windows or UNIX environment you must learn them and they should also be included in any list of Unix commands for beginners. By the way In this hostname to IP address tutorial I will show you how to get IP address from hostname or computer-name in Unix or Linux and how to get hostname if you have IP address. If you are looking a way to do it via Java program then you can also see my post how to find IP address of localhost in Java.
Finding IP address from hostname in UNIX and Linux
If you are working in UNIX network and have lots of machine in LAN (Local Area network), many times you want to know IP address of computers from hostname. Here are top 4 ways of getting IP address from hostname in Linux or UNIX machine
This is the easiest way of finding IP address of your computer but limitation is that sometime this option may or may not available in your UNIX machine e.g. I hardly find this command on Solaris and IBM AIX machines but they are mostly available on Linux Servers. also limitation of hostname is that you can not find IP address of any other machine. It's like finding IP address of localhost.
ping is another simplest way of finding IP address of localhost or any other host in network, if you know the hostname or computer-name just ping and it will display IP address associated with it. Normally pint command is used to check if a host is alive and connected with network. In above example IP address associated with trading_system is "192.24.112.23". Disadvantage of using ping command is that you can not convert IP address back to hostname.
nslookup is my favorite command for getting IP address form hostname, its very powerful and also available in many UNIX operating system e.g. Linux , Solaris, IBM AIX, Ubuntu or BSD. Another advantage of nslookup command is that , we can get either from hostname to IP address or from IP address to hostname. It can also be used to find IP address of your own host or any other machine in the network. In above example of nslookup we have displayed IP address associated with trading_system. If you want to find hostname form IP address you can just provide IP address instead of hostname
ifconfig is another networking utility in UNIX or Linux which can be used to find IP address of your UNIX machine. ifconfig shows lot of information so I just grep on inet to find the IP address in below example, IP address associate with "trading_system.com" is "192.24.112.23".
IP Address from hostname in Windows Linux and Unix
How to find IP address of your computer in Windows
How to find external IP address of your network or computer
All above example will show your internal IP address if you are inside a LAN. If you have connected with internet and want to know your external IP address assigned by your service provider there are lots of website which will let you know your IP address e.g. ipchicken.com just logging into this site and it will show you your IP address and location. If you have an IP address and wanted to know about location you can also get it from internet.
How to improve speed and productivity in Unix
Difference between Hard link and soft link in Unix
Top 30 UNIX command interview questions asked in Investment banks
10 example of using VI Editor in Unix
10 xargs command example in Linux and UNIX
How to create archive in UNIX using tar command
How to sort output of a command in UNIX and Linux
Hi,
ReplyDeleteUseful java program. Very well explained. Thanks for sharing.
Cheers,
http://www.flowerbrackets.com/getting-ip-address-of-current-machine-using-java-program/