Linux架设DDNS服务器之自动更新脚本
2014-11-16 18:21
323 查看
问题描述:客户端是动态IP,每次连网之后要nsupdate下才可以把客户端的hostname 与IP映射更新到DNS Server上
命令如下:
这样的效率实在是有点低,于是我就自己写个脚本来更新了。直接贴上我的脚本。脚本下载地址: http://pan.baidu.com/s/1lhlAu
测试如下:
这样的效率确实就提高了不少。
本文来自:爱好Linux技术网
本文链接:http://www.ahlinux.com/shell/7971.html
命令如下:
nsupdate -k K*****.key >server 192.*.*.* #dns server ip address >update delete yourfqdn A delete >update add yourFQDN 600 A your new IP
这样的效率实在是有点低,于是我就自己写个脚本来更新了。直接贴上我的脚本。脚本下载地址: http://pan.baidu.com/s/1lhlAu
#!/bin/bash ######################################### ## ## Author:Medici.Yan@gmail.com ######################################### PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH usage(){ echo " Usage:$0 [-i interface] [-d basedir] [-h hostname] [-t ttl] [-s servername] [-k keyfile] [-c ClientIP] [-m testdomain]" echo " Default:" echo " -i eth0 -d /usr/local/ddns -t 600 -k /usr/local/ddns/*.key" echo "" echo " Notice: 如果你自己的主机是DNS Server,那么你不能改变你自己的 hostname 与 IP" echo " 如果你不知道你的DNS Server是什么,就加上-m 参数,后面是测试的域名,eg:$0 -m swu.edu.cn " echo " Notice: If your PC is your DNS Server, you can't change your hostname and IP" echo " If you don't know your DNS Server Address, you can use the param [-m TestDomain] to get the right server address,eg:$0 -m swu.edu.cn " exit 1 } ((params=$#%2)) if [[ $# -gt 14 ]]; then usage #elif [ $params -eq 1 ]; then # usage fi #设置默认参数值 domain="swu.edu.cn" #默认测试DNS Server 地址的域名 basedir="/usr/local/ddns" # 基本工作目录 keyfile="$basedir"/"`ls $basedir|grep '.key$'`" #公钥文件 ttl=600 # ttl interface="eth0" # 对外的联机接口! hostname=`hostname` servername=`grep 'nameserver' /etc/resolv.conf | head -n 1 |awk '{print $2}'` #dns Server IP newip=`ifconfig "$interface" | grep 'inet addr' | awk '{print $2}' | sed -e "s/addr\://"` #IP地址 #处理NetworkManager管理DNS Server,基本上用不到,一般在启动NetworkManager后会自动修改resolv.conf if [ "$servername" == "" ]; then servername=`nslookup $domain|grep Server|awk '{print $2}'` fi #获取用户输入参数,如不指定则使用默认参数 while [ $# -gt 0 ] do case $1 in -i)shift;interface=$1;shift;; -d)shift;basedir=$1;shift;; -h)shift;hostname=$1;shift;; -t)shift;ttl=$1;shift;; -s)shift;servername=$1;shift;; -k)shift;keyfile=$1;shift;; -c)shift;newip=$1;shift;; -m)shift;domain=$1;shift;; *)usage;; esac done #自动查找DNS和手动都找不到DNS则退出 if [ "$servername" == "" ]; then echo "Error:Can not find the DNS Server!" exit 1 fi #检查IP合法性 checkip=`echo $newip | grep "^[0-9]"` if [ "$checkip" == "" ]; then echo "$0: The interface can't connect internet...." exit 1 fi #检测basedir目录是否存在,不存在则创建 if !([ -d $basedir ]);then mkdir -p $basedir fi #检测keyfile存在性 if !([ -f $keyfile ]);then echo "Error:$keyfile does not exist!" exit 1 fi tmpfile=$basedir/tmp.txt #如果文件不存在,则创建 if !([ -f $tmpfile ]);then touch $tmpfile #查看是否创建成功 if !([ -f $tmpfile ]);then echo "Permission Denyed,Can not touch $tmpfile in $basedir" exit 1 fi fi #写入配置文件 echo "server $servername" > $tmpfile echo "update delete $hostname A " >> $tmpfile echo "update add $hostname $ttl A $newip" >> $tmpfile echo "send" >> $tmpfile #更新 nsupdate -k $keyfile -v $tmpfile
测试如下:
这样的效率确实就提高了不少。
本文来自:爱好Linux技术网
本文链接:http://www.ahlinux.com/shell/7971.html
相关文章推荐
- 多linux服务器之间实现文件自动复制(脚本)
- linux下svn使用(三) - svn高级应用 - 自动更新web服务器
- linux系统shell脚本实现 恶意扫描服务器密码 自动屏蔽
- Linux与云计算——第二阶段Linux服务器架设 第七章:网站WEB服务器架设—使用各种WEB脚本环境
- Linux CentOS SVN 设置钩子hooks/post-commit来同步更新服务器web目录,实现代码自动部署
- Linux(CentOS)+SVN服务器,并实现本地提交后,服务器端自动更新
- bat脚本自动上传文件到Linux FTP服务器上
- 自己写的一个项目自动更新的Linux脚本
- centos shell编程4【分发系统】 服务器标准化 mkpasswd 生成密码的工具 expect讲解 expect传递参数 expect自动同步文件 expect指定host和要同步的文件 expect文件分发系统 expect自动发送密钥脚本 Linux脚本执行方式 第三十八节课
- 使用Linux定时脚本更新服务器的git代码
- Linux VPS/服务器 网站及数据库自动本地备份并FTP上传备份脚本
- linux下自动备份脚本并上传到ftp服务器
- 〖Linux〗自动更新Hosts的一个脚本
- linux下shell脚本自动上传或下载脚本及远程服务器相关vsftpd iptables配置
- 通过crond自动运行Python脚本实现多台linux服务器的监控
- Linux VPS/服务器 网站及数据库自动本地备份并FTP上传备份脚本
- Linux crontab的使用方式,sh脚本的编写,sh脚本自动启动tomcat服务器,sh监控系统运行情况
- 批处理程序:自动上传FTP,再登陆linux服务器执行更新
- Linux_Shell 服务器互通脚本, 第一次通信 自动记入 know_hosts
- Linux下搭建SVN服务器及自动更新项目文件到web发布目录(www)