WANIPSITE="http://icanhazip.com"
WANIPSITE="ipinfo.io/ip"
CFID=
./scriptname.sh -f true
Missing DNS record IDfetching from Cloudflare...
=> Found CFID=56778800 , advising to save this to [COLOR=#000000]/usr/local/bin/cf-ddns.sh or set it using the -i flag
Updating DNS to 188.186.36.77
Updated succesfuly!
Updating DNS to 188.186.36.77[COLOR=#000000]Updated succesfuly!
WAN IP Unchanged, to update anyway use flag -f trueWAN IP Unchanged, to update anyway use flag -f true[COLOR=#000000]
[COLOR=#000000]*/1 * * * * /usr/local/bin/cf-ddns.sh -f true [COLOR=#000000]>> /var/log/dyndns.log[COLOR=#000000]
Es sagt immer "Permission Denied"du kanns in das verzeichnis vom Script wechseln und
eingeben das -f true ist dafür, das auch die IP geupdatet wird, falls die immer noch die gleiche IP wie vorher ist.Code:./scriptname.sh -f true
Das Script wird schon sagen wenn was Falsch ist
Edit habe es mal getestet, mit:
*/1 * * * * /usr/local/bin/cf-ddns.sh >> /var/log/dyndns.log
wird etwas ins log geschrieben.
PS: bei mir kommt:
Code:Missing DNS record IDfetching from Cloudflare... => Found CFID=56778800 , advising to save this to /home/axiomgarden/cloudflare_ddns.sh or set it using the -i flag Updating DNS to 188.186.36.77 Updated succesfuly!
Habe oben natürlich CFID und IP geändert
Die CFID die dort angezeigt wird kannste dann auch im Script einfügen
Wenn die CFID im Script eingeben wurde kommt das:
Code:Updating DNS to 188.186.36.77[COLOR=#000000]Updated succesfuly![COLOR=#000000]
root@piserver:/# /usr/local/bin/cf-ddns.sh
WAN IP Unchanged, to update anyway use flag -f true
root@piserver:/# /usr/local/bin/cf-ddns.sh -f true
Missing DNS record ID
fetching from Cloudflare...
=> Found CFID=1187842744 , advising to save this to /usr/local/bin/cf-ddns.sh or set it using the -i flag
Updating DNS to 91.1.40.12
Updated succesfuly!
[COLOR=#000000]cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/[COLOR=#E94849]deinedomain.net[COLOR=#000000].conf
[COLOR=#000000]nano /etc/apache2/sites-available/[COLOR=#E94849]deinedomain.net[COLOR=#000000].conf
<VirtualHost *:80> ServerName [COLOR=#E94849]deinedomain.net ServerAlias [COLOR=#E94849]www.deinedomain.net DocumentRoot /var/www/example.com/public_html [COLOR=#E94849]<hier den Pfad zur Website auf deiner Pi ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
[COLOR=#000000]a2ensite [COLOR=#E94849]deinedomain.net[COLOR=#000000].conf
/etc/init.d/apache2 restart
<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
[COLOR=#000000]<VirtualHost *:80>
ServerName [COLOR=#E94849]deinedomain.net ServerAlias [COLOR=#E94849]www.deinedomain.net DocumentRoot /var/www/example.com/public_html [COLOR=#E94849]<hier den Pfad zur Website auf deiner Pi ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
[COLOR=#000000]</VirtualHost>
root@piserver:/# sudo a2ensite Your choices are: default default-ssl follow-the-white-rabbit.net.conf
Which site(s) do you want to enable (wildcards ok)?
follow-the-white-rabbit.net.conf
Enabling site follow-the-white-rabbit.net.conf.
To activate the new configuration, you need to run:
service apache2 reload
root@piserver:/# service apache2 reload
[....] Reloading web server config: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
. ok
Oh ich sehe, scheint wie auch immer, jetzt zu funktionieren
Glückwunsch, wie das auch gelöst wurde
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
# Automatically update your CloudFlare DNS record to the IP, Dynamic DNS
# Can retrieve cloudflare Domain id and list zone's, because, lazy
# Place at:
# /usr/local/bin/cf-ddns.sh
# run `crontab -e` and add next line:
# 0 * * * * /usr/local/bin/cf-ddns.sh >/dev/null 2>&1
# run /usr/local/bin/cf-ddns.sh in terminal to check all settings are valid
# Usage:
# cf-ddns.sh -k cloudflare-api-key \
# -u user@example.com \
# -h host.example.com \ # fqdn of the record you want to update
# -z example.com \ # will show you all zones if forgot, but you need this
# Optional flags:
# -i cloudflare-record-id \ # script will show this
# -a true|false \ # auto get zone list and record id
# -f false|true \ # force dns update, disregard local stored ip
# default config
# API key, see https://www.cloudflare.com/a/account/my-account,
# incorrect api-key results in E_UNAUTH error
CFKEY=
# Zone name, will list all possible if missing, eg: example.com
CFZONE=
# Domain id, will retrieve itself by default
CFID=
# Username, eg: user@example.com
CFUSER=
# Hostname to update, eg: homeserver.example.com
CFHOST=
# Cloudflare TTL for record, between 120 and 86400 seconds
CFTTL=120
# Get domain ID from Cloudflare using awk/sed and python json.tool
GETID=true
# Ignore local file, update ip anyway
FORCE=true
# Site to retrieve WAN ip, other examples are: bot.whatismyipaddress.com, https://api.ipify.org/ ...
WANIPSITE="ipinfo.io/ip"
# get parameter
while getopts a:k:i:u:h:z:f: opts; do
case ${opts} in
a) GETID=${OPTARG} ;;
k) CFKEY=${OPTARG} ;;
i) CFID=${OPTARG} ;;
u) CFUSER=${OPTARG} ;;
h) CFHOST=${OPTARG} ;;
z) CFZONE=${OPTARG} ;;
f) FORCE=${OPTARG} ;;
esac
done
# If required settings are missing just exit
if [ "$CFKEY" = "" ]; then
echo "Missing api-key, get at: https://www.cloudflare.com/a/account/my-account"
echo "and save in ${0} or using the -k flag"
exit 2
fi
if [ "$CFUSER" = "" ]; then
echo "Missing username, probably your email-address"
echo "and save in ${0} or using the -u flag"
exit 2
fi
if [ "$CFHOST" = "" ]; then
echo "Missing hostname, what host do you want to update?"
echo "save in ${0} or using the -h flag"
exit 2
fi
# If the hostname is not a FQDN
if [ "$CFHOST" != "$CFZONE" ] && ! [ -z "${CFHOST##*$CFZONE}" ]; then
CFHOST="$CFHOST.$CFZONE"
echo " => Hostname is not a FQDN, assuming $CFHOST"
fi
# If CFZONE is missing, retrieve them all from CF
if [ "$CFZONE" = "" ]; then
echo "Missing zone"
if ! [ "$GETID" == true ]; then exit 2; fi
echo "listing all zones: (if api-key is valid)"
curl -s https://www.cloudflare.com/api_json.html \
-d a=zone_load_multi \
-d tkn=$CFKEY \
-d email=$CFUSER \
| grep -Eo '"zone_name":"([^"]+)"' \
| cut -d':' -f2 \
| awk '{gsub("\"","");print "* "$1}'
echo "Please specify the matching zone in ${0} or specify using the -z flag"
exit 2
fi
# Get current and old WAN ip
WAN_IP=`curl -s ${WANIPSITE}`
if [ -f $HOME/.wan_ip-cf2.txt ]; then
OLD_WAN_IP=`cat $HOME/.wan_ip-cf2.txt`
else
echo "No file, need IP"
OLD_WAN_IP=""
fi
# If WAN IP is unchanged an not -f flag, exit here
if [ "$WAN_IP" = "$OLD_WAN_IP" ] && [ "$FORCE" = false ]; then
echo "WAN IP Unchanged, to update anyway use flag -f true"
exit 0
fi
# If CFID is missing retrieve and use it
if [ "$CFID" = "" ]; then
echo "Missing DNS record ID"
if ! [ "$GETID" == true ]; then exit 2; fi
echo "fetching from Cloudflare..."
if ! CFID=$(
curl -s https://www.cloudflare.com/api_json.html \
-d a=rec_load_all \
-d tkn=$CFKEY \
-d email=$CFUSER \
-d z=$CFZONE \
| grep -Eo '"(rec_id|name|type)":"([^"]+)"' \
| cut -d':' -f2 \
| awk 'NR%3{gsub("\"","");printf $0" ";next;}1' \
| grep -E "${CFHOST//./\\.}" \
| grep -e '"A"' \
| grep -Eo "(^|\s)([0-9]+)(\s|$)"
); then
echo " => Incorrect zone, or zone doesn't contain the A-record ${CFHOST}!"
echo "listing all records for zone ${CFZONE}:"
(printf "ID RECORD TYPE\n";
curl -s https://www.cloudflare.com/api_json.html \
-d a=rec_load_all \
-d tkn=$CFKEY \
-d email=$CFUSER \
-d z=$CFZONE \
| grep -Eo '"(rec_id|name|type)":"([^"]+)"' \
| cut -d':' -f2 \
| awk 'NR%3{gsub("\"","");printf $0" ";next;}1'
)| column -t
exit 2
fi
echo " => Found CFID=${CFID}, advising to save this to ${0} or set it using the -i flag"
fi
# If WAN is changed, update cloudflare
echo "Updating DNS to $WAN_IP"
RESPONSE=$(
curl -s https://www.cloudflare.com/api_json.html \
-d a=rec_edit \
-d tkn=$CFKEY \
-d email=$CFUSER \
-d z=$CFZONE \
-d id=$CFID \
-d ttl=$CFTTL \
-d type=A \
-d name=$CFHOST \
-d "content=$WAN_IP"
)
if [ "$RESPONSE" != "${RESPONSE%success*}" ]; then
echo "Updated succesfuly!"
echo $WAN_IP > $HOME/.wan_ip-cf.txt
exit
else
echo 'Something went wrong :('
echo "Response: $RESPONSE"
exit 1
fi
chmod +x pfad/zum/script/cf_ddns2.sh
root@piserver:~# /usr/local/bin/cf-ddns-WO_www.sh
=> Hostname is not a FQDN, assuming follow-the-white-rabbiut.net.follow-the-white-rabbit.net
Missing DNS record ID
fetching from Cloudflare...
=> Incorrect zone, or zone doesn't contain the A-record follow-the-white-rabbiut.net.follow-the-white-rabbit.net!
listing all records for zone follow-the-white-rabbit.net:
ID RECORD TYPE
******42747 follow-the-white-rabbit.net "A"
******42744 www.follow-the-white-rabbit.net "A"
******42750 autodiscover.follow-the-white-rabbit.net "CNAME"
******42756 follow-the-white-rabbit.net "MX"
******42753 follow-the-white-rabbit.net "MX"