未連線到 Internet 時在 OS X 上使用 dnsmasq

未連線到 Internet 時在 OS X 上使用 dnsmasq

我透過 dnsmasq 路由 dns 請求,以便我用於本地開發的網域指向 127.0.0.1。當我透過 Wi-Fi 或乙太網路連接到網路時,這非常有效,但當我完全沒有連接到網路時,我就會開始遇到問題。

在 dnsmasq.conf 中,我有以下設定:

address=/gentoo/127.0.0.1

關閉所有網路連接,我運行:

$ dscacheutil -q host -a name test.gentoo
name: test.gentoo
ip_address: 127.0.0.1

$ ping test.gentoo
PING test.gentoo (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.043 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.107 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.177 ms
^C
--- test.gentoo ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.043/0.109/0.177/0.055 ms

所以這似乎工作正常。但如果我嘗試打開http://test.gentoo/在 Chrome 中,我收到訊息:

無法連線到網路 Google Chrome 無法顯示網頁,因為您的電腦未連接至網際網路。

您可以嘗試透過執行以下步驟來診斷問題:

前往應用程式 > 系統偏好設定 > 網路 > 協助我測試您的連線。錯誤 106 (net::ERR_INTERNET_DISCONNECTED):網路連線已遺失。

Chrome 發現我沒有網路連接,它甚至不會嘗試發出請求。

知道我該如何解決這個問題嗎?我可以建立一個虛擬網路介面來讓 Chrome 相信我已連接到網路嗎?即使我沒有連接,我可以讓它發送請求嗎?還有其他想法嗎?

我嘗試了該解決方案https://serverfault.com/q/22419/92378但它不起作用,因為我使用的是 OS X 10.7.3,所以未連接到網路時解析器將被忽略。

相關內容