Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - deddey

#1
opnsense因为基于freeBSD + packet filtering 的,这和大多数linux下的环境不同,所以常见的科学上网如V2Ray、clash、shadowsocks等等的redirect(数据包重定向)在opnsense都没法使用。但在某些情况下确实又需要透明代理的功能,比如机顶盒这类不方便安装的,或者大量的机器不想一个一个维护的。
通过摸索,确实有这么一个方式能够在opnsense中实现透明代理科学上网的方法,但是这方法现在还不适合UDP连接,而且稍显复杂。
首先说一下基本方法的吧,抛砖引玉,希望有大神看到能给更简单、更方便的方法,或者能出一个opnsense的插件实现就更好了。
刚才说到,常见的科学上网工具并没有在opnsense中直接实现redirect功能的,但是在opnsense中其实已经有了能实现透明代理的工具,而且不是插件,是包含在opnsense基础功能中的,这就是 服务 > web代理,这个是由squid实现的,通过简单的设置就可以实现透明代理功能,实现网络中http(s)流量通过代理来访问。
squid为缓存而设计,并没有科学上网的功能。但是它却开了另一个窗户,能实现一种曲折但可行的方法,那就是squid支持父级代理,就是把squid代理的流量送到另一个代理来代理。说到这大家应该明白了,squid的父级代理如果能科学上网,那不就是在opnsense中实现了使用透明代理科学上网了。
虽然这个方法挺曲折的,但其实实践下来其实也挺好用的。各种工具中最适合做squid的父级代理的是clash,不但支持分流、web页面控制,还能自动更新节点列表和分流规则,不用老是手动传配置文件。

基本方法说完了,下面简单说一下如何实现的。注意,这里说的简单说一下,是真的"简单"说一下,小白就此打住吧。
首先是web代理的设置,请参考官方文档https://docs.opnsense.org/manual/proxy.html,完成启用并实现透明代理功能。不同的是在正向代理>转发常规设置中,要勾选 "仅记录SNI信息" ,这个可以实现在不需要在终端中安装证书。(如果你有缓存https流量的需求,请按文档操作)完成后在终端中测试一下,方法是不启用任何代理访问一个网站,这网站出现在 Access Log中,说明透明代理设置成功。
在  代理常规设置 > 父代理设置  中填写相应信息,对clash来说一般IP和端口是 127.0.0.1:7890,这个在clash设置完成后再启用。
然后是在opnsense中的捣鼓一个clash出来,因为没有现成插件,这个只有手动了。
首先准备要上传的文件。第一个是clash程序本身,记得是freebsd版的,个人建议premium版,(https://github.com/Dreamacro/clash/releases/tag/premium) 因为Rule Providers功能,毕竟这里配置传一次挺麻烦,尽量一份配置能一直用不用随时改。第二个是你的配置文件config.yaml,可以把神机规则拿来修改待用,(https://github.com/DivineEngine/Profiles/blob/master/Clash/Outbound.yaml) 为启用web控制界面要修改这两排

external-controller: 0.0.0.0:9090
external-ui: ./ui

如果在配置中引用了外部的节点列表和分流规则,请先在本地按这个配置先运行一次clash,把节点列表和分流规则先下载下来准备好,否则在opnsense中直接运行clash,会因为某些墙外的连接无法下载而启动失败。第三个是web控制界面clash dashboard (https://github.com/Dreamacro/clash-dashboard/archive/gh-pages.zip),下载、解压、修改文件夹名为"ui"。以上准备完后,有clash,config.yaml两个文件和 Proxy、RuleSet、ui三个文件夹。
然后是手动安装了,通过ssh登录,把刚才准备的文件都上传,然后复制clash执行程序到 /usr/local/bin/clash,修改程序所有者为 root:wheel ,添加执行权限,新建 /usr/local/etc/clash 文件夹,把config.yaml和 Proxy、RuleSet、ui三个文件夹 复制/usr/local/etc/clash下面,修改 /usr/local/etc/clash 和下面所有文件所有者为 root:wheel 。
在shell输入 "/usr/local/etc/clash -d  /usr/local/bin/clash"测试一下,如果能跑起来说明clash可以正常运行了
可以正常运行之后,需要把clash设置为系统服务,让opnsense开机启动clash。但这个有个坑,因为clash作为系统服务启动后,并没有完成启动后就保持后台运行的功能,这样每次系统重启后会启动到clash之后就不会往后走,因该clash一直会保持在前台,导致排在clash后面的待启动服务就没法启动了。所以这里需要一个变通的办法,通过monit来管理启动clash。下面是具体的干货:


vi /usr/local/etc/rc.d/clash #建立服务配置文件
chmod +x /usr/local/etc/rc.d/clash #给刚才建立服务配置文件添加执行权限


服务配置文件内容如下:

#!/bin/sh
# $FreeBSD$

# PROVIDE: clash
# REQUIRE: LOGIN cleanvar
# KEYWORD: shutdown

# Add the following lines to /etc/rc.conf to enable clash:
# clash_enable (bool):  Set to "NO" by default.
#      Set to "YES" to enable clash.
# clash_config (path): Clash config dir.
#      Defaults to "/usr/local/etc/clash"


. /etc/rc.subr

name="clash"
rcvar=clash_enable


load_rc_config $name

: ${clash_enable:="NO"}
: ${clash_config="/usr/local/etc/clash"}

command="/usr/local/bin/clash"
#pidfile="/var/run/clash.pid"
required_files="${clash_config}"

command_args="-d $clash_config"

run_rc_command "$1"


这里没法生成pid文件,所以 pidfile="/var/run/clash.pid" 这行注释掉了,这个问题还请能有大神解答

然后建立/usr/local/opnsense/service/conf/actions.d/actions_clash.conf 文件,这个方便monit管理启动clash。

vi /usr/local/opnsense/service/conf/actions.d/actions_clash.conf
service configd restart #使刚才的文件生效

actions_clash.conf文件内容如下

[start]
command:/usr/local/etc/rc.d/clash onestart
type:script
message:starting clash

[stop]
command:/usr/local/etc/rc.d/clash stop
type:script
message:stoping clash

[status]
command:/usr/local/etc/rc.d/clash statusexit 0
type:script_output
message:get clash status

[restart]
command:/usr/local/etc/rc.d/clash onerestart
type:script
message:restarting clash


最后,终于到最后了,启用monit服务,参考官方文档https://docs.opnsense.org/manual/monit.html?highlight=monit
在monit的 Service Tests Settings 中添加两个:

第一个

| Setting   | Value                                    |
| --------- | ---------------------------------------- |
| Name      | Clash                                    |
| Condition | failed host 127.0.0.1 port 7890 type tcp |
| Action    | Restart                                  |

第二个,避免重启死循环

| Setting   | Value                                    |
| --------- | ---------------------------------------- |
| Name      | RestartLimit4                            |
| Condition | 5 restarts within 5 cycles               |
| Action    | Unmonitor                                |

在monit的 Service Settings 中添加:

| Setting   | Value                                    |
| --------- | ---------------------------------------- |
| Name      | Clash                                    |
| Match     | clash                                    |
| Start     | /usr/local/sbin/configctl clash start    |
| Stop      | /usr/local/sbin/configctl clash stop     |
| Tests     | Clash,RestartLimit4                      |

完成后隔一会,monit会启动clash,在终端中输入 /usr/local/sbin/configctl clash status,查看clash运行状态。

至此,使用透明代理科学上网完成,别忘了在web代理中启用刚才说的父代理功能。

注:这里也可以直接将 "网关地址":7890  作为代理服务使用,但前提是需要的规则中允许 lan网络 到 "网关地址":7890 的连接。
#2
In China, because of the relationship of GFW, tor can not be directly connected. If you need to use tor, you need to add a pre-proxy. The shadowsocks plugin in onsense can be used as a good pre-agent to add pre-proxy options to the tor plugin.
#3
18.7 Legacy Series / about wpad/pac question
October 09, 2018, 08:02:32 PM
first,thanks for the update in wpad/pac

question 1:
when I used the Matches "IP Is In Network",the wpad.dat like this:

if (((isInNet(dstip, "10.0.0.0", "255.0.0.0")))) {
reture "DIRECT";
}

compare with "https://github.com/opnsense/core/blob/master/src/opnsense/service/templates/OPNsense/Proxy/wpad.dat"

I think the wpad.dat is missing "var dstip = dnsResolve(host);"

question 2:
I think These rules should be in order to determine which one is a priority match, and which one is a second match.

Thanks again, please forgive me for my poor English.
#4
一前一直通过genpac自动转换gfwlist生成wpad.pac文件,手动把wpad.pac拷入 /usr/local/www/,手动在unbound中添加wpad的解析,来达到科学上网的目的
今天跟新了18.7.4,发现wpad.pac文件被自动更新了,原来真是一个新功能,https://wiki.opnsense.org/manual/how-tos/pac.html
出来转换gfwlist到pac的步骤,其他都不用手动了
各位,在新功能下有啥办法转换gfwlist到pac吗?
可以写个python转换gfwlist到opnsense的配置然后导入,不过我就会一点点python。
各位有其他办法吗?
#5
Chinese - 中文 / shadowsocks插件即将可用
February 22, 2018, 04:57:08 AM
感谢opnsense的开发团队,shadowsocks插件现在正在测试阶段,待稳定后即可发布。
该插件基于shadowsocks-libev,可作为ss服务器端和客户端使用,不支持ssr。
因freebsd系统限制,不支持ss-redir模式。
#6
18.1 Legacy Series / shadowsocks-local can't service
February 09, 2018, 06:46:47 AM
I'm sorry for my poor english

I install os-shadowsocks-devel-0.2.txz,the ShadowSocks Server is good,but the ShadowSocks Local is bad,

because of "/usr/local/etc/rc.d/opnsense-ss-local" is not executable.

another problem:
the config file "/usr/local/etc/shadowsocks-libev/local.json" need to add a line like this:

     "local_address":"LAN address eg:192.168.1.1",

for open a socket port on the IP of LAN address. the default ip is 127.0.0.1 can't service for LAN user.


#7
Chinese - 中文 / opnsense 17.7试用
August 06, 2017, 01:23:41 PM
正好pfsense的硬盘快挂了,找了台旧电脑,试用了17.7,感觉不错,正式切换过来

常用的squid和IPS也集成了,不用装插件了

不习惯的就是各种测试信息工具放在不同的菜单下,像ping、socket dump、dhcp lease等,

netflows很赞,

squid的cache log能有分析工具就好了

squid 和 unbound 依然无法和 mutli wan 和平相处

另外,墙的问题有好的办法没有?

最后,严重感谢@tianmo 的辛苦的翻译
#8
在System: Configuration: Backups中,没有DNS Resolver的备份和恢复选项。

in System: Configuration: Backups,i can't backup or restore the DNS Resolver's configuration
#9
升级服务器实在很慢,试了好几次都升级不成功。我看下载服务器有中国地区的,能手动选择吗?