目前在eaf browser 代理设置是全局的,如果在使用过程中需要访问内网服务或者是访问一些不想走代理的站点的时候,又要先关闭代理。这样频繁的切换的代理操作属实优点麻烦。
之前想过给eaf browser的加一个内置的黑白名单的代理插件,但是受限于QtWebEngine的设计,没有特别好的解决方案,有兴趣的同学可以看看一下的帖子
既然从应用层不行,那就换个思路,通过一个基于rule的tunnel的来“曲线救国”。
这篇帖子后面介绍的就是如果使用clash来设置一个基于规则转发的中间的代理来服务eaf browser达到黑白名单的效果。
基本原理就是:
eaf browser => clash => proxy
通过clash 来进行规则匹配,看看对应的请求是否要走代理
Clash
Clash是一个跨平台、支持SS/V2ray/Trojan协议、基于规则的网络代理软件
(刚开始在网上搜了一下,发现很多文章的介绍的用途基本都是和科学上网相关的,开篇直接给个及其复杂的配置文件)
设置步骤
-
首先到 Clash 的 Github Release 界面下载,对应你系统版本的Clash
-
新建个config.yml文件,写好一些代理配置和规则配置,下面是我的参考模板
# config.yml
# 本地http(s)代理端口
port: 18080
# 本地socks5代理端口
socks-port: 10808
# 是否允许局域网中其他机器访问
allow-lan: false
# 仅当allow-lan设置为true时生效
# '*': 绑定所有IP
# 192.168.122.11:绑定单个IPV4
# "[aaaa::a8aa:ff:fe09:57d8]":绑定单个IPV6
bind-address: '*'
# 运行模式
# rule: 基于规则
# global: 全局代理
# direct: 不代理
mode: rule
# 日志输出级别
# info / warning / error / debug / silent
log-level: info
# 当设置为false时,不解析IPV6地址
ipv6: false
# 流量出口
interface-name: wlp4s0
# DNS 设置
dns:
enable: false
listen: 0.0.0.0:53
# ipv6: false # when the false, response to AAAA questions will be empty
# These nameservers are used to resolve the DNS nameserver hostnames below.
# Specify IP addresses only
default-nameserver:
- 114.114.114.114
- 8.8.8.8
enhanced-mode: redir-host # or fake-ip
fake-ip-range: 198.18.0.1/16 # Fake IP addresses pool CIDR
# use-hosts: true # lookup hosts and return IP record
# Hostnames in this list will not be resolved with fake IPs
# i.e. questions to these domain names will always be answered with their
# real IP addresses
# fake-ip-filter:
# - '*.lan'
# - localhost.ptlogin2.qq.com
# Supports UDP, TCP, DoT, DoH. You can specify the port to connect to.
# All DNS questions are sent directly to the nameserver, without proxies
# involved. Clash answers the DNS question with the first result gathered.
nameserver:
- 114.114.114.114 # default value
- 8.8.8.8 # default value
- tls://dns.rubyfish.cn:853 # DNS over TLS
- https://1.1.1.1/dns-query # DNS over HTTPS
- dhcp://en0 # dns from dhcp
# When `fallback` is present, the DNS server will send concurrent requests
# to the servers in this section along with servers in `nameservers`.
# The answers from fallback servers are used when the GEOIP country
# is not `CN`.
# fallback:
# - tcp://1.1.1.1
# If IP addresses resolved with servers in `nameservers` are in the specified
# subnets below, they are considered invalid and results from `fallback`
# servers are used instead.
#
# IP address resolved with servers in `nameserver` is used when
# `fallback-filter.geoip` is true and when GEOIP of the IP address is `CN`.
#
# If `fallback-filter.geoip` is false, results from `nameserver` nameservers
# are always used if not match `fallback-filter.ipcidr`.
#
# This is a countermeasure against DNS pollution attacks.
# fallback-filter:
# geoip: true
# geoip-code: CN
# ipcidr:
# - 240.0.0.0/4
# domain:
# - '+.google.com'
# - '+.facebook.com'
# - '+.youtube.com'
# Lookup domains via specific nameservers
# nameserver-policy:
# 'www.baidu.com': '114.114.114.114'
# '+.internal.crop.com': '10.0.0.1'
proxies:
# 代理服务器配置,更多的代理设置请查看:https://lancellc.gitbook.io/clash/clash-config-file/an-example-configuration-file
- name: "http"
type: http
server: localhost
port: 1081
proxy-groups:
# 组策略
# url-test 自动选择最快的节点进行访问.
- name: "auto" #策略名
type: url-test
proxies:
- http
# tolerance: 150
url: 'http://www.gstatic.com/generate_204'
interval: 300
rules:
# 规则策略
# 当一级域名是google.com时使用auto策略
- DOMAIN-SUFFIX,google.com,auto
- DOMAIN-SUFFIX,gitee.com,DIRECT
- DOMAIN-SUFFIX,emacs-china.org,DIRECT
- DOMAIN-SUFFIX,ruby-china.org,DIRECT
- DOMAIN-SUFFIX,baidu.com,DIRECT
# 当域名含有关键词google时使用auto
- DOMAIN-KEYWORD,google,auto
- DOMAIN,google.com,auto
# 当一级域名是ad.com时拒绝访问,可以用于屏蔽广告
- DOMAIN-SUFFIX,ad.com,REJECT
# 内网服务ip不走代理
- SRC-IP-CIDR,192.168.1.0/32,DIRECT
- SRC-IP-CIDR,10.0.0.0/8,DIRECT
# 可选参数 "no-resolve" ,基于IP的规则 (GEOIP, IP-CIDR, IP-CIDR6)
- IP-CIDR,127.0.0.0/8,DIRECT
- GEOIP,CN,DIRECT
# 目标端口是8888时,直接访问不走代理
- SRC-PORT,8888,DIRECT
# 默认规则
- MATCH,auto
- 设置 eaf browser 代理为clash
(setq eaf-proxy-type "http")
(setq eaf-proxy-host "127.0.0.1")
(setq eaf-proxy-port "18080")
- 运行Clash
clash -f config.yml
- Done