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.
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.
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