1

There are two WAN interfaces to different ISP, which are configured with PEERDNS=yes and installed BIND 9 server which is configured with forward only.

These interfaces are used in rotation (not same time).

What is the preferred method in CentOS 6.3 allows to change the BIND forwarders to active ISP nameservers when changing active WAN interface?

jurijcz
  • 207
  • 3
  • 9

2 Answers2

3

It sounds like you have a fairly simple use case. Assuming that you are only operating as a forwarder (i.e. you do not have a large set of zone data or complicated configuration to reload) you might as well just have something which just changes the configuration file and then causes named to reload it using "rndc reconfig"

What I might do to make this a little cleaner would be to use the "include" directive in your named.conf, e.g.

# {stuff that you do all the time}
blah
blah
blah

# ISP specific forwarding section
include "ISP-forwarder-config.conf";

# {other stuff}

and then have "ISP-forwarder-config.conf" be a symlink that you can switch between target files for "ISP-1.conf" and "ISP-2.conf". (choose your own names, but the idea is that if you are only switching the symlink and not messing with your master named.conf file all the time there's much less chance of suffering some mishap that messes up your config.

To change forwarders, then, all you would need to do is change the target of the symlink and do an "rndc reconfig"

Michael McNally
  • 1,500
  • 9
  • 14
  • Exactly, a symbolic link to preformatted configs is a solution, because isn't possible to include `/var/run/ppp/resolv.conf` directly inside `forwardes { }` section of `named.conf`. Thank you, you gave me the idea (I place it as a response). – jurijcz Oct 02 '12 at 07:08
1

set PEERDNS=no for my interfaces to ISPs in /etc/sysconfig/network-scripts/ifup-ppp0 and /etc/sysconfig/network-scripts/ifup-ppp1

create executable script /usr/sbin/ifup-local with:

#!/bin/sh
if [[ "ppp0 ppp1" =~ $1 ]] ; then
  conf='/etc/named/forwarders.conf'
  fetc=$(cat $conf)
  frun=$(echo 'forwarders {';sed 's/nameserver //g;s/$/;/g' /var/run/ppp/resolv.conf;echo '};';)
  echo $frun > $conf
  named-checkconf > /dev/null 2>&1 || echo $fetc > $conf
  rndc reconfig
fi

edit option { } section in /etc/named.conf with:

include "/etc/named/forwarders.conf";
jurijcz
  • 207
  • 3
  • 9