Results 1 to 6 of 6

Thread: Linux / Unix Shell Script To Edit DNS zone files

  1. #1
    Junior Member jbooth45's Avatar
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Linux / Unix Shell Script To Edit DNS zone files

    Hello,
    I have been trying to come up with a script to parse a DNS master zone file and manipulate it to point to a new IP address, but to no avail. It sounds simple and I'm sure it is, however I don't believe my Linux knowledge expands quite that far yet. I would greatly appreciate any assistance.
    I'm using Centos 6.3

    --nixCraft Forum newcomer
    Last edited by jbooth45; 3rd October 2012 at 10:41 PM.

  2. #2
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    447
    Thanks
    10
    Thanked 46 Times in 43 Posts
    Rep Power
    6

    Default

    Hello,

    what you have tried ?
    check this page for the same
    Rahul Patil <http://www.linuxian.com>

  3. #3
    Junior Member jbooth45's Avatar
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Quote Originally Posted by Rahul.Patil View Post
    Hello,

    what you have tried ?
    check this page for the same
    Rahul,
    I spent many hours scouring the net and found something that I thought was going to work. Someone had posted a thread (not on this forum I believe and I can't seem to locate it any longer) about using sed to parse the zone file and look for a specific pattern (the IP address that points to the domain) and change it accordingly.

    I've peeked at what you linked and so far it looks very promising, so thank you, profusely. I will try to work with that and see what I can come up with.

  4. #4
    Junior Member jbooth45's Avatar
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Rahul,
    The link you posted is good and I like it and will probably use it for future projects, but I want to be able to change JUST the IP address in the zone file automatically, without my intervention.

    I was thinking about in place of the IP address denoted in the zone file, I could use command substitution such as:
    Code:
    $(cat /path/to/ip_file)
    and then just have that file it is referencing automatically updated as necessary. Think this could work?


    --nixCraft Forum newcomer

  5. #5
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,374
    Thanks
    17
    Thanked 754 Times in 496 Posts
    Rep Power
    10

    Default

    Use sed command search and replace.

    Code:
    sed 's/OLD-IP-HERE/NEW-IP-HERE/' input > output
    sed -i 's/OLD-IP-HERE/NEW-IP-HERE/' input
    ## replace 202.1.2.3 with 99.1.2.3
    sed -i 's/202.1.2.3/99.1.2.3/' /path/to/zone.db
    Also, you need to backup zone.db before making any changes.
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  6. #6
    Junior Member jbooth45's Avatar
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Quote Originally Posted by nixcraft View Post
    Use sed command search and replace.

    Code:
    sed 's/OLD-IP-HERE/NEW-IP-HERE/' input > output
    sed -i 's/OLD-IP-HERE/NEW-IP-HERE/' input
    ## replace 202.1.2.3 with 99.1.2.3
    sed -i 's/202.1.2.3/99.1.2.3/' /path/to/zone.db
    Also, you need to backup zone.db before making any changes.
    Awesome-sauce Nixcraft!!! Thank you so much! This worked excellently. I appreciate the guidance greatly.

    --Nixcraft newcomer

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 20th September 2011, 07:06 PM
  2. [Solved] Small error in unix shell script that is used for backing up files
    By aish in forum Shell scripting
    Replies: 4
    Last Post: 24th June 2011, 04:44 PM
  3. Replies: 3
    Last Post: 1st February 2011, 09:10 PM
  4. Linux gui tools to edit files
    By never_give_up in forum Ubuntu / Debian
    Replies: 1
    Last Post: 21st July 2009, 08:14 PM
  5. Shell BIND NAMED Zone Creation Script
    By asim.mcp in forum Shell scripting
    Replies: 4
    Last Post: 13th February 2009, 04:51 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41