Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the ip address of the server in linux?

How can I get the ip address of a server in linux?

I need to use the bash command in Linux to tell me the IP address.

like image 847
vinyuri Avatar asked Feb 21 '11 07:02

vinyuri


People also ask

How to find your IP address in Linux?

The third method to find your IP address involves using the ifconfig command. In the command line, enter the following: The system will display all network connections – including connected, disconnected, and virtual. Look for the one labeled UP, BROADCAST, RUNNING, MULTICAST to find your IP address. This lists both IPv4 and IPv6 addresses.

How to get the IP of the host system in Linux?

Here are multiple ways to get the IP of host system in Linux. A Few years back, ifconfig was the favorite way to know IP address in Linux. Unfortunately, ifconfig command has been deprecated.

How to find the public IP address of a server?

To find your public IP addresses, use the opendns.com resolver as in the command below: 2. Using host Utility host command is an easy-to-use command line utility for carrying out DNS lookups.

How to get the IPv6 address of a Linux network interface?

The ip command also prints the IPv6 address attached to the network interfaces of your Linux server or workstation. As you can see, on my CentOS 7 server, the IPv6 address attached to the ens33 network interface is fe80:fd75:7722:6480:6d8f. The same way, the IPv6 address configured to the ens37 network interface is fe80:20c:29ff:feaa:bd0e.


2 Answers

If you are trying to get this information from BASH, you probably want to use nslookup. For example:

[michaelsafyan@codemage ~]$ nslookup redmine.org
Server:     8.8.8.8
Address:    8.8.8.8#53

Non-authoritative answer:
Name:   redmine.org
Address: 46.4.36.71

I should add that an IP address does NOT represent a computer, but rather a network interface. And a computer can have any number of network interfaces (and IP addresses). Also, a website or domain may have many machines (and consequently many more network interaces and IP addresses). When querying with nslookup you will get at least one IP address for the given domain name (assuming DNS is working and it doesn't fail for one reason or another), but it won't necessarily give you all the addresses.

like image 153
Michael Aaron Safyan Avatar answered Sep 28 '22 05:09

Michael Aaron Safyan


If you are just after the IP for a script, the following is a lot cleaner:

dig +short stackoverflow.com

For example:

@felix:~% dig +short stackoverflow.com
198.252.206.16
like image 32
Tigger Avatar answered Sep 28 '22 04:09

Tigger