opi*_*rce 27 linux ubuntu bash command-line-interface ip-address
是否有 bash 命令来查找 Ubuntu 机器的 IP 地址?我需要找到 IP 地址,以便稍后通过 ssh 进入机器。
Rob*_*her 27
您可以使用:
/bin/ip addr
Run Code Online (Sandbox Code Playgroud)
nik*_*nik 22
如果您正在使用内部地址,请检查
curl http://myip.dnsomatic.com
Run Code Online (Sandbox Code Playgroud)
在 unix shell 上可能是个好主意。
或者,只需将该 URL 插入浏览器即可。
如果您从“ ifconfig -a”结果中得到不同的答案,
则ifconfig给出了您的内部地址——这在外部可能不起作用。
即使一切看起来都很好,您也可以设置一个防火墙来禁止传入的ssh连接。
那时你应该从机器上的浏览器尝试感兴趣的端口,
http://www.canyouseeme.org/
Run Code Online (Sandbox Code Playgroud)
这将通过以下方式确认连接,
Jam*_*mes 19
/bin/hostname -i
chi*_*uit 13
curl icanhazip.com
Run Code Online (Sandbox Code Playgroud)
嘻嘻!
来自http://www.commandlinefu.com/commands/view/2966/return-external-ip
小智 10
/sbin/ifconfig|grep inet|head -1|sed 's/\:/ /'|awk '{print $3}'
Run Code Online (Sandbox Code Playgroud)
如果您需要内部地址,请在 ifconfig 后附加您的接口,例如
/sbin/ifconfig eth0|grep inet|head -1|sed 's/\:/ /'|awk '{print $3}'
Run Code Online (Sandbox Code Playgroud)
如果您在 NAT 后面,并且需要公共 IP,请使用以下命令:
wget -q -O - checkip.dyndns.org|sed -e 's/. 当前 IP 地址://' -e 's/<. $//'
取自:http : //www.go2linux.org/what-is-my-public-ip-address-with-linux
如果您有多个接口,则指定您想要哪个 IP 可能会很有用。如果你想要接口'eth0'的IPV4地址:
ip addr show dev eth0 | grep "inet " | awk '{ print $2 }'
Run Code Online (Sandbox Code Playgroud)
如果你想要接口'eth0'的IPV6地址:
ip addr show dev eth0 | grep "inet6 " | awk '{ print $2 }'
Run Code Online (Sandbox Code Playgroud)
如果要在笔记本电脑的两个常用接口 wlan0 和 eth0 之间搜索 IP:
CURRENT_IP=''
for INTERFACE in wlan0 eth0; do
if [ -z $CURRENT_IP ]; then
CURRENT_IP=$(ip addr show dev $INTERFACE | grep "inet " | awk '{ print $2 }')
fi
done
Run Code Online (Sandbox Code Playgroud)