JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

How to Find IP Address from Host Name in Windows Linux and Unix

Author:JIYIK Last Updated:2025/04/06 Views:

How many times in a day do we have a hostname and want to know the IP address? While dealing with network commands in Unix, hostname to IP address and IP address to hostname conversion is one of the common things we need to do for many things. For one command we need an IP address and for other we need a hostname, even from a bash script, sometimes we need a hostname and sometimes we need an IP address.

Network commands are not as popular as find or grep, but they are equally important and you must learn them if you work in Windows or UNIX environment, and they should also be included in any list of Unix commands for beginners.

By the way, in this hostname to IP address article, I will show you how to get the IP address from the hostname or computer name in Unix or Linux, and how to get the hostname if you have an IP address. If you are looking for a way to do this through a Java program, you can also check out our article on how to find the IP address of the local host using Java .


Finding an IP address from a host name in UNIX and Linux Examples

If we work in UNIX network and have many machines in LAN (Local Area Network), then many times we want to know the IP address of a computer from its host name.

Here are the top 4 ways to get IP address from hostname in Linux or UNIX machines

1) Use the hostname command to obtain the IP address in Unix/Linux

$ hostname -i

This is the simplest way to find the IP address of a machine, but the limitation is that sometimes this option may or may not be available on your UNIX machine, for example, you can hardly find this command on Solaris and IBM AIX, but they are mostly available on Linux servers. Also, one limitation of hostname is that we cannot find the IP address of any other machine. It is like finding the IP address of the local host.

2) Use the ping command to obtain the IP address in UNIX or Linux

$ ping jiyik
Pinging jiyik.com [192.24.112.23] with 32 bytes of data:
Reply from 192.24.112.23: bytes=32 time<1ms TTL=128
Reply from 192.24.112.23: bytes=32 time<1ms TTL=128
Reply from 192.24.112.23: bytes=32 time<1ms TTL=128

pingIt is another simplest way to find the IP address of the local host or any other host in the network, if we know the host name or computer name, we can just ping it and it will display the IP address associated with it. Usually pint command is used to check if the host is alive and connected to the network.

In the example above, the IP address associated with trading_system is "192.24.112.23." The disadvantage of using the ping command is that you cannot convert the IP address back to a host name.

3) Use nslookup command to get IP address in UNIX or Linux

$ nslookup jiyik
Name:    jiyik.com
Address:  192.24.112.23

nslookupis my favorite command to get IP address from hostname, it is very powerful and also available in many UNIX operating systems like Linux, Solaris, IBM AIX, Ubuntu or BSD. Another advantage of nslookup command is that we can get IP address from hostname or hostname from IP address.

It can also be used to find the IP address of our own host or any other machine in the network. In nslookupthe example above, we displayed the IP address associated with jiyik. If you want to find the hostname from the IP address, you can just provide the IP address instead of the hostname

4) How to find IP address using ifconfig command

ifconfigis another network utility in UNIX or Linux that can be used to find the IP address of a UNIX machine. ifconfig displays a lot of information, so I'm just going to look up the IP address ineton grepIn the example below, the IP address associated with "jiyik.com" is "192.24.112.23".

$ /sbin/ifconfig -a | grep inet
inet 192.24.112.23 netmask ffffff00 broadcast 192.24.112.255

Find IP address from hostname command in Windows Linux and Unix


IP addresses for hostnames in Windows, Linux, and Unix

Now, let's look at some examples of converting host names to IP addresses in Windows, Linux, and other UNIX-based systems.

1. How to find your computer's IP address in Windows

Surprisingly, some of the examples above for finding an IP address from a hostname will work on Windows. We can use ipconfig pingand ifconfig in exactly the same way as shown above nslookup. There is even a hostname command available in the Windows Command Prompt, but I doubt the options hostname -i. Another change is that ifconfigin the command ipconfig is used instead of ifconfig to find a computer's IP address in Windows.

How to Find Your IP Address Using the ipconfig Command in Windows

Here is an example of using the ipconfig command in Windows to find our computer's IP address:

C:\Documents and Settings\jiyik>ipconfig
Windows IP Configuration
Ethernet adapter Local Area Connection:

        Connection-specific DNS Suffix  . : jiyik.com
        IP Address. . . . . . . . . . . . : 192.24.112.23
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.24.112.254

2. How to find the external IP address of a network or computer

If you are in a LAN, all of the above examples will show the internal IP address. If you are already connected to the Internet and want to know the external IP address assigned to us by the service provider, there are many websites that can let us know the IP address, such as ip.onmpw.com. Just log in to visit this site and it will show the IP address. If you have an IP address and want to know the location, you can also get it from the Internet.

That's it for our nice little tips on converting IP addresses to hostnames and back from hostnames to IP addresses. If you have other ways to find the IP addresses and hostnames of local and remote machines, please let us know.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Restart PostgreSQL in Ubuntu 18.04

Publish Date:2025/04/09 Views:72 Category:PostgreSQL

This short article shows how to restart PostgreSQL in Ubuntu. Restart PostgreSQL Server in Ubuntu You can restart Postgres server in Ubuntu using the following command. Order: sudo service postgres restart Sometimes the above command does n

Issues to note when installing Apache on Linux

Publish Date:2025/04/08 Views:78 Category:OPERATING SYSTEM

As the most commonly used web server, Apache can be used in most computer operating systems. As a free and open source Unix-like operating system, Linux and Apache are a golden pair. This article will introduce the installation and use of A

How to decompress x.tar.xz format files under Linux

Publish Date:2025/04/08 Views:186 Category:OPERATING SYSTEM

A lot of software found today is in the tar.xz format, which is a lossless data compression file format that uses the LZMA compression algorithm. Like gzip and bzip2, it supports multiple file compression, but the convention is not to compr

Summary of vim common commands

Publish Date:2025/04/08 Views:115 Category:OPERATING SYSTEM

In Linux, the best editor should be vim. However, the complex commands behind vim's powerful functions also make us daunted. Of course, these commands do not need to be memorized by rote. As long as you practice using vim more, you can reme

Detailed explanation of command return value $? in Linux

Publish Date:2025/04/08 Views:58 Category:OPERATING SYSTEM

? is a special variable. This variable represents the return value of the previous command. That is to say, when we run certain commands, these commands will return a code after running. Generally, if the command is successfully run, the re

Common judgment formulas for Linux script shell

Publish Date:2025/04/08 Views:159 Category:OPERATING SYSTEM

In shell script programming, predicates are often used. There are two ways to use predicates, one is to use test, and the other is to use []. Let's take a look at how to use these two methods through two simple examples. Example 1 # test –

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial