Nov 09

最近发现教育网拨号后是独立ip,而且80还没有被封,就萌生了在Raspberry Pi搭建博客的念头,搭建WordPress的教程很多,以前也搭建成功过,所以没有问题,但是DDNS解析的问题一直没有解决。

先是在OpenWrt下设置端口映射成功后,发现在的TP Link这样垃圾的路由器下也能设置,当然不是使用花生壳,但是不能自动更新DDNS。

先后参考了一下项目,这些别人运行起来都没有问题,但是我这里就是不能运行,出现的错误也各不相同,最主要的问题是连接超时。

1.dnspod-ddns
https://github.com/ohsc/dnspod-ddns
2.lixin-dnspod-ddns
https://github.com/topdogs/lixin-dnspod-ddns
3.Python dynamic DNSPod DNS Script
https://gist.github.com/chuangbo/833369
4.dnspod-client
https://github.com/lapause/dnspod-client
5.dnspod_inter_ddns
https://github.com/jenson-shi/dnspod_inter_ddns

现将自己的方法如下:

1.编辑ddns.sh文件

vim ddns.sh
#!/bin/sh
curl -X POST https://dnsapi.cn/Record.Ddns -d 'login_email=xxxx#qq.com&login_password=xxx&format=json&domain_id=2895571&record_id=85355459&sub_domain=blog&record_line=%E9%BB%98%E8%AE%A4'

增加执行权限

chmod +x /home/pi/ddns.sh

2.编辑autoddns.sh文件

vim autoddns.sh
#!/bin/bsh
bash /home/pi/ddns.sh >/dev/null 2>&1

增加执行权限

chmod +x /home/pi/autoddns.sh

3.修改crontab默认编辑器为vim

sudo update-alternatives --config editor

输入/usr/vim/vim.basic的编号,回车。vim.tiny与vim.basic的区别是vim.basic为完全的vim,而vim.tiny为简化版,功能上有所区别,如不支持高亮等。

4.添加crontab任务

sudo crontab -u root -e
*/3 * * * * bash /home/pi/autoddns.sh

5.重启cron服务
添加crontab任务

sudo /etc/init.d/cron restart

发现Raspberry Pi下需要以root才能执行cron任务,因此绕了很大的弯。另外cron的需要用绝对地址。

参考资料:
1.http://www.cnblogs.com/colipso/p/3536361.html
2.http://blog.csdn.net/w6611415/article/category/2302447
3.http://www.bttme.com/117.html
4.http://blog.csdn.net/ithomer/article/details/6817019
5.http://shixf.com/dnspod-inter-ddns-cn/

Leave a Reply