dd-wrt自动更新ddns

路由器重启,不能及时更新ip到dns,如何解决,下面方法可以解决。前提是已经注册了ddns网站,获得ddns域名,在dd-wrt路由上正确配置了ddns。ddns通过手动更新可以获得正常域名ip匹配,现在需要自动更新,即设备重启后更新。

准备脚本

提供ddns解析的网站一般提供更新脚本,譬如
http://freedns.afraid.org/dynamic/index.php
提供有wget,curl,cron等脚本示例,根据自己路由器支持程度,选择合适的脚本

sleep 36
wget -q  -t=400  http://freedns.afraid.org/dynamic/update.php?dksiejlsfkdielakielskjfielakdfie

每个注册用户的脚本是不同,请复制粘贴自己的脚本。
sleep 是必须的,否则不能正常启动脚本。

下面是花生壳的

wanip=$(nvram get wan_ipaddr)
wget -q -O /var/log/hsk.log http://用户名:密码@ddns.oray.com/ph/update?hostname=花生壳域名&myip=$wanip >/dev/null 2>&1

添加到路由器启动脚本

https://www.dd-wrt.com/wiki/index.php/Startup_Scripts
两个方法

通过web接口

Using the Web Interface, goto the Administration tab.
If available, go to the Command subtab, otherwise go to the diagnostics subtab.
Type the commands you wish to run every startup into the Commands: dialog box (place each command on a newline using the enter key, and if the command isn’t something that stops running after a moment, put a ‘&’ after the command)
Click the Save Startup button at the bottom of the page if you’d like the commands to save into the rc_startup variable (you may need to scroll). Save Firewall will save the commands into the rc_firewall variable.

通过nvram命令

Login to your router using Telnet/SSH
To set the startup scripts, use the following:

 nvram set rc_startup="
 <command 1>
 <command 2>
 ...
 <command n>
 "

When you give the command nvram commit the rc_startup variable is saved in flash memory and will remain when you reboot.

 nvram commit
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值