|
本帖最后由 infi450 于 2021-7-5 22:40 编辑
参考了
https://www.right.com.cn/forum/f ... ypeid%26typeid%3D15
和
https://www.right.com.cn/forum/thread-4112536-1-1.html
仅适用于IPV6,端口根据需要设置,脚本如下:(设置完不是即时生效的,要等一段时间)
1、首先梅林打开SSH。——以便winscp连接、修改上传脚本;
2、winscp连接到路由,定位到 /jffs/scripts/ ,然后直接右键“新建” 文件——
文件名:ddns-start
脚本代码:(注意红色部分替换成你的dynv6帐号相关信息),
#!/bin/sh -e
hostname=i****.dns.army
device=ppp0
token=dg88888888888888888888X
netmask=64
file=/jffs/scripts/.dynv6.addr6
[ -e $file ] && old=`cat $file`
if [ -z "$hostname" -o -z "$token" ]; then
echo "Usage: token=<your-authentication-token> [netmask=64] $0 your-name.dynv6.net [device]"
exit 1
fi
if [ -z "$netmask" ]; then
netmask=128
fi
if [ -n "$device" ]; then
device="dev $device"
fi
address=$(ip -6 addr list scope global $device | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1)
if [ -e /usr/sbin/curl ]; then
bin="curl -fsS"
elif [ -e /usr/sbin/wget ]; then
bin="wget -O-"
else
echo "neither curl nor wget found"
exit 1
fi
if [ -z "$address" ]; then
echo "no IPv6 address found"
exit 1
fi
# address with netmask
current=$address/$netmask
#if [ "$old" = "$current" ]; then
# echo "IPv6 address unchanged"
# exit
#fi
# send addresses to dynv6
$bin "http://dynv6.com/api/update?hostname=$hostname&ipv6=$current&token=$token"
# save current address
echo $current > $file
/sbin/ddns_custom_updated 1
ip6tables -I INPUT -i ppp0 -p tcp -m tcp --dport 8001 -j ACCEPT
nohup /usr/sbin/socat TCP6-LISTEN:8001,reuseaddr,fork TCP4:192.168.*.1:80 >/dev/null 2>&1 &
#上面两行一组,端口号和内部IP地址自己设置,开几个端口设置几组
ip6tables -I INPUT -i ppp0 -p tcp -m tcp --dport 8007 -j ACCEPT
nohup /usr/sbin/socat TCP6-LISTEN:8007,reuseaddr,fork TCP4:192.168.*.*:80 >/dev/null 2>&1 &
#上面两行一组,端口号和内部IP地址自己设置,开几个端口设置几组
ip6tables -I INPUT -i ppp0 -p tcp -m tcp --dport 8008 -j ACCEPT
nohup /usr/sbin/socat TCP6-LISTEN:8008,reuseaddr,fork TCP4:192.168.*.*:8000 >/dev/null 2>&1 &
#上面两行一组,端口号和内部IP地址自己设置,开几个端口设置几组
|
|