Linux setup DDNS server automatic Update script

Source: Internet
Author: User

Problem Description: The client is a dynamic IP, after each network to Nsupdate to the client's hostname and IP map to update to the DNS server

The command is as follows:

Nsupdate-k k*****.key>server 192.*.*.*        #dns server IP address>update Delete yourfqdn A delete>update add you Rfqdn A your new IP

This kind of efficiency is a little low, so I wrote a script to update. Paste my script directly. Script: Http://pan.baidu.com/s/1lhlAu

#!/bin/bash############################################# author:[email protected]######################### ############### #PATH =/sbin:/bin:/usr/sbin:/usr/binexport pathusage () {echo "usage:$0 [-I interface] [-D basedir] [-H ho Stname] [-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: If your own host is DNS Server, then you cannot change your own hostname with IP "Ech O "If you do not know what your DNS server is, add-m parameter, followed by the test domain name, eg:$0-m swu.edu.cn" echo "Notice:if your PC is your DNS server, you CA  N ' 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# usagefi# Set default parameter value domain= "swu.edu.cn" #默认测试DNS the domain name of the Server address basedir= "/usr/local/ddns" # Basic working directory Keyfile= "$ Basedir "/" ' LS $basEdir|grep '. key$ ' "#公钥文件ttl =600 # ttlinterface=" eth0 "# External online interface! Hostname= ' hostname ' servername= ' grep ' nameserver '/etc/resolv.conf | Head-n 1 |awk ' {print $} ' #dns Server ipnewip= ' ifconfig $interface ' | grep ' inet addr ' | awk ' {print $} ' | Sed-e "s/addr\://" ' #IP地址 # handles NetworkManager management of DNS Server, which is basically not used, generally after the boot NetworkManager will automatically modify RESOLV.CONFIF ["$servername " == "" ];    Then Servername= ' nslookup $domain |grep Server|awk ' {print $} ' fi# get user input parameters, use default parameters if not specified while [$#-gt 0]do case $ 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;; esacdone# automatically find DNS and manually cannot find DNS then exit if ["$servername" = = ""];  Then echo "Error:can not find the DNS server!" Exit 1fi# Check IP legitimacy checkip= ' echo $newip | grep "^[0-9" "If [" $checkip "= =" "]; Then echo "$0:the interface can ' t connect Internet ...."Exit 1fi# detects if the Basedir directory exists, does not exist then creates if!" ([-D $basedir]); then mkdir-p $basedirfi # Detect keyfile Presence if!  ([-F $keyfile]); then echo "Error: $keyfile does not exist!" Exit 1fitmpfile= $basedir/tmp.txt# If the file does not exist, create if! ([-F $tmpfile]); then touch $tmpfile #查看是否创建成功 if! ([-F $tmpfile]); then echo "Permission Denyed,can not touch $tmpfile in $basedir" Exit 1 fifi# write config file echo "server $ ServerName "> $tmpfileecho" update delete $hostname a ">> $tmpfileecho" update add $hostname $ttl A $newip "> > $tmpfileecho "Send" >> $tmpfile # Update nsupdate-k $keyfile-V $tmpfile

The test is as follows:

This efficiency has indeed improved a lot.

    • This article from: Hobby Linux Technology Network
    • This article link: http://www.ahlinux.com/shell/7971.html

Linux setup DDNS server automatic Update script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.