
這是一件有趣的事。
我們的主機名稱和 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