Since a hostname can have multiple IP address, its better to use a DNS lookup utillity like host or nslookup.
Here is how you can use 'host' command : host google. Thanks Anonymous, this is seriously good information. We recently have a problem where we migrated machine to new infrastructure. Most of things went fine but one of the host in infrastructure was still resolving to old IP address.
After much debugging it turns out the stale entry in nscd, a daemon which provide cache for most common name service requests.
Once the nscd was restarted in problematic host the issue was resolved and hostname was resolved to new IP address. Pages Home core java thread java 8 array coding string sql books j2ee oop collections data structure interview certification. Unix command to find IP address from hostname - Linux example. You always need either hostname or IP address to connect to any host. Sometimes you want to find the IP address of the localhost, some time IP address of another host on the network, etc.
We have shown some techniques to find the IP address from hostname in UNIX and here we will see is a particular list of UNIX commands to get the IP address of localhost or host on which you are working along with any other host for which we know hostname. Let's see an example of ifconfig command to find The IP address of localhost on which you are working :. As I said ifconfig command shows a lot of details but I have only included relevant inet one if you have more than one network card attached to that host, you may see more than one inet address corresponding to each of them.
The main drawback of ifconfig command in UNIX is that you can only get the IP address of localhost from this command, you can not get the IP address of any other host.
Our plain old ping command can also be used to find the IP address of the localhost or any other host provided you know the hostname. Even if you don't use it directly, when you type website-name. Let's divide IP addresses into two categories: private and public. Private IP addresses are the ones your WiFi box and company intranet provide. They are in the range of Public IP addresses, as the name suggests, are "public" and you can reach them from anywhere in the world.
Kevdog 2, 13 13 gold badges 36 36 silver badges 61 61 bronze badges. This is available from the netifaces package. Additional menu. I thought to myself it could be done by accessing the router with an Windows Laptop, but I dont know my neighbours too well to borrow one. Hot Network Questions. Moreover, the IP address also specifies the location of a device. IP address gives an identity to your device so that you can recognize it whenever you want to.
Every website has a unique IP address that can be reached by anyone and from anywhere; that is considered a public IP address. IPv4 addresses have the format x. IPv6 addresses have a more complex format using hex numbers.
In this Unix command tutorial, we will see how to find the IP address of any host in a UNIX based system, e.g. Linux, Solaris, or IBM AIX. In general hostname. try this code to see the IP address of unix machine nslookup mach_name.
IPv6 was introduced to tackle the foreseeable exhaustion of IPv4 addresses in the near future. All the devices connected to the same WiFi have private IP addresses locally identified by the range provided above.
For example, my laptop is connected with the IP address These are private IP addresses, but both would have the same public IP address. The following commands will get you the IP address list to find public IP addresses for your machine:.
Note: Some utilities need to be installed on your system based on the Linux distro you are using. Also, some of the noted commands use a third-party website to get the IP. Every website has a unique, public IP address that can be reached by anyone and from anywhere.
Image credits :.
Get the highlights in your inbox every week. More Linux resources.
Linux commands cheat sheet Advanced Linux commands cheat sheet Linux networking cheat sheet SELinux cheat sheet Linux common commands cheat sheet What are Linux containers? Our latest Linux articles.
Topics Linux. About the author. Archit Modi - OpenStack enthusiast.
Linux and Networking guy.