修改dns实现方式,大幅度优化使用流程

This commit is contained in:
juewuy
2020-07-23 12:32:13 +08:00
parent bd27372fc8
commit 2a904d3d10
5 changed files with 42 additions and 41 deletions

View File

@@ -11,7 +11,7 @@ PS
使用依赖:
--
•请确认路由器或设备已经开启ssh并获取root权限小米AX系列可参考https://www.right.com.cn/forum/thread-4032490-1-1.html<br>
•请确认路由器或设备已经开启SSH并获取root权限小米AX系列可参考https://www.right.com.cn/forum/thread-4032490-1-1.html 开启<br>
•SSH连接工具例如puttybitvise等请自行安装使用<br>
•SCP连接工具如winscp内置了putty只安装这一个其实就可以<br>
@@ -23,67 +23,54 @@ PS
*·如有必要也可以自行前往下载更新clash核心文件并自行改名 https://github.com/Dreamacro/clash/releases/tag/premium 小米AX3600是armv8ax1800/ax5是armv7其他路由器请自查<br>*
•将下载并修改后的4个文件通过winSCP上传到路由器/etc/clash文件夹clash文件夹请自行创建最终应该是/etc/clash/"4个文件"<br>
•登陆SSH并在SSH中用root用户执行下方的**对应命令**即可使用!<br>
**首次安装clash**
```Shell
#首次启用clash
mv /etc/clash/clashservice /etc/init.d/clash #将clash服务文件移动到系统目录
chmod 777 /etc/clash/clash #授予权限
chmod 777 /etc/init.d/clash #授予权限
sed -i "8iport=5335" /etc/dnsmasq.conf #修改dnsmasq监听端口为5335
service dnsmasq restart #重启dnsmasq服务报错“cp: can't stat '/etc/dnsmasq.d/*'……”可无视)
service clash enable #启用clash开机启动
service clash start #启动clash服务
```
**停止clash**
```Shell
#停止clash透明网关-Tun模式
service clash disable #禁用clash开机启动
service clash stop #停止clash服务
sed -i '/port=5335/d' /etc/dnsmasq.conf #重置dnsmasq监听端口为默认值port:53)
service dnsmasq restart #重启dnsmasq服务报错“cp: can't stat '/etc/dnsmasq.d/*'……”可无视,不放心可重启系统)
```
```Shell
#停止clash透明网关-Redir模式
service clash disable #禁用clash开机启动
service clash stop #停止clash服务
sed -i '/port=5335/d' /etc/dnsmasq.conf #重置dnsmasq监听端口为默认值port:53)
service dnsmasq restart #重启dnsmasq服务报错“cp: can't stat '/etc/dnsmasq.d/*'……”可无视,不放心可重启系统)
service firewall restart #重启防火墙以重置iptables规则
```
**启用clash**
```Shell
#停止后再次启用clash透明网关
sed -i "8iport=5335" /etc/dnsmasq.conf #修改dnsmasq监听端口为5335
service dnsmasq restart #重启dnsmasq服务报错“cp: can't stat '/etc/dnsmasq.d/*'……”可无视)
service clash enable #启用clash开机启动
service clash start #启动clash服务
```
```Shell
#完全卸载clash相关文件
service clash disable #禁用clash开机启动
service clash stop #停止clash服务
sed -i '/port=5335/d' /etc/dnsmasq.conf #重置dnsmasq监听端口为默认值port:53)
service dnsmasq restart #重启dnsmasq服务报错“cp: can't stat '/etc/dnsmasq.d/*'……”可无视,不放心可重启系统)
**设置clash开机启动**
```Shell
service clash enable #启用clash开机启动
```
**禁止clash开机启动**
```Shell
service clash disable #禁止clash开机启动
```
**卸载clash相关文件**
```Shell
rm -rf /etc/clash #删除clash文件夹及文件
rm /etc/init.d/clash #删除clash开机启动文件
```
•启用后可以通过 http://clash.razord.top IP为网关IP端口为9999管理clash内置规则,通常无需额外设置即可正常使用,且设备重启后会保持自动运行<br>
•启用后可以通过 http://clash.razord.top IP为网关IP端口为9999管理clash内置规则<br>
故障解决:
--
•在浏览器或设备WiFi管理的高级选项中配置http代理IP为路由器IP端口7890如果能连通外网则说明clash服务运行正常不能连通则说明clash运行失败或者配置错误<br>
•如果能正常连接国内网站而无法访问屏蔽网站,请在浏览器中打开 http://clash.razord.top 并使用测速功能,之后手动指定服务器即可;如果所有服务器都不可用即代表配置文件有问题<br>
•如果能连通http代理但是无法使用透明代理可能是tun网卡启用失败或者dnsmasq启动失败重启设备通常可以解决,或重新执行安装命令<br>
•如果能连通http代理可在浏览器中设置http代理端口为7890但是无法使用透明代理可能是tun网卡启用失败或者dnsmasq启动失败重启设备通常可以解决<br>
已知问题:
--
•部分软件不会经过clash例如telegram可以通过设置软件内置sock5或http代理解决<br>
•部分系统版本较低安卓6.0以下的安卓设备可能无法正确通过dhcp服务获取dns地址需要手动在WIFI中设置dns为路由器网关地址<br>
•由于使用了clash的fake-ip模式暂不支持ipv6<br>
tun模式下clash服务可能会和小米路由器内置的tx网游加速器冲突请谨慎同时使用<br>
Tun模式下clash服务可能会和小米路由器内置的tx网游加速器冲突请谨慎同时使用<br>
•Tun模式下部分软件不会经过clash例如telegram可以通过设置软件内置sock5或http代理解决<br>
•Redir模式无法转发udp流量外服游戏可能会受影响此功能是由于官方系统阉割了Tproxy导致故无法修复<br>
•全局模式代理无效原因不明同样的配置文件在pc端或者安卓上都可以使用全局模式怀疑是clash核心的bug<br>
•小米路由内置的openwrt默认阉割了对tproxy的支持所以使用redir模式做透明代理时无法转发udp流量<br>
感谢:
--
•https://lancellc.gitbook.io/clash/start-clash/clash-tun-mode<br>
•https://comzyh.gitbook.io/clash/<br>
•https://h-cheung.gitlab.io/post/使用_clash_和路由表实现透明代理/<br>
•https://h-cheung.gitlab.io/post/使用_clash_和路由表实现透明代理<br>
•https://www.right.com.cn/forum/thread-4042741-1-1.html<br>

View File

@@ -14,7 +14,15 @@ start_service() {
procd_set_param command /etc/clash/clash -d /etc/clash
procd_close_instance
#修改iptables规则使流量进入clash
iptables -t nat -N clash
iptables -t nat -N clash
iptables -t nat -A clash -p tcp -j REDIRECT --to-ports 7892
iptables -t nat -A PREROUTING -p tcp -j clash
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
}
stop_service() {
#重置iptables规则
iptables -t nat -D PREROUTING -p tcp -j clash
iptables -t nat -F clash
iptables -t nat -X clash
iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
}

View File

@@ -18,13 +18,13 @@ external-controller: 0.0.0.0:9999
dns:
enable: true
listen: 0.0.0.0:53 #监听端口0.0.0.0则拦截所有
listen: 0.0.0.0:1053 #监听端口0.0.0.0则拦截所有
fake-ip-range: 198.18.0.1/16 #fake-ip模式下子网段尽量不要改动
enhanced-mode: fake-ip #或者redir-host可能有bug尽量不要改动
nameserver: #国内DNS可配置多条
- tls://dns.rubyfish.cn:853
#- 114.114.114.114
- 127.0.0.1:5335 #内置的dnsmasq
- 127.0.0.1:53 #内置的dnsmasq
fallback: #国外DNS可配置多条
- tcp://1.1.1.1
- tls://dns.google:853
@@ -87,7 +87,7 @@ proxy-groups:
- "v2ray"
- "Trojan"
url: 'http://www.gstatic.com/generate_204'
interval: 999
interval: 100
# 代理节点选择
- name: "PROXY"

View File

@@ -6,11 +6,17 @@ USE_PROCD=1
START=99
start_service() {
#创建clash后台进程
procd_open_instance
procd_set_param respawn
procd_set_param stderr 1
procd_set_param stdout 1
procd_set_param command /etc/clash/clash -d /etc/clash
procd_close_instance
#修改iptables规则使流量进入clash
iptables -I FORWARD -o utun -j ACCEPT
iptables -t nat -I PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
}
stop_service() {
iptables -t nat -D PREROUTING -p udp --dport 53 -j REDIRECT --to 1053
}

View File

@@ -18,12 +18,12 @@ external-controller: 0.0.0.0:9999
dns:
enable: true
listen: 0.0.0.0:53 #监听端口0.0.0.0则拦截所有
listen: 0.0.0.0:1053 #监听端口0.0.0.0则拦截所有
fake-ip-range: 198.18.0.1/16 #fake-ip模式下子网段尽量不要改动
enhanced-mode: fake-ip #尽量不要改动
nameserver: #国内DNS可配置多条
- tls://dns.rubyfish.cn:853
- 127.0.0.1:5335 #本地dnsmasq服务器
- 127.0.0.1:53 #本地dnsmasq服务器
fallback: #国外DNS可配置多条
- tcp://1.1.1.1
- tls://dns.google:853
@@ -86,7 +86,7 @@ proxy-groups: #代理服务器组
- "v2ray"
- "Trojan"
url: 'http://www.gstatic.com/generate_204'
interval: 999
interval: 100
# 代理节点选择
- name: "PROXY"