日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

搞懂 macOS 上的主机名/hostname/ComputerName

發布時間:2023/12/13 综合教程 24 生活家
生活随笔 收集整理的這篇文章主要介紹了 搞懂 macOS 上的主机名/hostname/ComputerName 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

主機名/hostname/ComputerName 的含義

主機名、hostname 是一個東西,中英文而已,指的是你本地網絡上的電腦可以通過主機名訪問你的電腦。這個與 Linux 系統是一致的。

ComputerName,這個是 macOS 才有的東西。跟 Windows 上一樣,表示的是電腦名稱,給人看的。

可以從下圖中看出來(系統偏好設置>共享):

對于 macOS 來說,它會按以下的順序來確定主機名,直到獲取到為止:

從以下文件中讀取:/etc/hostconfig
從以下系統配置項讀取:/Library/Preferences/SystemConfiguration/preferences.plist中的System ? System ? HostName
由本機 IP 地址的反向 DNS 查詢獲取
從以下系統配置項讀取:/Library/Preferences/SystemConfiguration/preferences.plist中的System ? Network ? HostNames ? LocalHostName
如果以上方法都沒獲取到,就為默認的localhost

主機名/hostname 修改

查看

hostname

或者

scutil --get LocalHostName

修改

sudo scutil --set LocalHostName XXX

示例

$ hostname
shocker.local
$ scutil --get LocalHostName
shocker
$ sudo scutil --set LocalHostName hello
Password:
$ hostname
hello.local
$ scutil --get LocalHostName
hello

ComputerName 修改

查看

scutil --get ComputerName

修改

sudo scutil --set ComputerName XXX

示例

$ scutil --get ComputerName
shocker
$ sudo scutil --set ComputerName MyMacBook
Password:
$ scutil --get ComputerName
MyMacBook

scutil 命令

scutil是個可動態訪問 macOS 系統信息的交互式工具。

$ scutil --help
usage: scutil
    interactive access to the dynamic store.

   or: scutil --prefs [preference-file]
    interactive access to the [raw] stored preferences.

   or: scutil [-W] -r nodename
   or: scutil [-W] -r address
   or: scutil [-W] -r local-address remote-address
    check reachability of node, address, or address pair (-W to "watch").

   or: scutil -w dynamic-store-key [ -t timeout ]
    -w    wait for presense of dynamic store key
    -t    time to wait for key

   or: scutil --get pref
   or: scutil --set pref [newval]
   or: scutil --get filename path key
    pref    display (or set) the specified preference.  Valid preferences
        include:
            ComputerName, LocalHostName, HostName
    newval    New preference value to be set.  If not specified,
        the new value will be read from standard input.

   or: scutil --dns
    show DNS configuration.

   or: scutil --proxy
    show "proxy" configuration.

   or: scutil --nwi
    show network information

   or: scutil --nc
    show VPN network configuration information. Use --nc help for full command list

   or: scutil --allow-new-interfaces [off|on]
    manage new interface creation with screen locked.

   or: scutil --error err#
    display a descriptive message for the given error code

查看 DNS 配置

$ scutil --dns

DNS configuration

resolver #1
  nameserver[0] : 61.139.2.69
  nameserver[1] : 218.6.200.139
  if_index : 5 (en0)
  flags    : Request A records
  reach    : 0x00000002 (Reachable)

resolver #2
  domain   : 8163912288.members.btmm.icloud.com
  options  : pdns
  timeout  : 5
  flags    : Request A records
  reach    : 0x00000000 (Not Reachable)
  order    : 150000

// more ...

查看代理配置

$ scutil --proxy
<dictionary> {
  HTTPEnable : 0
  HTTPSEnable : 0
  ProxyAutoConfigEnable : 0
  SOCKSEnable : 0
}

查看網絡配置

$ scutil --nwi

Network information

IPv4 network interface information
     en0 : flags      : 0x5 (IPv4,DNS)
           address    : 192.168.0.105
           reach      : 0x00000002 (Reachable)

   REACH : flags 0x00000002 (Reachable)

IPv6 network interface information
   No IPv6 states found


   REACH : flags 0x00000000 (Not Reachable)

Network interfaces: en0

修改主機名、電腦名稱等

$ scutil --set ComputerName xxx
$ scutil --set HostName xxx
$ scutil --set LocalHostName xxx

參考

Where does the prompt name come from in the macOS Terminal?
How to set hostname in Mac OS X with scutil

原文地址:https://shockerli.net/post/ma...


總結

以上是生活随笔為你收集整理的搞懂 macOS 上的主机名/hostname/ComputerName的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。