WEIGEL FORUM
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Login

    DynDNS mit AWS Route53

    Linux
    1
    1
    24
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DerMeldosD
      DerMeldos
      last edited by DerMeldos

      1. AWS CLI Installieren
        https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html

      2. AWS CLI Configurieren

      $ aws configure
      AWS Access Key ID [None]: 
      AWS Secret Access Key [None]: 
      Default region name [None]: 
      Default output format [None]: json
      
      1. Script Ordner Erstellen und folgendes Scirpt anlegen und anpassen:
      #!/bin/bash
      
      # (optional) You might need to set your PATH variable at the top here
      # depending on how you run this script
      #PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      
      # Hosted Zone ID e.g. BJBK35SKMM9OE
      ZONEID="enter zone id here"
      
      # The CNAME you want to update e.g. hello.example.com
      RECORDSET="enter cname here"
      
      # More advanced options below
      # The Time-To-Live of this recordset
      TTL=300
      # Change to AAAA if using an IPv6 address
      TYPE="A"
      
      # Get the external IP address from OpenDNS (more reliable than other providers)
      IP=`curl http://checkip.amazonaws.com/`
      
      function valid_ip()
      {
          local  ip=$1
          local  stat=1
      
          if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
              OIFS=$IFS
              IFS='.'
              ip=($ip)
              IFS=$OIFS
              [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
                  && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
              stat=$?
          fi
          return $stat
      }
      
      # Get current dir
      # (from http://stackoverflow.com/a/246128/920350)
      DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
      LOGFILE="$DIR/update-route53.log"
      IPFILE="$DIR/update-route53.ip"
      
      if ! valid_ip $IP; then
          echo "Invalid IP address: $IP" >> "$LOGFILE"
          exit 1
      fi
      
      # Check if the IP has changed
      if [ ! -f "$IPFILE" ]
          then
          touch "$IPFILE"
      fi
      
      if grep -Fxq "$IP" "$IPFILE"; then
          # code if found
          echo "IP is still $IP. Exiting" >> "$LOGFILE"
          exit 0
      else
          echo "IP has changed to $IP" >> "$LOGFILE"
          # Fill a temp file with valid JSON
          TMPFILE=$(mktemp /tmp/temporary-file.XXXXXXXX)
          cat > ${TMPFILE} << EOF
          {
            "Changes":[
              {
                "Action":"UPSERT",
                "ResourceRecordSet":{
                  "ResourceRecords":[
                    {
                      "Value":"$IP"
                    }
                  ],
                  "Name":"$RECORDSET",
                  "Type":"$TYPE",
                  "TTL":$TTL
                }
              }
            ]
          }
      EOF
      
          # Update the Hosted Zone record
          aws route53 change-resource-record-sets \
              --hosted-zone-id $ZONEID \
              --change-batch file://"$TMPFILE" >> "$LOGFILE"
          echo "" >> "$LOGFILE"
      
          # Clean up
          rm $TMPFILE
      fi
      
      # All Done - cache the IP address for next time
      echo "$IP" > "$IPFILE"
      
      1. Cron Job erstellen
      crontab -e
      
      PATH=/usr/bin:/usr/local/bin
      * * * * * /bin/bash /usr/local/bin/scripts/update-route53.sh
      

      CREDIT: https://avishayil.medium.com/dynamic-dns-using-aws-route-53-60a2331a58a4

      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Powered by NodeBB | Contributors