Update multiple Bind zone files with sed

Update multiple Bind zone files with sed

Problem description: Your DNS infrastructure is running on Bind and the operating system is linux. You need to update a host record (A) “private”. The current ip address is : 10.1.0.22. The new ip address is 10.45.2.1

Solution:

  1. To check all zone files you can type the command below:
    grep 10.1.0.22 *.dns
    The output will give you the list of the zone files with the records that use this ip address.
  2. To change the ip address on all of the zone files, use the following command:
    sed -i 's/10.1.0.22/10.45.2.1/g' *.dns
  3. After that, you will need to update the serial number of all zone files :
    sed -i 's/20[0-9][0-9]\{7\}/2015012201/g' *.dns
    In our case, the serial number is using the following template : YYYYMMDDNN where NN is the update number for that day.
  4. You can now reload all zones:
    rndc reload

Check your logs and that’s all !

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Social Media Auto Publish Powered By : XYZScripts.com