docker-easyconnect / docker-easyconnect

使深信服(Sangfor)开发的非自由的 VPN 软件 EasyConnect 和 aTrust 运行在 docker 或 podman 中,并作为网关和/或提供 socks5、http 代理服务
Do What The F*ck You Want To Public License
3.63k stars 331 forks source link

Can't find available method to automatically set route for opening ports #97

Closed ghost-909 closed 2 years ago

ghost-909 commented 2 years ago

Ghost@Ghostserver:~$ sudo docker run --device /dev/net/tun --cap-add NET_ADMIN -ti -p 127.0.0.1:1080:1080 -p 127.0.0.1:8888:8888 -e EC_VER=7.6.8 -e CLI_OPTS="-d 117.141.120.131 -u 10053612 -p xxxx" hagb/docker-easyconnect:cli update-alternatives: using /usr/sbin/iptables-legacy to provide /usr/sbin/iptables (iptables) in manual mode update-alternatives: using /usr/sbin/ip6tables-legacy to provide /usr/sbin/ip6tables (ip6tables) in manual mode Can't find available method to automatically set route for opening ports (refer to https://github.com/Hagb/docker-easyconnect/tree/master/doc/route.md) WARNING: logging deactivated (can't log to stdout when daemonized) auto login is disabled user "10053612" login successfully!

我把容器运行在群晖上,看这个信息输出是登录成功了吗? 但是我用windows机器去连接群晖的1080和8888端口,都连接不上。这个是啥情况呢?

hagb/docker-easyconnect cli bc1ed22af3b9 3 months ago 117MB

ghost-909 commented 2 years ago

运行以下命令后,提示消失,但仍然连不上两个端口

sudo insmod /lib/modules/iptable_mangle.ko sudo insmod /lib/modules/xt_mark.ko

Hagb commented 2 years ago

运行以下命令后,提示消失,但仍然连不上两个端口

sudo insmod /lib/modules/iptable_mangle.ko sudo insmod /lib/modules/xt_mark.ko

“连接不上”具体有什么提示不?(比如是超时、拒绝连接还是重设之类的)

ghost-909 commented 2 years ago

我的docker跑在家里的群晖上,当群晖上的容器跑起来之后,使用以下命令能看到VPN已经获取到了服务器分配的内部地址(公司分配的VPN地址都是10.196开头的) sudo docker exec -it 6b3a5f0d5df7 cat /usr/share/sangfor/EasyConnect/resources/logs/CSClient.log | grep 10.196 在家里与群晖同一网段的windows电脑上使用端口扫描器扫描群晖的IP地址(192.168.0.17),没看到1080和8888端口打开。 使用浏览器设置代理的IP为192.168.0.17(端口为1080或8888),浏览器上不了网 在容器内部尝试ping 公司的内网地址,ping不通 同时在公司尝试使用ssh到docker得到的10.196.xx.xx地址,连接超时 总的感觉就是,docker登录VPN成功了,但是根本用不了

Hagb commented 2 years ago

我的docker跑在家里的群晖上,当群晖上的容器跑起来之后,使用以下命令能看到VPN已经获取到了服务器分配的内部地址(公司分配的VPN地址都是10.196开头的) sudo docker exec -it 6b3a5f0d5df7 cat /usr/share/sangfor/EasyConnect/resources/logs/CSClient.log | grep 10.196 在家里与群晖同一网段的windows电脑上使用端口扫描器扫描群晖的IP地址(192.168.0.17),没看到1080和8888端口打开。 使用浏览器设置代理的IP为192.168.0.17(端口为1080或8888),浏览器上不了网 在容器内部尝试ping 公司的内网地址,ping不通 同时在公司尝试使用ssh到docker得到的10.196.xx.xx地址,连接超时 总的感觉就是,docker登录VPN成功了,但是根本用不了

看看在容器里运行 ifconfig 的输出有没有 tun0 设备,ip route 的输出有没有指向 tun0 的路由?

ghost-909 commented 2 years ago

运行ifconfig命令可以看到tun0的设备

root@edea4e76df33:/# busybox ifconfig eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02
inet addr:172.17.0.2 Bcast:172.17.255.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:663738 errors:0 dropped:0 overruns:0 frame:0 TX packets:1244821 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:73620702 (70.2 MiB) TX bytes:86041247 (82.0 MiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:276 errors:0 dropped:0 overruns:0 frame:0 TX packets:276 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:180474 (176.2 KiB) TX bytes:180474 (176.2 KiB)

tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.196.0.144 P-t-P:10.196.0.144 Mask:255.255.255.0 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1400 Metric:1 RX packets:13735 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:500 RX bytes:1040644 (1016.2 KiB) TX bytes:0 (0.0 B)

运行 ip route命令看到是这样的,能看到公司内部的172网段指向了eth0设备

root@edea4e76df33:/# busybox ip route default via 172.17.0.1 dev eth0 10.1.3.2 dev tun0 scope link 10.1.3.4 dev tun0 scope link 10.1.3.5 dev tun0 scope link 10.1.3.6 dev tun0 scope link 10.1.3.8 dev tun0 scope link 10.1.3.10 dev tun0 scope link 10.1.3.12 dev tun0 scope link 10.1.3.13 dev tun0 scope link 10.1.3.24 dev tun0 scope link 10.1.3.25 dev tun0 scope link 10.1.40.100 dev tun0 scope link 10.10.10.10 dev tun0 scope link 10.10.10.250 dev tun0 scope link 10.10.10.251 dev tun0 scope link 10.10.20.1 dev tun0 scope link 10.11.20.1 dev tun0 scope link 10.12.10.254 dev tun0 scope link 10.13.10.254 dev tun0 scope link 10.14.10.254 dev tun0 scope link 10.15.10.254 dev tun0 scope link 10.18.21.1 dev tun0 scope link 10.18.21.2/31 dev tun0 scope link 10.18.21.4/30 dev tun0 scope link 10.18.21.8/29 dev tun0 scope link 10.18.21.16/28 dev tun0 scope link 10.18.21.32/27 dev tun0 scope link 10.18.21.64/26 dev tun0 scope link 10.18.21.128/26 dev tun0 scope link 10.18.21.192/27 dev tun0 scope link 10.18.21.224/28 dev tun0 scope link 10.18.21.240/29 dev tun0 scope link 10.18.21.248/30 dev tun0 scope link 10.18.21.252/31 dev tun0 scope link 10.18.21.254 dev tun0 scope link 10.18.22.1 dev tun0 scope link 10.18.22.2/31 dev tun0 scope link 10.18.22.4/30 dev tun0 scope link 10.18.22.8/29 dev tun0 scope link 10.18.22.16/28 dev tun0 scope link 10.18.22.32/27 dev tun0 scope link 10.18.22.64/26 dev tun0 scope link 10.18.22.128/26 dev tun0 scope link 10.18.22.192/27 dev tun0 scope link 10.18.22.224/28 dev tun0 scope link 10.18.22.240/29 dev tun0 scope link 10.18.22.248/30 dev tun0 scope link 10.18.22.252/31 dev tun0 scope link 10.18.22.254 dev tun0 scope link 10.18.23.1 dev tun0 scope link 10.18.23.2/31 dev tun0 scope link 10.18.23.4/30 dev tun0 scope link 10.18.23.8/29 dev tun0 scope link 10.18.23.16/28 dev tun0 scope link 10.18.23.32/27 dev tun0 scope link 10.18.23.64/26 dev tun0 scope link 10.18.23.128/26 dev tun0 scope link 10.18.23.192/27 dev tun0 scope link 10.18.23.224/28 dev tun0 scope link 10.18.23.240/29 dev tun0 scope link 10.18.23.248/30 dev tun0 scope link 10.18.23.252/31 dev tun0 scope link 10.18.23.254 dev tun0 scope link 10.18.24.1 dev tun0 scope link 10.18.24.2/31 dev tun0 scope link 10.18.24.4/30 dev tun0 scope link 10.18.24.8/29 dev tun0 scope link 10.18.24.16/28 dev tun0 scope link 10.18.24.32/27 dev tun0 scope link 10.18.24.64/26 dev tun0 scope link 10.18.24.128/26 dev tun0 scope link 10.18.24.192/27 dev tun0 scope link 10.18.24.224/28 dev tun0 scope link 10.18.24.240/29 dev tun0 scope link 10.18.24.248/30 dev tun0 scope link 10.18.24.252/31 dev tun0 scope link 10.18.24.254 dev tun0 scope link 10.18.110.235 dev tun0 scope link 10.196.0.0/24 dev tun0 scope link src 10.196.0.144 10.208.12.121 dev tun0 scope link 10.208.12.122 dev tun0 scope link 10.208.12.123 dev tun0 scope link 172.16.0.8 dev tun0 scope link 172.16.0.61 dev tun0 scope link 172.16.0.62/31 dev tun0 scope link 172.16.0.64/31 dev tun0 scope link 172.16.0.70/31 dev tun0 scope link 172.16.0.72/29 dev tun0 scope link 172.16.0.80/31 dev tun0 scope link 172.16.0.99 dev tun0 scope link 172.16.0.101 dev tun0 scope link 172.16.0.102 dev tun0 scope link 172.16.0.103 dev tun0 scope link 172.16.0.110 dev tun0 scope link 172.16.0.140 dev tun0 scope link 172.16.0.160 dev tun0 scope link

Hagb commented 2 years ago

运行以下命令后,提示消失,但仍然连不上两个端口

sudo insmod /lib/modules/iptable_mangle.ko sudo insmod /lib/modules/xt_mark.ko

在家里与群晖同一网段的windows电脑上使用端口扫描器扫描群晖的IP地址(192.168.0.17),没看到1080和8888端口打开。

~尝试在宿主机中运行~ ~iptables -I POSTROUTING -d 容器ip地址 -p tcp -m tcp --dport 1080 -j MASQUERADE -t nat~ ~iptables -I POSTROUTING -d 容器ip地址 -p tcp -m tcp --dport 8888 -j MASQUERADE -t nat~

~之后看看能不能连接代理端口~

emmm 仔细看了看 issue 正文,看起来你启动容器时没有将端口开放。将 -p 127.0.0.1:1080:1080 -p 127.0.0.1:8888:8888 改成 -p 1080:1080 -p 8888:8888 将端口设为开放状态

在容器内部尝试ping 公司的内网地址,ping不通

尝试使用 busybox wget http://xxx.xxx.xxx.xxx 来访问内网的一个 http 服务,看看能不能正常访问?

如果不行,发一下上面 busybox wget 命令和 iptables -Siptables -S -t nat 的输出

同时在公司尝试使用ssh到docker得到的10.196.xx.xx地址,连接超时

  1. 之前没想到可能会有从 vpn 那边连接容器的情形(事实上我甚至不知道 easyconnect 对此有支持,在我们学校这个 ip 是共用的),所以直接 drop 了从 vpn 那边主动发起的连接
  2. 即使接受这样的连接,直接 ssh 连的话只会连到容器中的网络,而不会直接连到宿主机的 ssh 端口中

如果想尝试这种连接有没有可能,可以在容器里运行

iptables -I INPUT -p tcp -j ACCEPT  #接受连接
busybox httpd -fvvv -p8080 #开一个用于测试的http服务端

之后在内网访问容器 ip 的 8080 端口看看能不能连上。

ghost-909 commented 2 years ago

感谢楼主!将 -p 127.0.0.1:1080:1080 -p 127.0.0.1:8888:8888 改成 -p 1080:1080 -p 8888:8888后,端口成功打开并且连上内网了!

接下来运行 iptables -I INPUT -p tcp -j ACCEPT #接受连接 busybox httpd -fvvv -p8080 #开一个用于测试的http服务端

然后在内网用浏览器访问,虽然提示404找不到,但是容器内有以下回显,这个月应该是成功了吧?

root@79e38ed6bb94:/# busybox httpd -fvvv -p8080 [::ffff:172.19.23.192]:56897: connected [::ffff:172.19.23.192]:56897: url:/ [::ffff:172.19.23.192]:56897: response:404 [::ffff:172.19.23.192]:56897: closed [::ffff:172.19.23.192]:56899: connected [::ffff:172.19.23.192]:56899: url:/favicon.ico [::ffff:172.19.23.192]:56899: response:404 [::ffff:172.19.23.192]:56899: closed [::ffff:172.19.23.192]:56926: connected

Hagb commented 2 years ago

然后在内网用浏览器访问,虽然提示404找不到,但是容器内有以下回显,这个月应该是成功了吧?

root@79e38ed6bb94:/# busybox httpd -fvvv -p8080 [::ffff:172.19.23.192]:56897: connected [::ffff:172.19.23.192]:56897: url:/ [::ffff:172.19.23.192]:56897: response:404 [::ffff:172.19.23.192]:56897: closed [::ffff:172.19.23.192]:56899: connected [::ffff:172.19.23.192]:56899: url:/favicon.ico [::ffff:172.19.23.192]:56899: response:404 [::ffff:172.19.23.192]:56899: closed [::ffff:172.19.23.192]:56926: connected

嗯,看来确实有这种从 vpn 一侧访问客户端的可能…

ghost-909 commented 2 years ago

老大,用busybox httpd开一个8080端口虽然能从公司端访问一下,但从公司端还是访问不到容器开的8888和1080端口啊

在家里反而是另外一种情况:能访问容器的1080和8888端口,但是却访问不到busybox httpd开的8080端口

Hagb commented 2 years ago

老大,用busybox httpd开一个8080端口虽然能从公司端访问一下,但从公司端还是访问不到容器开的8888和1080端口啊

这是预期情况,策略路由的方式导致的(详见 docker-root/usr/local/bin/detect-route.sh)。另外从公司端访问容器的 8888 和 1080 端口有什么作用吗?

在家里反而是另外一种情况:能访问容器的1080和8888端口,但是却访问不到busybox httpd开的8080端口

要在启动容器时开放 8080 端口,启动容器后运行

ip rule add iif lo table 2 sport 8080
ghost-909 commented 2 years ago

老大,用busybox httpd开一个8080端口虽然能从公司端访问一下,但从公司端还是访问不到容器开的8888和1080端口啊

这是预期情况,策略路由的方式导致的(详见 docker-root/usr/local/bin/detect-route.sh)。另外从公司端访问容器的 8888 和 1080 端口有什么作用吗?

大神啊,我水平有限,搞不懂这个路由表啊。能不能直接告诉我如何实现公司端和家里都能访问容器的8888和1080端口 单位的网络封锁了一些IP(比如onedrive,onenote,bilibili等等),所以我需要通过容器作为代理来转发

Hagb commented 2 years ago

大神啊,我水平有限,搞不懂这个路由表啊。能不能直接告诉我如何实现公司端和家里都能访问容器的8888和1080端口

我没想出这个该怎么搞。但是可以换个思路,在 CentOS 上安装 dante server,将公司那一侧对容器的访问转发到 CentOS 的这个端口上(下面设为 1081)。

使用 hagb/docker-easyconnect:dev-cli 加上环境变量参数 -e FORWARD=1081:172.17.0.1:1081,然后从公司那一侧访问容器 1081 端口。

ghost-909 commented 2 years ago

老大,如果能通过修改容器的路由策略能达成,最好还是修改路由表来实现吧。否则我只有群晖,要多折腾一个dante的容器,水平有限,说不定是另外一个大坑……

Hagb commented 2 years ago

如果能通过修改容器的路由策略能达成,最好还是修改路由表来实现吧。

如果按照你原原本本的话,访问 1080 端口那个 socks 服务端,难以办到(起码我是没有找到办法)

否则我只有群晖,要多折腾一个dante的容器,水平有限,说不定是另外一个大坑……

为了摸鱼已经不择手段了么😂

这种是不依赖于路由策略的方式: 在 EasyConnect 容器的 /tmp/danted2.conf 写入

internal: 0.0.0.0 port = 1081
external: eth0
socksmethod: none
clientmethod: none
client pass {
        from: 0/0 to: 0/0
}
socks pass {
        from: 0/0 to: 0.0.0.0/0
}

再在容器中运行

iptables -D INPUT -i tun0 -p 6 -j DROP
danted -D -f /tmp/danted2.conf

能不能成功我不确定,我没测试,应该可以。

之前没说这种方式,主要是需要手动操作(起码我是没有足够理由说服自己把它实现到脚本的),而端口转发的方式更具有普遍性,值得去实现

ghost-909 commented 2 years ago

好吧,既然大佬认为端口转发的方法可行,那我就试试用dante的容器来试试看吧。我说下我的步奏

首先我找了一个dante的容器(https://hub.docker.com/r/bakasura/dante2) 然后用以下命令跑了起来 $ docker run -e workers=20 -d -p 5555:1080 bakasura/dante2

然后找到dante容器的IP是172.17.0.2.

然后使用以下命令测试,curl --proxy socks5://localhost:5555 -L ip.tool.lu 有返回值 当前IP: 117.140.26.107 归属地: 中国 广西 玉林

到此我认为dante容器应该正常了,我接下来去弄EC容器

按照你的说法,我试用一下命令启动容器: docker run --device /dev/net/tun --cap-add NET_ADMIN -ti -p 1080:1080 -p 8888:8888 -e EC_VER=7.6.8 -e FORWARD=5555:172.17.0.2:5555 -e CLI_OPTS="-d 117.141.120.131 -u xxxxx -p xxx" hagb/docker-easyconnect:cli

结果在家里扫描群晖的IP地址,1080,5555,8888端口都打开了,但是在公司端扫描vpn地址(10.196.1.33),什么端口都没开。 这个是啥情况呢?

Hagb commented 2 years ago

启动 easyconnect 容器时加上参数 --link=danted容器的容器名 这个容器名可以用 docker container ls 来查看,或者启动 danted 容器时通过 --name=容器名 来人为指定

ghost-909 commented 2 years ago

启动EC容器加上--link=danted容器的容器名了,也进入容器内部输入以下命令了(iptables -I INPUT -p tcp -j ACCEPT)

但是EC内网地址(10.196.1.33)的任何端口(1080,5555,8888)都没有打开啊,在公司端访问容器的VPN内网地址都不通呢

端口没打开跟--link参数没关系吧?

但使用以下命令(busybox httpd -fvvv -p8080),在公司端访问10.196.1.33:8080却有反应(端口打开)。真是奇怪

Ghost

From: Hagb (Junyu Guo 郭俊余) Date: 2022-02-14 17:21 To: Hagb/docker-easyconnect CC: ghost-909; Author Subject: Re: [Hagb/docker-easyconnect] Can't find available method to automatically set route for opening ports (Issue #97) 启动 easyconnect 容器时加上参数 --link=danted容器的容器名 这个容器名可以用 docker container ls 来查看,或者启动 danted 容器时通过 --name=容器名 来人为指定 — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.Message ID: @.***>

Hagb commented 2 years ago

但使用以下命令(busybox httpd -fvvv -p8080),在公司端访问10.196.1.33:8080却有反应(端口打开)。真是奇怪

这是预期现象。所以前面(https://github.com/Hagb/docker-easyconnect/issues/97#issuecomment-1038585802 )我还提供了另一种在 easyconnect 容器里就地开 1081 端口 danted 的方式。

启动EC容器加上--link=danted容器的容器名了,也进入容器内部输入以下命令了(iptables -I INPUT -p tcp -j ACCEPT)

但是EC内网地址(10.196.1.33)的任何端口(1080,5555,8888)都没有打开啊,在公司端访问容器的VPN内网地址都不通呢

你用的是 hagb/docker-easyconnect:cli 还是 hagb/docker-easyconnect:dev-cli? 我加了端口转发功能的是后者。另外,如果用端口转发的话就没必要手动运行那个 iptables 了

端口没打开跟--link参数没关系吧?

有的。不加的话 docker 默认情况下会阻断不同容器之间的互访。

ghost-909 commented 2 years ago

老大我重新下载了你的hagb/docker-easyconnect:dev-cli镜像,然后如下启动容器

docker run --device /dev/net/tun --cap-add NET_ADMIN -ti -p 1080:1080 -p 8888:8888 --link=gallant_benz -e EC_VER=7.6.8 -e FORWARD=5555:172.17.0.2:5555 -e CLI_OPTS="-d 117.141.120.131 -u xxx -p xxx" hagb/docker-easyconnect:dev-cli

其中172.17.0.2是dante的容器地址,gallant_benz是dante容器的名字

但是经过在单位扫描10.196.1.33的端口,还是没有任何端口开放呢

Ghost

From: Hagb (Junyu Guo 郭俊余) Date: 2022-02-15 11:25 To: Hagb/docker-easyconnect CC: ghost-909; Author Subject: Re: [Hagb/docker-easyconnect] Can't find available method to automatically set route for opening ports (Issue #97) 但使用以下命令(busybox httpd -fvvv -p8080),在公司端访问10.196.1.33:8080却有反应(端口打开)。真是奇怪 这是预期现象。所以前面(#97 (comment) )我还提供了另一种在 easyconnect 容器里就地开 1081 端口 danted 的方式。 启动EC容器加上--link=danted容器的容器名了,也进入容器内部输入以下命令了(iptables -I INPUT -p tcp -j ACCEPT) 但是EC内网地址(10.196.1.33)的任何端口(1080,5555,8888)都没有打开啊,在公司端访问容器的VPN内网地址都不通呢 你用的是 hagb/docker-easyconnect:cli 还是 hagb/docker-easyconnect:dev-cli? 我加了端口转发功能的是后者。另外,如果用端口转发的话就没必要手动运行那个 iptables 了 端口没打开跟--link参数没关系吧? 有的。不加的话 docker 默认情况下会阻断不同容器之间的互访。 — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.Message ID: @.***>

Hagb commented 2 years ago

我又翻了翻前面,这个 dante 容器开的端口是 1080 吧。5555 只是你映射到宿主机的,但并不会应用到 172.17.0.2。所以 FORWORD 参数应该是 xxxx:172.17.0.2:1080 (xxxx 自己定)。

ghost-909 commented 2 years ago

哈哈哈,谢谢老大,这次把端口修改后果然成功了!成功摸鱼!

ghost-909 commented 2 years ago

大哥,有不用进入容器内,查看VPN链接后的IP地址的方法吗?

Ghost

From: Hagb (Junyu Guo 郭俊余) Date: 2022-02-15 11:25 To: Hagb/docker-easyconnect CC: ghost-909; Author Subject: Re: [Hagb/docker-easyconnect] Can't find available method to automatically set route for opening ports (Issue #97) 但使用以下命令(busybox httpd -fvvv -p8080),在公司端访问10.196.1.33:8080却有反应(端口打开)。真是奇怪 这是预期现象。所以前面(#97 (comment) )我还提供了另一种在 easyconnect 容器里就地开 1081 端口 danted 的方式。 启动EC容器加上--link=danted容器的容器名了,也进入容器内部输入以下命令了(iptables -I INPUT -p tcp -j ACCEPT) 但是EC内网地址(10.196.1.33)的任何端口(1080,5555,8888)都没有打开啊,在公司端访问容器的VPN内网地址都不通呢 你用的是 hagb/docker-easyconnect:cli 还是 hagb/docker-easyconnect:dev-cli? 我加了端口转发功能的是后者。另外,如果用端口转发的话就没必要手动运行那个 iptables 了 端口没打开跟--link参数没关系吧? 有的。不加的话 docker 默认情况下会阻断不同容器之间的互访。 — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.Message ID: @.***>

ghost-909 commented 2 years ago

啊我懂了,可以通过以下命令来查看

docker exec -it ID/NAMES ip addr

Ghost

From: Ghost Date: 2022-02-16 14:57 To: Hagb/docker-easyconnect; Hagb/docker-easyconnect CC: Author Subject: Re: Re: [Hagb/docker-easyconnect] Can't find available method to automatically set route for opening ports (Issue #97) 大哥,有不用进入容器内,查看VPN链接后的IP地址的方法吗?

Ghost

From: Hagb (Junyu Guo 郭俊余) Date: 2022-02-15 11:25 To: Hagb/docker-easyconnect CC: ghost-909; Author Subject: Re: [Hagb/docker-easyconnect] Can't find available method to automatically set route for opening ports (Issue #97) 但使用以下命令(busybox httpd -fvvv -p8080),在公司端访问10.196.1.33:8080却有反应(端口打开)。真是奇怪 这是预期现象。所以前面(#97 (comment) )我还提供了另一种在 easyconnect 容器里就地开 1081 端口 danted 的方式。 启动EC容器加上--link=danted容器的容器名了,也进入容器内部输入以下命令了(iptables -I INPUT -p tcp -j ACCEPT) 但是EC内网地址(10.196.1.33)的任何端口(1080,5555,8888)都没有打开啊,在公司端访问容器的VPN内网地址都不通呢 你用的是 hagb/docker-easyconnect:cli 还是 hagb/docker-easyconnect:dev-cli? 我加了端口转发功能的是后者。另外,如果用端口转发的话就没必要手动运行那个 iptables 了 端口没打开跟--link参数没关系吧? 有的。不加的话 docker 默认情况下会阻断不同容器之间的互访。 — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.Message ID: @.***>

ghost-909 commented 2 years ago

老大你好,我想在容器启动、或链接、断开的时候,打印出相应的时间和获取到的VPN地址,请问在哪个文件中修改? Message ID: @.***>

user "10053612" login successfully! (这里加个时间和IP) svpn stop! (这里加个时间) Auth "10053612" by passowrd failed user "10053612" auto login failed auth failed, please check if the vpn address is valid and reachable! user "10053612" login FAILED! svpn stop! Auth "10053612" by passowrd failed user "10053612" auto login failed auth failed, please check if the vpn address is valid and reachable! user "10053612" login FAILED! svpn stop! user "10053612" auto login successfully

Hagb commented 2 years ago

可以用 date 命令打印时间。 在 https://github.com/Hagb/docker-easyconnect/blob/d1debe2dfcbba5210b7ee5a401a8380f01d362a4/docker-root/usr/local/bin/start-sangfor.sh#L28https://github.com/Hagb/docker-easyconnect/blob/d1debe2dfcbba5210b7ee5a401a8380f01d362a4/docker-root/usr/local/bin/start-sangfor.sh#L20

不过如果想要精确地输出到你要的那个地方,还有点麻烦

ghost-909 commented 2 years ago

老大你好,后来我在容器中运行ps命令也看到了这两个文件中的内容。

我的主要目的是这样子的: 容器每次运行都会获取一个内部的IP地址,我想在容器获取到IP地址后,容器运行一段sh脚本,将获取到的内部IP地址更新到域名上,这样我就不需要去修改各个软件中代理IP地址了(用域名代替了)

但是我看了start-sangfor.sh这个文件,内部IP地址应该是在17行执行这行代码之后才能够获取到的: fake-hwaddr-run /usr/share/sangfor/EasyConnect/EasyConnect --enable-transparent-visuals --disable-gpu

于是我在17行后面加了一行echo代码想看看能否成功执行,发现echo语句从来不运行(测试方法:先stop容器,复制修改过的start-sangfor.sh到容器中,然后在start容器) 我猜测应该是执行EasyConnect程序后,控制权交给系统,然后EasyConnect一直在运行不返回所导致EasyConnect后面的语句都不执行。

我的更新IP代码也很简单,就只有几行

!/bin/bash

token="xxx" ipaddr=busybox ifconfig | grep "inet addr:10" | sed 's#^.*addr:##g' | awk '{print $1}' echo $ipaddr result=curl "http://ipv4.dynv6.com/api/update?hostname=xxx.dns.army&ipv4=$ipaddr&token=$token" echo $result

老大指点一下,这段sh代码放在那里比较好,才能成功执行?(在Dockerfile末尾再加一行CMD命令?)

Ghost

From: Hagb (Junyu Guo 郭俊余) Date: 2022-03-01 23:13 To: Hagb/docker-easyconnect CC: ghost-909; Author Subject: Re: [Hagb/docker-easyconnect] Can't find available method to automatically set route for opening ports (Issue #97) 可以用 date 命令打印时间。 在 https://github.com/Hagb/docker-easyconnect/blob/d1debe2dfcbba5210b7ee5a401a8380f01d362a4/docker-root/usr/local/bin/start-sangfor.sh#L28https://github.com/Hagb/docker-easyconnect/blob/d1debe2dfcbba5210b7ee5a401a8380f01d362a4/docker-root/usr/local/bin/start-sangfor.sh#L20 不过如果想要精确地输出到你要的那个地方,还有点麻烦 — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.Message ID: @.***>

Hagb commented 2 years ago

但是我看了start-sangfor.sh这个文件,内部IP地址应该是在17行执行这行代码之后才能够获取到的: fake-hwaddr-run /usr/share/sangfor/EasyConnect/EasyConnect --enable-transparent-visuals --disable-gpu

@ghost-909 可以在 https://github.com/Hagb/docker-easyconnect/blob/d1debe2dfcbba5210b7ee5a401a8380f01d362a4/docker-root/usr/local/bin/start.sh#L18 下面加。 那个花括号括着的代码会在容器本次启动后第一次登陆上 vpn 服务器时运行

ghost-909 commented 2 years ago

嗯,只在第一次登陆成功之后运行吗?这个达不到我的目的啊 能不能再每次VPN登录成功后运行呢? 因为有时候很多原因,比如VPN服务器重启,我家的IP地址变了,都会导致容器重连然后导致获取到的VPN内网地址变更,如果只在第一次登录上VPN的时候执行,那可能隔几天IP又变了……

Hagb commented 2 years ago

嗯,只在第一次登陆成功之后运行吗?这个达不到我的目的啊 能不能再每次VPN登录成功后运行呢? 因为有时候很多原因,比如VPN服务器重启,我家的IP地址变了,都会导致容器重连然后导致获取到的VPN内网地址变更,如果只在第一次登录上VPN的时候执行,那可能隔几天IP又变了……

那我觉得可以写一个定时获取 ip,变了的话就运行。

token="xxx"
oldip=`busybox ifconfig | grep "inet addr:10" | sed 's#^.*addr:##g' | awk '{print $1}'`
while true; do
    ipaddr=`busybox ifconfig | grep "inet addr:10" | sed 's#^.*addr:##g' | awk '{print $1}'`
    if [ "$ipaddr" == "$oldip"]; then
            sleep 300 # 五分钟
            continue
    fi
    oldip=$ipaddr
    echo $ipaddr
    result=`curl "[http://ipv4.dynv6.com/api/update?hostname=xxx.dns.army&ipv4=$ipaddr&token=$token"`](http://ipv4.dynv6.com/api/update?hostname=xxx.dns.army&ipv4=%24ipaddr&token=%24token%22%60)
    echo $result
    sleep 300 # 五分钟
done

曾经我也有类似需求(用 ddns 来绑定域名)的时候,我直接就是 5 分钟请求绑定一次(最好看看服务商有没有限额?),甚至没管它有没有变。

ghost-909 commented 1 year ago

命令是这样的

docker run --device /dev/net/tun --cap-add NET_ADMIN -ti -p 1080:1080 -p 8888:8888 --link=gallant_benz --link=squid -e EC_VER=7.6.8 -e FORWARD=5555:172.17.0.2:1080 -e FORWARD=3128:172.17.0.4:3128 -e CLI_OPTS="-d 117.141.120.131 -u 10053612 -p xxx" hagb/docker-easyconnect:dev-cli

Ghost

发件人: Ghost 发送时间: 2022-05-11 09:32 收件人: Hagb/docker-easyconnect; Hagb/docker-easyconnect 抄送: Mention 主题: Re: Re: [Hagb/docker-easyconnect] Can't find available method to automatically set route for opening ports (Issue #97) 感谢老大还这么贴心提供了sh的脚本。不过我要的功能比较简单,我自己改了一下,然后用群晖的计划任务执行成功,目的实现了。

现在有另外一个问题,端口转发好像有一个生效,比如我运行下面的命令,只有第二个3128成功了

Ghost

From: Hagb (Junyu Guo 郭俊余) Date: 2022-03-26 14:48 To: Hagb/docker-easyconnect CC: ghost-909; Mention Subject: Re: [Hagb/docker-easyconnect] Can't find available method to automatically set route for opening ports (Issue #97) 嗯,只在第一次登陆成功之后运行吗?这个达不到我的目的啊 能不能再每次VPN登录成功后运行呢? 因为有时候很多原因,比如VPN服务器重启,我家的IP地址变了,都会导致容器重连然后导致获取到的VPN内网地址变更,如果只在第一次登录上VPN的时候执行,那可能隔几天IP又变了…… 那我觉得可以写一个定时获取 ip,变了的话就运行。 token="xxx" oldip=busybox ifconfig | grep "inet addr:10" | sed 's#^.*addr:##g' | awk '{print $1}' while true; do ipaddr=busybox ifconfig | grep "inet addr:10" | sed 's#^.*addr:##g' | awk '{print $1}' if [ "$ipaddr" == "$oldip"]; then sleep 300 # 五分钟 continue fi oldip=$ipaddr echo $ipaddr result=curl "[http://ipv4.dynv6.com/api/update?hostname=xxx.dns.army&ipv4=$ipaddr&token=$token"](http://ipv4.dynv6.com/api/update?hostname=xxx.dns.army&ipv4=%24ipaddr&token=%24token%22%60) echo $result sleep 300 # 五分钟 done 曾经我也有类似需求(用 ddns 来绑定域名)的时候,我直接就是 5 分钟请求绑定一次(最好看看服务商有没有限额?),甚至没管它有没有变。 ― Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

ghost-909 commented 1 year ago

感谢老大还这么贴心提供了sh的脚本。不过我要的功能比较简单,我自己改了一下,然后用群晖的计划任务执行成功,目的实现了。

现在有另外一个问题,端口转发好像有一个生效,比如我运行下面的命令,只有第二个3128成功了

Ghost

From: Hagb (Junyu Guo 郭俊余) Date: 2022-03-26 14:48 To: Hagb/docker-easyconnect CC: ghost-909; Mention Subject: Re: [Hagb/docker-easyconnect] Can't find available method to automatically set route for opening ports (Issue #97) 嗯,只在第一次登陆成功之后运行吗?这个达不到我的目的啊 能不能再每次VPN登录成功后运行呢? 因为有时候很多原因,比如VPN服务器重启,我家的IP地址变了,都会导致容器重连然后导致获取到的VPN内网地址变更,如果只在第一次登录上VPN的时候执行,那可能隔几天IP又变了…… 那我觉得可以写一个定时获取 ip,变了的话就运行。 token="xxx" oldip=busybox ifconfig | grep "inet addr:10" | sed 's#^.*addr:##g' | awk '{print $1}' while true; do ipaddr=busybox ifconfig | grep "inet addr:10" | sed 's#^.*addr:##g' | awk '{print $1}' if [ "$ipaddr" == "$oldip"]; then sleep 300 # 五分钟 continue fi oldip=$ipaddr echo $ipaddr result=curl "[http://ipv4.dynv6.com/api/update?hostname=xxx.dns.army&ipv4=$ipaddr&token=$token"](http://ipv4.dynv6.com/api/update?hostname=xxx.dns.army&ipv4=%24ipaddr&token=%24token%22%60) echo $result sleep 300 # 五分钟 done 曾经我也有类似需求(用 ddns 来绑定域名)的时候,我直接就是 5 分钟请求绑定一次(最好看看服务商有没有限额?),甚至没管它有没有变。 ― Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>