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.
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.
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With