Clash一款强大的本地HTTP/HTTPS/SOCKS代理软件,内置DNS服务器,可以最大限度减少DNS污染,支持DoH/DoT上游DNS。可以基于域、GEOIP、IP-CIDR或进程名称规则将数据包路由到不同目的地。代理组允许用户制定灵活的规则,支持自动回退、负载均衡或基于延迟自动选择远程代理节点。Clash提供了基于Freebsd平台运行的程序,本文介绍在pfSense和OPNsense上安装Clash并设置透明代理的方法。
如果有海外VPS,推荐使用Sing-box一键四协议共存脚本,能直接提供clash.meta核心使用的Clash配置文件。
本教程所使用的防火墙为pfSense plus 24.03和OPNsense24.7_1。在配置clash之前,请先按正常步骤配置防火墙,确保各项功能正常使用。
本文使用Clash Meta(mihomo)内核代理clash,该内核还在持续更新当中。
安装clash
请参阅以下教程:
安装完成如下图所示:
OPNsense的clash控制界面
pfSense的clash控制界面
修改配置
下载文末附件并解压缩,修改config.yaml配置。从支持Clash Meta核心的客户端程序(如:ClashN、Clash Verge等)导出所使用机场的配置文件,保留http和socks代理端口设置,如下图所示:
port: 7890 socks-port: 7891 allow-lan: true mode: rule ipv6: true log-level: info unified-delay: true global-client-fingerprint: chrome external-controller: '0.0.0.0:9090' external-ui: /usr/local/etc/clash/ui external_ui_download_url: 'https://github.com/MetaCubeX/metacubexd/archive/refs/heads/gh-pages.zip' external_ui_download_detour: 'proxy' secret: 123456 dns: enable: true listen: :1053 ipv6: true enhanced-mode: fake-ip fake-ip-range: 198.18.0.1/16 default-nameserver: - 223.5.5.5 - 8.8.8.8 nameserver: - https://dns.alidns.com/dns-query - https://doh.pub/dns-query fallback: - https://1.0.0.1/dns-query - tls://dns.google fallback-filter: geoip: true geoip-code: CN ipcidr: - 240.0.0.0/4 proxies:
allow-lan参数设置为true,以允许防火墙的客户端使用代理。为了使用Clash仪表面板,需要设置仪表面板访问地址、下载地址和安全密钥。如果想使用OPNsense的Unbound DNS进行DNS查询(阻止黑名单功能),可以将default-nameserver项设置为127.0.0.1(在使用透明代理后,可能存在国内国外IP全局出站的情况)。listen的值不能与防火墙DNS默认监听端口冲突。
注意:在pfSense和OPNsnes上,clash(mihomo)不支持使用tun模式。
订阅管理
安装脚本自带了本地订阅功能,订阅程序来自github。请按以下方法进行操作:
修改订阅地址
打开sub/env文件(安装后位置:/usr/local/etc/clash/sub/env),输入自己机场的订阅地址,根据需要修改安全密钥。
修改模板文件
修改sub/sub/temp/templete文件(安装后位置:/usr/local/etc/clash/sub/temp/templete_config.yaml),参照示例修改clash配置文件除proxies的部分,注意不要添加socks-port: 7891条目,订阅程序会自动添加。
测试订阅功能
运行以下命令,检查订阅功能:
sub
如果订阅不成功,就会出现下图的出错提示:
自动更新订阅
pfSense需要安装cron插件,然后导航到服务>cron,添加一个定时任务,命令格式为/usr/bin/sub,时间根据需要设置。如下图所示,表示每周六的凌晨3点自动更新订阅。
OPNsesne无需安装插件,导航到系统>设置>任务,添加Clash Subscription Updates任务,时间根据需要设置。如下图所示,表示每周六的凌晨3点自动更新订阅。
注意事项
- 更新订阅会自动替换clash所使用的配置文件并重启clash服务。
- 部分机场采用了加密链接,可能无法获取订阅文件。
- 建议使用sublinkX搭建节点订阅系统,可以将自建节点和机场放入一个订阅链接进行订阅。
仪表面板
如果config.yaml当中包括了clash仪表面板的设置信息,在程序运行以后,就可以通过仪表面板查看代理连接信息。
仪表面板访问地址:http://LAN地址:9090/ui,默认安全密钥为123456,可以修改config.yaml中“secret”的值进行更改。
测试代理
Windows系统按以下方法添加http代理:点击左下角搜索图标,输入“代理服务器设置”,点击打开,选择手动设置代理,http代理按下图设置:
socks代理按下图设置:
设好代理并保存以后,测试是否能正常访问google、youtube等网站,访问ip111.cn,检查分流设置是否正常。
透明代理
由于mihomo在freebsd中未提供对tun的完全支持,在pfSense、OPNsense防火墙上实现透明代理请参阅以下文章:
附件下载
相关文章:
-
- pfSense、OPNsense配置Xray代理教程
- pfSense、OPNsense配置trojan-go教程
- pfSense、OPNsense配置v2ray代理教程
- pfSense、OPNsense配置Clash代理教程
- pfSense、OPNsense配置hysteria代理教程
- pfSense、OPNsense配置sing-box代理教程
- pfSense、OPNsense配置http透明代理教程
- pfSense、OPNsense配置hysteria2代理教程
- pfSense、OPNsense配置tun2socks(透明代理)
- pfSense、OPNsense配置hysteria 透明代理(TUN)教程
我的clash for windows配置文件中有一句 listen: ‘127.0.0.1:35353’。请问这个应该怎么改?
—————–
dns:
enable: true
listen: ‘127.0.0.1:35353’
default-nameserver: [223.5.5.5, 114.114.114.114]
enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16
…
——————–
解决了,这里不用改。
注意上边allow-lan: false 改成allow-lan:true
OK
外网访问clash的socks代理怎么访问,能出一期教程吗?
设置透明代理后,无线ap无法访问网络
有线能访问,无线不能访问,找找无线配置的问题。
配置了透明代理之后内网的设备可以正常透明代理上网,但是防火墙本身不走代理访问网站,博主知道该咋设置吗?
目前还没找到办法,也没有这种需求。
如果从clash复制出来config后又自己修改过的话,一定要记得不能有空行!!!!这个插件估计文件检查比较严格,clash客户端或者直接运行clash core的话,config带有空行不影响运行,但是这个插件不行。今天换成clash premium core,一度以为是不支持,结果就是单纯我的config有空行。。。。
clash.meta内核没这么讲究。
clash已删库,可以使用clash meta(mihomo)内核来替换。
I can’t find the clash.meta kerne and also Clash script program what do you name it? system proxy? i hope there a tutorial for this on youtube it will be great to have this.
😔
版本
OPNsense 24.7-amd64
FreeBSD 14.1-RELEASE-p2
OpenSSL 3.0.14
运行安装脚本之后 service clash start 端口没起来 service clash status 显示没运行
root@OPN:~/clash # service clash status
clash is not running.
检查CLASH配置文件是否正确,你可以运行“/usr/local/bin/clash -d /usr/local/etc/clash”进行测试,看是否能正常跑码
回复 This program can only be run on AMD64 processors with v3 microarchitecture support.
是因为cpu不支持么?CPU为j1900v4
OK我找到原因了 是站长下载的内核非兼容版 无法运行起来 替换兼容版mihomo-freebsd-amd64-compatible-v1.18.7.gz
解决问题
出现新问题 配置透明代理完成后启动
Starting squid.
CPU Usage: 0.021 seconds = 0.021 user + 0.000 sys
Maximum Resident Size: 62464 KB
Page faults with physical i/o: 0
2024/08/03 05:15:32| Processing Configuration File: /usr/local/etc/squid/squid.conf (depth 0)
2024/08/03 05:15:32| Starting Authentication on port 127.0.0.1:3128
2024/08/03 05:15:32| Disabling Authentication on port 127.0.0.1:3128 (interception enabled)
2024/08/03 05:15:32| Starting Authentication on port [::1]:3128
2024/08/03 05:15:32| Disabling Authentication on port [::1]:3128 (interception enabled)
2024/08/03 05:15:32| Starting Authentication on port 127.0.0.1:3129
2024/08/03 05:15:32| Disabling Authentication on port 127.0.0.1:3129 (interception enabled)
2024/08/03 05:15:32| Starting Authentication on port [::1]:3129
2024/08/03 05:15:32| Disabling Authentication on port [::1]:3129 (interception enabled)
2024/08/03 05:15:32| WARNING: empty ACL: acl bump_nobumpsites ssl::server_name “/usr/local/etc/squid/nobumpsites.acl”
2024/08/03 05:15:32| Processing Configuration File: /usr/local/etc/squid/pre-auth/40-snmp.conf (depth 1)
2024/08/03 05:15:32| Processing Configuration File: /usr/local/etc/squid/pre-auth/dummy.conf (depth 1)
2024/08/03 05:15:32| Processing Configuration File: /usr/local/etc/squid/pre-auth/parentproxy.conf (depth 1)
2024/08/03 05:15:32| ERROR: ACL not found: Safe_ports
2024/08/03 05:15:32| Not currently OK to rewrite swap log.
2024/08/03 05:15:32| storeDirWriteCleanLogs: Operation aborted.
2024/08/03 05:15:32| FATAL: Bungled /usr/local/etc/squid/squid.conf line 99: http_access deny !Safe_ports !unrestricted
2024/08/03 05:15:32| Squid Cache (Version 6.10): Terminated abnormally.
/usr/local/etc/rc.d/squid: WARNING: failed to start squid
最新版本
缺少两条访问控制 才能启动
/usr/local/etc/squid/squid.conf
acl Safe_ports port 80
acl SSL_ports port 443
启动成功!
这两条命令,应该可以在正向代理>访问控制列表,允许目标tcp端口处进行添加,教程添加了这一部分内容。
尝试按你说的加这两条规则 发现不行 会导致访问任何网站都报ssl错误
。。。。。
教程有完善 我再测试一下
。。。。。。
再修改 app都能用 就电报不行 奇了怪了
我测试了是可以的。下面是的我squid.conf的配置。
#
# Automatic generated configuration for Squid.
# Do not edit this file manually.
#
# Setup transparent mode listeners on loopback interfaces
http_port 127.0.0.1:3128 intercept ssl-bump cert=/var/squid/ssl/ca.pem dynamic_cert_mem_cache_size=10MB generate-host-certificates=on
http_port [::1]:3128 intercept ssl-bump cert=/var/squid/ssl/ca.pem dynamic_cert_mem_cache_size=10MB generate-host-certificates=on
https_port 127.0.0.1:3129 intercept ssl-bump cert=/var/squid/ssl/ca.pem dynamic_cert_mem_cache_size=10MB generate-host-certificates=on
https_port [::1]:3129 intercept ssl-bump cert=/var/squid/ssl/ca.pem dynamic_cert_mem_cache_size=10MB generate-host-certificates=on
# Setup regular listeners configuration
http_port 192.168.101.250:3128 ssl-bump cert=/var/squid/ssl/ca.pem dynamic_cert_mem_cache_size=10MB generate-host-certificates=on
# setup ssl re-cert
sslcrtd_program /usr/local/libexec/squid/security_file_certgen -s /var/squid/ssl_crtd -M 10MB
sslcrtd_children 25
tls_outgoing_options options=NO_TLSv1 cipher=HIGH:MEDIUM:!RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS
# setup ssl bump acl’s
acl bump_step1 at_step SslBump1
acl bump_step2 at_step SslBump2
acl bump_step3 at_step SslBump3
acl bump_nobumpsites ssl::server_name “/usr/local/etc/squid/nobumpsites.acl”
# configure bump
ssl_bump peek bump_step1 all
ssl_bump splice all
ssl_bump peek bump_step2 all
ssl_bump splice bump_step3 all
ssl_bump bump
sslproxy_cert_error deny all
acl ftp proto FTP
http_access allow ftp
# Setup ftp proxy
# Rules allowing access from your local networks.
# Generated list of (internal) IP networks from where browsing
# should be allowed. (Allow interface subnets).
acl localnet src 192.168.101.0/24 # Possible internal network (interfaces v4)
# Default allow for local-link and private networks
acl localnet src fc00::/7 # RFC 4193 local private network range
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
# ACL – Allow localhost for PURGE cache if enabled
# ACL lists
# ACL – Remote fetched Blacklist (remoteblacklist)
# ACL – Block browser/user-agent – User defined (browser)
# ACL – SSL ports, default are configured in config.xml
acl SSL_ports port 443 # https
# Default Safe ports are now defined in config.xml
# ACL – Safe_ports
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
# ICAP SETTINGS
# disable icap
icap_enable off
# Pre-auth plugins
include /usr/local/etc/squid/pre-auth/*.conf
# Authentication Settings
# Google Suite Filter
# YouTube Filter
request_header_add YouTube-Restrict moderate
# Deny requests to certain unsafe ports
http_access deny !Safe_ports
# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports
# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager
# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on “localhost” is a local user
http_access deny to_localhost
# Auth plugins
include /usr/local/etc/squid/auth/*.conf
#
# Access Permission configuration:
#
# Deny request from unauthorized clients
#
# ACL – localnet – default these include ranges from selected interfaces (Allow local subnets)
http_access allow localnet
# ACL – localhost
http_access allow localhost
# Deny all other access to this proxy
http_access deny all
# Post-auth plugins
include /usr/local/etc/squid/post-auth/*.conf
# Caching settings
cache deny all
cache_mem 0
# Leave coredumps in the first cache dir
coredump_dir /var/squid/cache
#
# Add any of your own refresh_pattern entries above these.
#
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320
# Squid Options
pinger_enable off
# Disable access logging
access_log none
# Disable cache store log
cache_store_log none
# Suppress http version string (default=off)
httpd_suppress_version_string on
# URI handling with Whitespaces (default=strip)
uri_whitespace strip
# Disable squid logfile rotate to use system defaults
logfile_rotate 0
# Define visible hostname
visible_hostname wall.pfchina.org
# Define visible email
cache_mgr [email protected]
# Set error directory language
error_directory /usr/local/share/squid-langpack/en
使用是可以了 我后面加了分割线
但是电报不能用 其他能用
我测试电报可以正常使用,可能是clash配置文件本身的问题。你可以试试sing-box。
奇怪了 同配置我在openwrt是可以使用的
是不是可以再写一个脚本定时下载配置,达到订阅更新的目的?
pfSense可以安装cron插件解决这个问题,OPNsense稍微复杂一点,参考这个就可以:https://gist.github.com/PiDroid-B/078198bc84c1e8451d5fd331b46b332d
/usr/local/bin/clash -d /usr/local/etc/clash
重启后这个bin文件和目录全部消失了。。。
忽略,我的在root下
除非是在线运行模式,否则是不可能出现这种情况的。