Skip to content

Instantly share code, notes, and snippets.

@alixaxel
Forked from Techwolf12/README.md
Last active October 9, 2024 21:00

Revisions

  1. alixaxel revised this gist Aug 22, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -9,3 +9,5 @@ What you need to do:

    This will output the zones on STDOUT. If you want to save this to a zonefile, you can use this example:
    `./generate_v6_ptr.sh /path/to/zonefile.zone > /etc/bind/ip6.arpa.zone`

    cryptsetup
  2. @Techwolf12 Techwolf12 renamed this gist Jul 26, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @Techwolf12 Techwolf12 created this gist Jul 26, 2019.
    42 changes: 42 additions & 0 deletions generate_v6_ptr.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    #!/bin/bash

    read -r -d '' ZONEHEADER <<- EOM
    $TTL 1h ; Default TTL
    @ IN SOA <NAMESERVER 1>. <ABUSE EMAIL>. (
    2019071201 ; serial
    1h ; slave refresh interval
    15m ; slave retry interval
    1w ; slave copy expire time
    1h ; NXDOMAIN cache time
    )
    ;
    ; domain name servers
    ;
    @ IN NS <NAMESERVER 1>.
    @ IN NS <NAMESERVER 2>.
    ; IPv6 PTR entries
    EOM

    # Script:

    function reverseIp6 {
    echo "$1" | awk -F: 'BEGIN {OFS=""; }{addCount = 9 - NF; for(i=1; i<=NF;i++){if(length($i) == 0){ for(j=1;j<=addCount;j++){$i = ($i "0000");} } else { $i = substr(("0000" $i), length($i)+5-4);}}; print}' | rev | sed -e "s/./&./g"
    }


    if [ -z "$1" ]
    then
    echo "Usage: $0 <zonefile>"
    exit 1
    fi

    RECORD=(`cat $1 | grep AAAA | awk -v'OFS=,' '$2 == "IN" {print $4}'`)
    HOST=(`cat $1 | grep AAAA | awk -v'OFS=,' '$2 == "IN" {print $1}'`)

    echo "$ZONEHEADER"
    for (( i=0; i<${#RECORD[@]}; i++ )); do
    echo "$(reverseIp6 ${RECORD[i]})ip6.arpa. IN PTR ${HOST[i]}";
    done
    11 changes: 11 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    Generating IPv6 PTR records from a Bind9 Zonefile using Bash.
    =====

    The following script takes a Bind9 zonefile, gets all AAAA records from it and generated PTR records based on them.

    What you need to do:
    1. Edit the Zone header in the script.
    2. Run the script with `./generate_v6_ptr.sh /path/to/zonefile.zone`

    This will output the zones on STDOUT. If you want to save this to a zonefile, you can use this example:
    `./generate_v6_ptr.sh /path/to/zonefile.zone > /etc/bind/ip6.arpa.zone`