Edit your Hosts File on a Mac. Mac設定hosts檔案

Peggy Tsai 
May 11, 2022

(hosts file)

最近在研究PHP
首先需調整host檔案來設定網址連到指定的測試主機的網頁

記錄一下,如何在mac中調整hosts檔案

Windows中,hosts檔案路徑 C:\Windows\System32\drivers\etc\hosts
mac中,hosts檔案路徑/etc/hosts,且需要root權限才能執行

開啟終端機

切換root權限,sudo -i 並輸入現在登入帳號的密碼

sudo -i

編輯hosts檔案

vi /etc/hosts

在最下面加入IP跟網址

存檔後,就改成功了
再次開啟網頁,F12查看Remote Address的IP,已成功替換至測試的server了

--

--