这是一个有趣的问题。
我们的主机名和 IP 是什么?
echo $hostname $(ipaddr)
TCA0080ALKVTAGB xx.xx.242.47
ping
作品:
$ping $(hostname)
PING TCA0080ALKVTAGB (xx.xxx.242.47): 56 data bytes
64 bytes from xx.xxx.242.47: icmp_seq=0 ttl=64 time=0.049 ms
64 bytes from xx.xxx.242.47: icmp_seq=1 ttl=64 time=0.102 ms
ssh
做不是:显然在 DNS 世界中迷失了(对于同一主机):
$ssh $(hostname)
ssh: Could not resolve hostname tca0080alkvtagb: nodename nor servname provided, or not known
注意:我们已经禁用ipv6
:
networksetup -setv6off Wi-Fi
这是El Capitan
。
对于那些好奇的人来说ipaddr
:
$type ipaddr
ipaddr is a function
ipaddr ()
{
ifconfig -a | grep -A 6 en0 | grep "inet " | awk '{print $2}'
}
哦!别忘了提一下: ssh
使用 ip addr 确实有效:
ssh xx.xx.242.47
Last login: Mon Jan 16 12:24:08 2017 from xx.xx.242.47
更新
Telnet
工作正常;
telnet $(hostname) 22
以下是 `ssh -vvv $(hostname) 输出
$ssh -vvv $(hostname)
OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data /Users/boesc**/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: /etc/ssh/ssh_config line 56: Applying options for *
ssh: Could not resolve hostname tca0080alkvtagb: nodename nor servname provided, or not known
答案1
TL;DR:一种macos
主义……
ssh $(hostname).local
有效。感谢以下问答“伸出援手”: https://stackoverflow.com/a/33506923/1056563
此外,.local
还应添加到search
from DNS
: ,如下所述:https://apple.stackexchange.com/a/197884/55242