Loading... # MacOS上的伪透明代理配置方法 ## 资源 * [xray](https://github.com/XTLS/Xray-core/releases) * [fakedns](http://type.zimopy.com/usr/uploads/2024/05/1216184699.zip) * pf ## 配置xray ### 安装xray see [https://xtls.github.io/document/install.html](https://xtls.github.io/document/install.html) ### 配置config.json ```json { "log": { "loglevel": "none" }, "inbounds": [ { "tag": "inbound-promiscuous", "ip": "127.0.0.1", "port": 8127, "protocol": "dokodemo-door", "settings": { "network": "tcp", "followRedirect": true }, "sniffing": { "enabled": true, "destOverride": [ "http", "tls", "quic" ] }, "streamSettings": { "sockopt": { "tproxy": "redirect" } } } ], "outbounds": [ { "tag": "outbound-proxy", "your": "outbounds config" } ] } ``` ### 运行xray ```shell xray -c config.json ``` ## 配置fakedns ### 安装fakedns 1. 下载 [fakedns.zip](http://type.zimopy.com/usr/uploads/2024/05/1216184699.zip) 并解压 2. 添加权限 ```shell chmod +x fakedns ``` ### 配置fakedns #### 编辑代理域名 `/etc/fakedns/domain.conf` ```plaintext google.com youtube.com ``` #### 编辑排除域名 `/etc/fakedns/domain_exclude.conf` ```plaintext baidu.com ``` 或者下载我的[配置](http://type.zimopy.com/usr/uploads/2024/05/3390137032.zip) ### 运行fakedns ```shell fakedns -d /etc/fakedns/domain.conf -e /etc/fakedns/domain_exclude.conf ``` ## 配置pf ### 安装pf macOS 自带 ### 配置pf #### 获取流量出口网卡 ```shell route get default ``` ![image.png](http://type.zimopy.com/usr/uploads/2024/05/1978269644.png) #### 编辑配置文件 `/etc/pf.conf` ```plaintext xray_port = 8127 #不能修改 dns_port = 53 #不能修改 local_dns_port = 58888 #不能修改 net_if = bridge0 # 使用你上面获取的接口 local_if = lo0 # default 1.2.3.4 # 1.2.3.4 不能修改 # 可以添加你需要代理的ip网段空格分割 # 如 table <xray> { 1.2.3.4/32 20.27.177.113/32 } table <xray> { 1.2.3.4/32 } nat on $net_if inet proto udp from $net_if port !=$local_dns_port to any port $dns_port -> ($local_if) rdr pass on $local_if inet proto udp from $local_if port !=$local_dns_port to any port $dns_port -> $local_if port $dns_port rdr pass on $local_if inet proto tcp from $net_if to <xray> -> $local_if port $xray_port pass out on $net_if route-to ($local_if $local_if) proto udp from $local_if port !=$local_dns_port to any port $dns_port keep state queue std pass out on $net_if route-to ($local_if $local_if) proto tcp from any to <xray> keep state queue std ``` ### 运行pf ```shell # 开启pf sudo pfctl -e # 清空之前的全部配置 sudo pfctl -F all # 加载配置 sudo pfctl -vf /etc/pf.conf ``` ## 测试 ```shell curl -v https://www.youtube.com/ ``` ## 开机自启(非必须) 使用macOS自带方案`launchctl` ### xray 编辑 `/Library/LaunchDaemons/com.xray.plist` ```plaintext <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> <plist version='1.0'> <dict> <key>Label</key> <string>com.xray</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/xray</string> <string>-c</string> <string>/etc/xray/config.json</string> </array> <key>StandardOutPath</key> <string>/var/log/com.xray.log</string> <key>StandardErrorPath</key> <string>/var/log/com.xray.log</string> <key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/> <key>AbandonProcessGroup</key> <true/> <key>EnvironmentVariables</key> <dict> <key>PATH</key> <string>/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string> </dict> </dict> </plist> ``` ```shell # 加载 sudo launchctl load /Library/LaunchDaemons/com.xray.plist # 卸载 # sudo launchctl unload /Library/LaunchDaemons/com.xray.plist ``` ### fakedns 编辑 `/Library/LaunchDaemons/com.fakedns.plist` ```plaintext <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> <plist version='1.0'> <dict> <key>Label</key> <string>com.fakedns</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/fakedns</string> <string>--domain</string> <string>/etc/fakedns/domain.conf</string> <string>--exclude-domain</string> <string>/etc/fakedns/domain_exclude.conf</string> </array> <key>StandardOutPath</key> <string>/var/log/com.fakedns.log</string> <key>StandardErrorPath</key> <string>/var/log/com.fakedns.log</string> <key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/> <key>AbandonProcessGroup</key> <true/> <key>EnvironmentVariables</key> <dict> <key>PATH</key> <string>/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string> </dict> </dict> </plist> ``` ```shell # 加载 sudo launchctl load /Library/LaunchDaemons/com.fakedns.plist # 卸载 # sudo launchctl unload /Library/LaunchDaemons/com.fakedns.plist ``` 最后修改:2024 年 05 月 15 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏