配合 Dnsmasq 使用 Surge Router Mode

Surge 官方已經介紹過配合 DHCP 使用 Surge Router Mode 的方法,但教程中需要停用路由器的 DHCP 服務,還需要在另外的設備單獨部署 ISC DHCP Server。實際上大部分路由器自帶的 Dnsmasq 都可以實現上述的效果。

以筆者所在網路環境為例,路由器系統為 OpenWrt,IP 為 10.0.0.1,Mac 的 IP 為 10.0.0.3。首先,給 Mac 分配固定 IP,可以在 /etc/config/dhcp 添加

config host
    option mac '0d:4d:a9:ca:35:1c'
    option ip '10.0.0.3'
    option dns '1'
    option name 'mac'

執行 /etc/init.d/dnsmasq restart 重啓 Dnsmasq,在 Mac 重新獲取 IP,應該能獲取到固定 IP 10.0.0.3。在 Mac 中運行 Surge,啟用 Enhanced Mode。

接下來,找出需要把 Surge 作為網關的設備,以筆者的 HomePod 為例,獲取到 mac 地址為 D3:A4:4D:6B:B4:A4。同樣地,給它分配一個固定 IP 10.0.0.10,在 /etc/config/dhcp 添加

config host
    option name 'homepod'
    option dns '1'
    option mac 'D3:A4:4D:6B:B4:A4'
    option ip '10.0.0.10'
    option tag 'surge'

注意上述配置,新增了一個 option 為 option tag 'surge',代表把這個設備打上了 tag,在後面的 DHCP 分配中,我們就可以根據這個 tag 對特定設備區別對待了。

將所有需要把 Surge 作為網關的設備打上 tag 之後,需要在網段下設置 DHCP option,假設網段名為 lan,則在 /etc/config/dhcp 添加。

config dhcp 'lan'
    list dhcp_option 'tag:surge,3,10.0.0.10'
    list dhcp_option 'tag:surge,6,198.18.0.2'

其中,tag:surge,3,10.0.0.10 代表把 tag 為 surge 的設備,通告網關為 10.0.0.10,tag:surge,6,198.18.0.2 代表把 tag 為 surge 的設備,通告 DNS 為 198.18.0.2。

重啓 Dnsmasq,對應設備重新獲取 IP 地址,現在應該能暢快訪問互聯網了。

All rights reserved
Except where otherwise noted, content on this page is copyrighted.