DDNS client on a Linux machine

Using this tool -> inadyn 

apt-get install inadyn -y

Usage:

https://github.com/troglobit/inadyn#example-configuration

Suggested free DDNS providers: freedns.afraid.org, noip.com and etc..

auto-startup script as a service

knowledge from: http://www.linuxquestions.org/questions/linux-software-2/how-do-i-execute-inadyn-automatically-during-boot-541367/

And 

Init script for Inadyn

First of all you have to create (or edit) inadyn configuration file:

$~ mkdir /var/cache/inadyn

Edit this file:

/etc/inadyn.conf


this way

Code:
# Basic configuration file for inadyn
#
# /etc/inadyn.conf
#update_period_sec 600 # Check for a new IP every 600 seconds
background
verbose        1
period         300
cache-dir      /var/cache/inadyn
startup-delay  60
logfile /var/log/ddns.log
pidfile /var/run/ddns.pid


  

system default@freedns.afraid.org
ssl
username abcdefsafdsa
password fdadfferfsadf
alias oneofyour.donated.com
alias another.tooms.to
 

Now put this code in /etc/init.d/inadyn

Code:
#!/bin/bash
case "$1" in
    start)
    if [ -f /tmp/inadyn.pid ]; then
        PID=$(cat /tmp/inadyn.pid)
        kill -0 ${PID} &>/dev/null
        if [ $? = 0 ]; then
            echo "Inadyn is already running."
        else
            /usr/sbin/inadyn
            pidof inadyn > /tmp/inadyn.pid
            PID=$(cat /tmp/inadyn.pid)
            kill -0 ${PID} &>/dev/null
            if [ $? = 0 ]; then
                echo "Inadyn started succesfully."
            else
                echo "Error starting Inadyn"
            fi
        fi
    else
        /usr/sbin/inadyn
        pidof inadyn > /tmp/inadyn.pid
        PID=$(cat /tmp/inadyn.pid)
        kill -0 ${PID} &>/dev/null
        if [ $? = 0 ]; then
            echo "Inadyn started succesfully."
        else
            echo "Error starting Inadyn"
        fi
        fi
        ;;
    stop)
    if [ -f /tmp/inadyn.pid ];then
        PID=$(cat /tmp/inadyn.pid)
        kill -0 ${PID} &>/dev/null
        if [ $? = 0 ]; then
            /bin/kill ${PID}
            kill -0 ${PID} &>/dev/null
            if [ $? = 1 ]; then
                echo "Inadyn stopped succesfully."
            else
                echo "Error stopping Inadyn"
            fi
        else
            echo "Inadyn is already stopped."
        fi
    else
        echo "Inadyn is already stopped."
    fi
        ;;
    reload|restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 start|stop|restart|reload"
        exit 1
esac
exit 0
Then create these two links to start and stop service at system boot and shutdown:
ln -s /etc/init.d/inadyn /etc/rc2.d/S03inadyn
ln -s /etc/init.d/inadyn /etc/rc0.d/K03inadyn
 

Then you can use:

service inadyn start

原文地址:https://www.cnblogs.com/spaceship9/p/4818139.html