linux下如何获取服务器的ip地址?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5063343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the ip address of the server in linux?
提问by vinyuri
How can I get the ip address of a server in linux?
如何在linux中获取服务器的IP地址?
I need to use the bash command in Linux to tell me the IP address.
我需要在 Linux 中使用 bash 命令来告诉我 IP 地址。
采纳答案by Michael Aaron Safyan
If you are trying to get this information from BASH, you probably want to use nslookup. For example:
如果您尝试从 BASH 获取此信息,您可能想要使用nslookup。例如:
[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 NOTrepresent 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.
我要补充一点,一个IP地址确实不是代表计算机,而是一个网络接口。一台计算机可以有任意数量的网络接口(和 IP 地址)。此外,一个网站或域可能有许多机器(因此有更多的网络接口和 IP 地址)。使用 nslookup 进行查询时,您将获得至少一个给定域名的 IP 地址(假设 DNS 正在工作并且不会因某种原因而失败),但它不一定会为您提供所有地址。
回答by Tigger
If you are just after the IP for a script, the following is a lot cleaner:
如果您只是在寻找脚本的 IP,以下内容会更清晰:
dig +short stackoverflow.com
For example:
例如:
@felix:~% dig +short stackoverflow.com
198.252.206.16