在OpenWrt中,GOST实现IPv6代理(服务端)
最近折腾了在OpenWrt上运行gost来代理外来的IPv6流量,特此记录下来,以便给后来以参考。
0 下载GOST
GOST是一款有着极多协议支持的,使用GO语音编写的安全隧道软件,官网是https://gost.run/,这里可以下载到各种各样的版本。
我的服务端是ARM架构的,这里,我选择ArmV8版本。
使用ssh登录OpenWrt,默认为/root路径,我选择不更改,使用命令:
【wget -c 下载地址】 来下载GOST
这里我使用 【wget -c https://github.com/go-gost/gost/releases/download/v3.0.0-beta.2/gost-linux-armv8-3.0.0-beta.2.gz】
之后解压 【gzip -d 文件名】 ,得到GOST的可执行文件,使用【chmod +x 文件名】来赋予可执行权限。
1 配置GOST
在同级目录下创建【gost.yml】文件,内容为:(具体含义请参考GOST官网wiki,有详细的讲解)
services:
- name: service
addr: ":监听端口号"
handler:
type: socks5 #代理协议
auth:
username: 用户名
password: 密码
listener:
type: tcp #通讯协议
log:
output: /var/log/gost.log # 日志保存位置
level: info
format: text
2 开机自启
一种方法为:直接在 /etc/rc.local 里面(exit 0前面)加入你的启动语句, 但是我怎么试都不能启动,有知道怎么回事的朋友可以告诉我一下。
【sleep 10 && (nohup root/gostexe > /dev/null )&】
第二种方法:在/etc/init.d/中添加服务文件,命名为:【gostv3】(记得更改权限:【chmod +x /etc/init.d/gostv3】)
关于启动脚本可以看官网的介绍:
https://openwrt.org/docs/techref/initscripts
内容为:
#!/bin/sh /etc/rc.common
# Created By 章鱼萝卜猫
START=90
STOP=10
enable="$(uci -q get gostv3.arguments.enable)"
prog_path="$(uci -q get gostv3.arguments.path)"
configure_file="$(uci -q get gostv3.options.configure_file)"
prog=`basename $prog_path`
start()
{
[ "x${enable}" != "xtrue" ] && exit 0
pid=`ps | grep -v grep | grep -v etc | grep -i "$prog" | awk '{print $1}'`
if [ "x$pid" == "x" ]; then
$prog_path -C $configure_file 2>&1 > /var/log/$prog.log &
echo -e "\n$prog started!\n"
else
## program is running, exit with error.
echo -e "\nError! $prog is currently running!\n" 1>&2
exit 1
fi
}
stop() {
pid=`ps | grep -v grep | grep -v etc | grep -i "$prog" | awk '{print $1}'`
if [ "x$pid" == "x" ]; then
## Program is not running, exit with error.
echo -e "\nError! $prog not started!\n" 1>&2
exit 1
else
## Program is running, so stop it
kill -15 $pid
echo -e "\n$prog stopped!\n"
fi
}
restart() {
stop
start
}
这里使用了OpenWrt的UCI,关于UCI的简单介绍可以看这篇文章:
https://blog.csdn.net/hzlarm/article/details/102993291
在/etc/config下添加配置文件,命名为【gostv3】,内容为:
config gost_arguments 'arguments'
option enable 'true'
option path '/root/gostv3'
config gost_options 'options'
option configure_file '/root/gost.yml'
之后使用【service gostv3 enable】来打开 [开机自启]。
至此,所有服务端的工作已经完成。有什么疏漏,欢迎大家指出。