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

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


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

[michaelsafyan@codemage ~]$ nslookup redmine.orgServer:     8.8.8.8Address:    8.8.8.8#53Non-authoritative answer:Name:   redmine.orgAddress: 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.com198.252.206.16