So I did some more research and I found out that in /etc/dhclient.conf (location depending on distro) you can add the following to have static addition of multiple domain-name (search mydomain mydomain2 in /etc/resolv.conf):
Code:
append domain-name "mydomain mydomain2"
BUT: this will always add those search domains to your /etc/resolv.conf.
Another way is by installing openresolv and adding the following line to /etc/resolvconf.conf
Code:
search_domains="mydomain mydomain2"
BUT: this will again always add those entries.
REAL SOLUTION:
I found something about dhclient-script (resides in /sbin). This is just a bash script so you can easily change this script to your needs.
I changed make_resolv_conf() and added a few lines in the beginning of the file to initialize some variables (which you have to tune to your network).
After the code is changed only the first 3 variables should be edited to match your network where you want to add those additional search domains.
Code:
# Definition of variables
INTERFACE="eth0"
OFFICE_NETWORK="192.168.50."
ADDITIONAL_DOMAINS="mydomain mydomain2"
make_resolv_conf() {
if [ x$PEER_DNS = x ] || [ x$PEER_DNS = xyes ]; then
if [ "x$new_domain_name" != x ] || [ "x$new_domain_name_servers" != x ]; then
conf="# Generated by dhclient for interface $interface\n"
if [ "x$new_domain_name" != x ]; then
# DO NOT MOVE THESE: if put with the variables, the interface wont have an IP yet
IP=$(ifconfig $INTERFACE | grep inet\ addr: | grep -o -E "[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}" | head -n1)
ISATOFFICE=$(echo $IP | grep $OFFICE_NETWORK > /dev/null ; echo $?)
if [ "$ISATOFFICE" = "0" ]; then
conf="${conf}search $new_domain_name $ADDITIONAL_DOMAINS\n"
else
conf="${conf}search $new_domain_name\n"
fi
fi
for nameserver in $new_domain_name_servers; do
conf="${conf}nameserver $nameserver\n"
done
if [ -x /sbin/resolvconf ]; then
printf "$conf" | resolvconf -a "$interface"
else
printf "$conf" > /etc/resolv.conf
chmod 644 /etc/resolv.conf
fi
fi
fi
# If we're making confs, may as well make an ntp.conf too
make_ntp_conf
}
For people who want to use this I will put a unified diff:
Code:
--- /sbin/dhclient-script.bak 2009-12-17 17:05:36.000000000 +0100
+++ /sbin/dhclient-script 2009-12-17 17:59:17.000000000 +0100
@@ -22,12 +22,24 @@
# 4. TIMEOUT not tested. ping has a flag I don't know, and I'm suspicious
# of the $1 in its args.
+# Definition of variables
+INTERFACE="eth0"
+OFFICE_NETWORK="192.168.50."
+ADDITIONAL_DOMAINS="mydomain mydomain2"
+
make_resolv_conf() {
if [ x$PEER_DNS = x ] || [ x$PEER_DNS = xyes ]; then
if [ "x$new_domain_name" != x ] || [ "x$new_domain_name_servers" != x ]; then
conf="# Generated by dhclient for interface $interface\n"
if [ "x$new_domain_name" != x ]; then
- conf="${conf}search $new_domain_name\n"
+ # DO NOT MOVE THESE: if put with the variables, the interface wont have an IP yet
+ IP=$(ifconfig $INTERFACE | grep inet\ addr: | grep -o -E "[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}" | head -n1)
+ ISATOFFICE=$(echo $IP | grep $OFFICE_NETWORK > /dev/null ; echo $?)
+ if [ "$ISATOFFICE" = "0" ]; then
+ conf="${conf}search $new_domain_name $ADDITIONAL_DOMAINS\n"
+ else
+ conf="${conf}search $new_domain_name\n"
+ fi
fi
for nameserver in $new_domain_name_servers; do
conf="${conf}nameserver $nameserver\n"
As you can see: only a few lines of code!
I will do a final test when I am home in a few hours