在OpenWrt中,GOST實(shí)現(xiàn)IPv6代理(服務(wù)端)
最近折騰了在OpenWrt上運(yùn)行g(shù)ost來代理外來的IPv6流量,特此記錄下來,以便給后來以參考。
0 下載GOST
GOST是一款有著極多協(xié)議支持的,使用GO語音編寫的安全隧道軟件,官網(wǎng)是https://gost.run/,這里可以下載到各種各樣的版本。
我的服務(wù)端是ARM架構(gòu)的,這里,我選擇ArmV8版本。
使用ssh登錄OpenWrt,默認(rèn)為/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的可執(zhí)行文件,使用【chmod +x 文件名】來賦予可執(zhí)行權(quán)限。
1 配置GOST
在同級目錄下創(chuàng)建【gost.yml】文件,內(nèi)容為:(具體含義請參考GOST官網(wǎng)wiki,有詳細(xì)的講解)
services:
- name: service
? addr: ":監(jiān)聽端口號"
? handler:
? ? type: socks5 #代理協(xié)議
?? ?auth:
? ? ? username: 用戶名
? ? ? password: 密碼? ??
? listener:
? ? type: tcp #通訊協(xié)議
log:
? output: /var/log/gost.log # 日志保存位置
? level: info
? format: text
2 開機(jī)自啟
一種方法為:直接在 /etc/rc.local 里面(exit 0前面)加入你的啟動語句, 但是我怎么試都不能啟動,有知道怎么回事的朋友可以告訴我一下。
【sleep 10 && (nohup root/gostexe?> /dev/null )&】
第二種方法:在/etc/init.d/中添加服務(wù)文件,命名為:【gostv3】(記得更改權(quán)限:【chmod +x /etc/init.d/gostv3】)
關(guān)于啟動腳本可以看官網(wǎng)的介紹:
https://openwrt.org/docs/techref/initscripts
內(nèi)容為:
#!/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,關(guān)于UCI的簡單介紹可以看這篇文章:
https://blog.csdn.net/hzlarm/article/details/102993291
在/etc/config下添加配置文件,命名為【gostv3】,內(nèi)容為:
config gost_arguments 'arguments'
? ? ? ? option enable 'true'
? ? ? ? option path '/root/gostv3'
config gost_options 'options'
? ? ? ? option configure_file '/root/gost.yml'
之后使用【service gostv3 enable】來打開 [開機(jī)自啟]。
至此,所有服務(wù)端的工作已經(jīng)完成。有什么疏漏,歡迎大家指出。