You are not logged in.

#1 2008-06-20 18:20:46

jethro
Member
From: Canton, MI USA
Registered: 2008-06-18
Posts: 19

Adding search domains to the default DHCP DNS

Our DHCP isolates clients to a separate subnet than the servers. As such, unless you fully qualify the server name, you can't find the server. A work around is to put the IP in the hosts file, but there are just too many servers to do that with. Another option is to add the search domain(s) in the to the end of the search line in resolv.conf, however that file is re-written by dhcpcd, so changes are quickly lost.

Is there a way to add on search domains to what DHCP hands your system?

Thanks,
--Jeff

Offline

#2 2008-06-20 20:47:49

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Adding search domains to the default DHCP DNS

From the resolv.conf manpage:

manpage wrote:

In order to force options to be passed to the resolver(3) routines, the file resolv.conf.tail may be created manually. This file will be appended to the generated resolv.conf file by dhclient-script(8), ensuring options remain.

However the resolv.conf.tail file may be useful on notebooks, to search multiple domains, to refer to hard-coded information in local files, or otherwise override the defaults.

Try that.

Offline

#3 2008-06-30 18:57:48

jethro
Member
From: Canton, MI USA
Registered: 2008-06-18
Posts: 19

Re: Adding search domains to the default DHCP DNS

I had reviewed the man pages and just double checked - no mention of resolv.conf.tail. I tried it anyway and it did not work for me - apparently ArchLinux doesn't support it. Any other suggestions? I still have not found a solution.

--Jeff

Offline

#4 2008-06-30 19:15:08

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: Adding search domains to the default DHCP DNS

Try adding "-R" to /etc/conf.d/dhcpcd - that should stop dhcpcd from touching resolv.conf.

Offline

#5 2008-06-30 19:57:24

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Adding search domains to the default DHCP DNS

jethro wrote:

I had reviewed the man pages and just double checked - no mention of resolv.conf.tail. I tried it anyway and it did not work for me - apparently ArchLinux doesn't support it. Any other suggestions? I still have not found a solution.

--Jeff

Oops, that's an OpenBSD thing. Useful. But not relevant.

Offline

#6 2008-06-30 20:32:29

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: Adding search domains to the default DHCP DNS

Add to the dchp server conf (isc dhcpd):

option domain-name "domain1.com domain2.net domain3.org";

where domain1.com,etc.. are the domain suffixes you want added to the resolv.conf file on each client.

Note: pretty sure you can add that option to a subnet declaration, if you are using isc dhcpd, so that the servers will not get it..just the clients. I think dnsmasq has a similar method..but don't quote me on that.


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#7 2008-07-01 13:59:43

jethro
Member
From: Canton, MI USA
Registered: 2008-06-18
Posts: 19

Re: Adding search domains to the default DHCP DNS

Try adding "-R" to /etc/conf.d/dhcpcd - that should stop dhcpcd from touching resolv.conf.

Yep, I see how that could work. The downside to that would be that it also makes the nameservers static - generally not a problem but something to remember if the network group starts fiddling around. If the other option (below) mentioned doesn't pan out, this would be a good fallback.

Add to the dchp server conf (isc dhcpd):

I don't understand which file you are talking about editing - could you be more specific? I have no isc* or dhcpcd* on my drive.

Thanks,
--Jeff

Offline

#8 2008-07-01 14:13:58

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: Adding search domains to the default DHCP DNS

cactus refers to /etc/dhcpd.conf, a config file of a dhcp *server*.

Offline

#9 2008-07-01 14:21:12

jethro
Member
From: Canton, MI USA
Registered: 2008-06-18
Posts: 19

Re: Adding search domains to the default DHCP DNS

cactus refers to /etc/dhcpd.conf, a config file of a dhcp *server*.

Getting them to change something on that end is like pulling teeth. Well, actually more difficult than pulling teeth. I'll just use the -R option in this instance.

I'm surprised there isn't a more elegant way to do this on the client end. The tail file would have done the trick if it was applicable to ArchLinux. This is for a desktop, so not a huge issue. However, I guess I have to forgo the whole idea of adding search domains on my laptop since it will be on different networks (with different nameservers) so the -R option would only work for one given site.

--Jeff

Offline

#10 2008-07-01 14:24:11

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Adding search domains to the default DHCP DNS

From the OpenBSD resolv.conf manpage:

manpage wrote:

In order to force options to be passed to the resolver(3) routines, the file resolv.conf.tail may be created manually. This file will be appended to the generated resolv.conf file by dhclient-script(8), ensuring options remain.

However the resolv.conf.tail file may be useful on notebooks, to search multiple domains, to refer to hard-coded information in local files, or otherwise override the defaults.

Creating this file would be the most elegant way, IMO.

Who works on this part of the distro?

Offline

#11 2008-07-01 14:26:46

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Adding search domains to the default DHCP DNS

I just realized that jethro is using dhcpcd . . . the man page MAY not be JUST for OpenBSD, it looks like it is refering to dhclient.

Jethro: Can you install dhclient and use that instead of dhcpcd? Then create a resolv.conf.tail and add in your search domains. It MAY work.

Offline

#12 2008-07-01 14:33:35

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: Adding search domains to the default DHCP DNS

I'm not sure if this would work, but you could try to set up dnsmasq on your client, as an additional layer of dns resolving. Perhaps you will be able to set it up the way you want. If anything, you can use it to cache dns queries ;-)

Offline

#13 2008-07-01 14:44:08

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Adding search domains to the default DHCP DNS

This should resolv your problems.

Basically you will need to create the file /etc/resolv.conf.tail (give it the same permissions as resolv.conf)

Add in the following lines:

search <domain>
nameserver <DNS server 1>
nameserver <DNS server 2>

Then make yourself a script (like so):

#!/bin/bash

if [ -f /etc/resolv.conf.tail ]; then
   cat /etc/resolv.conf.tail >> /etc/resolv.conf
fi

Found that Here http://lists.freebsd.org/pipermail/free … 16167.html

After that just run your script on login, you should be fine.

Edit: Here is a VERY experimental patch for /etc/dhclient-script, this will add the /etc/resolv.conf.tail support.

Back up your original /sbin/dhclient-script BEFORE APPLYING THIS PATCH

--- ./dhclient-script    2008-07-01 11:14:35.000000000 -0400
+++ dhclient-script-arch    2008-07-01 11:18:46.000000000 -0400
@@ -43,6 +43,10 @@
     for nameserver in $new_domain_name_servers; do
       echo nameserver $nameserver >>/etc/resolv.conf
     done
+    if [ -f /etc/resolv.conf.tail ]; then
+        cat /etc/resolv.conf.tail >>/etc/resolv.conf
+        logger Adding /etc/resolv.conf.tail to /etc/resolv.conf
+    fi
   fi
 }

Last edited by timetrap (2008-07-01 15:35:38)

Offline

#14 2008-07-01 16:47:32

jethro
Member
From: Canton, MI USA
Registered: 2008-06-18
Posts: 19

Re: Adding search domains to the default DHCP DNS

I did this before the last couple of responses to this thread - let me know what you think...

I removed dhcpcd and installed dhclient. Then I created an /etc/dhclient.conf with just one line:

supersede domain-name "first.search.domain second.search.domain";

Then I updated /etc/rc.d/network by commenting out the line

# [ -f /etc/conf.d/dhcpcd ] && . /etc/conf.d/dhcpcd

And added this line

/sbin/dhclient

Then, here's where I start to get that uncomfortable feeling. I noted that I was getting error messages from /etc/rc.d/network on boot-up related to it trying to run other instances of dhcpcd, so I ended up commenting out sections to avoid the errors. Here's the relavent section:

ifup()
{
    if [ "$1" = "" ]; then
        echo "usage: $0 ifup <interface_name>"
        return 1
    fi
    eval iwcfg="\$wlan_${1}"
    if [ "$iwcfg" != "" ]; then
        /usr/sbin/iwconfig $iwcfg
        /bin/sleep 2
    fi
#    eval ifcfg="\$${1}"
#    if [ "$ifcfg" = "dhcp" ]; then
#        # remove the .pid file if it exists
#        /bin/rm -f /var/run/dhcpcd-${1}.pid >/dev/null 2>&1
#        /bin/rm -f /var/run/dhcpcd-${1}.cache >/dev/null 2>&1
#        /sbin/dhcpcd $DHCPCD_ARGS ${1}
#    else
#        /sbin/ifconfig $ifcfg
#    fi
    return $?
}

ifdown()
{
    if [ "$1" = "" ]; then
        echo "usage: $0 ifdown <interface_name>"
        return 1
    fi
#    eval ifcfg="\$${1}"
#    if [ "$ifcfg" = "dhcp" ]; then
#        if [ -f /var/run/dhcpcd-${1}.pid ]; then
#            /bin/kill $(cat /var/run/dhcpcd-${1}.pid)
#        fi
#    fi
    # Always bring the interface itself down
    /sbin/ifconfig ${1} down >/dev/null 2>&1
    return $?
}

Everything appears to work great - it's searching the other domains just fine and no errors on boot-up.
1) Is there a more polished way to accomplish this?
2) Are my hack-and-slash edits to /etc/rc.d/network ok or do I need to replace them with some dhclient-specific code?

Thanks so far for all the help - this is an amazing forum for getting assistance.

--J

Offline

#15 2008-07-01 17:04:45

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Adding search domains to the default DHCP DNS

jethro wrote:

I did this before the last couple of responses to this thread - let me know what you think...

I removed dhcpcd and installed dhclient. Then I created an /etc/dhclient.conf with just one line:

supersede domain-name "first.search.domain second.search.domain";

If this is a desktop, it looks fine, but if its a laptop won't this cause some problems if you connect to another network?

Then I updated /etc/rc.d/network by commenting out the line

# [ -f /etc/conf.d/dhcpcd ] && . /etc/conf.d/dhcpcd

And added this line

/sbin/dhclient

I didn't need to do any of this for dhclient, but then again I blacklisted the network daemon becuase I use wicd (which uses dhclient) so it looks like you're on the right track.

Then, here's where I start to get that uncomfortable feeling. I noted that I was getting error messages from /etc/rc.d/network on boot-up related to it trying to run other instances of dhcpcd, so I ended up commenting out sections to avoid the errors. Here's the relavent section:

ifup()
{
    if [ "$1" = "" ]; then
        echo "usage: $0 ifup <interface_name>"
        return 1
    fi
    eval iwcfg="\$wlan_${1}"
    if [ "$iwcfg" != "" ]; then
        /usr/sbin/iwconfig $iwcfg
        /bin/sleep 2
    fi
#    eval ifcfg="\$${1}"
#    if [ "$ifcfg" = "dhcp" ]; then
#        # remove the .pid file if it exists
#        /bin/rm -f /var/run/dhcpcd-${1}.pid >/dev/null 2>&1
#        /bin/rm -f /var/run/dhcpcd-${1}.cache >/dev/null 2>&1
#        /sbin/dhcpcd $DHCPCD_ARGS ${1}
#    else
#        /sbin/ifconfig $ifcfg
#    fi
    return $?
}

ifdown()
{
    if [ "$1" = "" ]; then
        echo "usage: $0 ifdown <interface_name>"
        return 1
    fi
#    eval ifcfg="\$${1}"
#    if [ "$ifcfg" = "dhcp" ]; then
#        if [ -f /var/run/dhcpcd-${1}.pid ]; then
#            /bin/kill $(cat /var/run/dhcpcd-${1}.pid)
#        fi
#    fi
    # Always bring the interface itself down
    /sbin/ifconfig ${1} down >/dev/null 2>&1
    return $?
}

This will probably break if/when someone updates the network daemon. So I would keep a copy of it in your home directory.


If it's working, great job, but just keep copies of all these files in case of an update.


My method of the /etc/resolv.conf.tail is ALMOST working. Once I get it done I will see if anyone is interested in adding it to the dhclient package.

Last edited by timetrap (2008-07-01 17:06:30)

Offline

#16 2008-07-01 17:24:33

jethro
Member
From: Canton, MI USA
Registered: 2008-06-18
Posts: 19

Re: Adding search domains to the default DHCP DNS

If this is a desktop, it looks fine, but if its a laptop won't this cause some problems if you connect to another network?

Yes, that's a problem. Although I think that since I'm superceding instead of replacing, I'd still have a valid search domain in my list. Problem is that it might spend too much time trying to find the search domain that knew about the name in question. I'm going to switch from using the "supercede" command to "append" which will ensure that the DNS issued search domain is first, and then it's followed by the 'extras'. If a name isn't found, it still could cause a delay, but only if it doesn't exist (I think).

Wouldn't the resolv.conf.tail patch you are working on have the same issue as the way I approached it? Unless you do some kind of test for what network you are on before the append, it's just going to be slapping those domains on at the end, right?

This will probably break if/when someone updates the network daemon. So I would keep a copy of it in your home directory.

Excellent point, thanks for pointing it out.

My method of the /etc/resolv.conf.tail is ALMOST working. Once I get it done I will see if anyone is interested in adding it to the dhclient package.

Let me know if you refine it further. I'm going to try out what you posted above shortly (after I do the 'append') as well.

Thanks,
-J

Offline

#17 2008-07-01 19:07:56

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Adding search domains to the default DHCP DNS

To answer your first question; yes it will always "append" the resolv.conf.tail to the current dynamic search domain. ie you will always have the statically defined AND the dynamically defined domains.

I managed to get it working and I emailed the patch to jgc (the dhclient maintainer). I'll let you know if it gets accepted.

Try both patches, they both "work" but this one works "better".  As always, backup your /sbin/dhclient-script


New Patch:

--- dhclient-script    2008-07-01 14:42:52.000000000 -0400
+++ dhclient-script-arch    2008-07-01 14:41:43.000000000 -0400
@@ -35,14 +35,26 @@
        fi;
 fi;
 
+
 make_resolv_conf() {
   if [ -n "$new_domain_name_servers" ]; then
     : > /etc/resolv.conf
-    [ -n "$new_domain_name" ] && echo search $new_domain_name >/etc/resolv.conf
+    if [ -f "/etc/resolv.conf.tail" ]; then
+        export tailname=`awk '/search/' /etc/resolv.conf.tail | sed -e 's/^search //'`
+        logger $tailname
+        export tailserver=`awk '/nameserver/' /etc/resolv.conf.tail | sed -e 's/^nameserver //'`
+        logger $tailserver
+    else
+        logger No /etc/resolv.conf.tail
+    fi
+    [ -n "$new_domain_name" ] && echo search $new_domain_name $tailname >/etc/resolv.conf
     chmod 644 /etc/resolv.conf
     for nameserver in $new_domain_name_servers; do
       echo nameserver $nameserver >>/etc/resolv.conf
     done
+    for new_tailserver in $tailserver; do
+      echo nameserver $new_tailserver >>/etc/resolv.conf
+    done
   fi
 }

Offline

#18 2008-07-01 19:44:05

jethro
Member
From: Canton, MI USA
Registered: 2008-06-18
Posts: 19

Re: Adding search domains to the default DHCP DNS

I revereted my system back to the way it defaulted to on the build (using dhcpcd) and tried the other stuff...

First I did the deal with the tail file and the script to append it to resolv.conf. Worked, but kludgy. Also realized that my second appended 'search' statement nullified the one already in resolv.conf, so you'd have to insure that you included that one in the resolve.conf.tail as well.

Next I tried the 1st edit of /sbin/dhclient-script, only to realize I don't have this file. I did a find on my drive and it doesn't exist anywhere. Am I misunderstanding something or do we have two different configurations and aren't apples to apples?

-J

Last edited by jethro (2008-07-01 19:44:32)

Offline

#19 2008-07-01 20:22:51

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Adding search domains to the default DHCP DNS

jethro wrote:

I revereted my system back to the way it defaulted to on the build (using dhcpcd) and tried the other stuff...

Next I tried the 1st edit of /sbin/dhclient-script, only to realize I don't have this file. I did a find on my drive and it doesn't exist anywhere. Am I misunderstanding something or do we have two different configurations and aren't apples to apples?

I assume from the first statement that you un-installed dhclient. Which would mean that you removed /sbin/dhclient-script  big_smile

Offline

#20 2008-07-02 14:31:13

jethro
Member
From: Canton, MI USA
Registered: 2008-06-18
Posts: 19

Re: Adding search domains to the default DHCP DNS

I assume from the first statement that you un-installed dhclient. Which would mean that you removed /sbin/dhclient-script

Yeah, you'd think I would have figured that one out....

Ok, back to dhclient, tried first patch, worked fine. Same deal as the manual one where the new search statement completely supercedes the auto-generated one, so you have to make sure you have all the search domains in the tail file.

I was about to do the second one and wanted to ask first about the relavence of the + and - in the front of the line - does the minus indicate that line should be deleted?

-    [ -n "$new_domain_name" ] && echo search $new_domain_name >/etc/resolv.conf
+    if [ -f "/etc/resolv.conf.tail" ]; then

Thanks,
--J

Offline

#21 2008-07-02 14:38:18

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: Adding search domains to the default DHCP DNS

jethro wrote:

I was about to do the second one and wanted to ask first about the relavence of the + and - in the front of the line - does the minus indicate that line should be deleted?

Yep. That's the syntax of "diff" and "patch" tools.

(the word is relevance - it spoils your otherwise nice statements ;-))

Last edited by lucke (2008-07-02 14:44:02)

Offline

#22 2008-07-02 16:10:51

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Adding search domains to the default DHCP DNS

jethro, just make sure to revert to the original dhclient-script before applying the latest patch.

Can you take out your superseded config? I need to know which one of the patches works, they format the /etc/resolv.conf differently.  And can you tell me if there is any difference in speed etc?

Offline

#23 2008-07-02 18:17:39

jethro
Member
From: Canton, MI USA
Registered: 2008-06-18
Posts: 19

Re: Adding search domains to the default DHCP DNS

Mmmm, patch not working so good. Or I type-o'd it and don't see it. Here's a cut/paste from my dhclient-script file. Mind you I cut/pasted most of it from your above email into the dhclient-script file:

make_resolv_conf() {
  if [ -n "$new_domain_name_servers" ]; then
    : > /etc/resolv.conf
#    [ -n "$new_domain_name" ] && echo search $new_domain_name >/etc/resolv.conf
  if [ -f "/etc/resolv.conf.tail" ]; then
    export tailname=`awk '/search/' /etc/resolv.conf.tail | sed -e 's/^search //'`
    logger $tailname
    export tailserver=`awk '/nameserver/' /etc/resolv.conf.tail | sed -e 's/^nameserver //'`
    logger $tailserver
  else
    logger No /etc/resolv.conf.tail
  fi
  [ -n "$new_domain_name" ] && echo search $new_domain_name $tailname >/etc/resolv.conf

     chmod 644 /etc/resolv.conf
     for nameserver in $new_domain_name_servers; do
       echo nameserver $nameserver >>/etc/resolv.conf
     done
    for new_tailserver in $tailserver; do
      echo nameserver $new_tailserver >>/etc/resolv.conf
    done

  fi

When I boot, I see the usual DHCP stuff fire up, then it says
    DHCPACK from 10.14.64.3
and it freezes. That IP must be our DHCP server here. CTRL-C/CTRL-ALT-DEL/etc don't work - have to power off.
Is this looping?

the word is relevance

Yeah - always nice to get spelling errors pointed out by people who probably use English as a second language. I blame my skools, or pretty much anyone but myself. smile

jethro, just make sure to revert to the original dhclient-script before applying the latest patch.

Yep, did that

Can you take out your superseded config?

Did that too.

Any ideas?

--J

Offline

#24 2008-07-03 00:44:29

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: Adding search domains to the default DHCP DNS

What does your /etc/resolv.conf file look like after running the new dhclient-script?

Offline

#25 2008-07-03 11:01:04

jethro
Member
From: Canton, MI USA
Registered: 2008-06-18
Posts: 19

Re: Adding search domains to the default DHCP DNS

What does your /etc/resolv.conf file look like after running the new dhclient-script?

It appears to be untouched by the script - probably because it freezes before that point, but that's just a guess. Here's the file...

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.1.9.22
nameserver 10.1.10.22
search clients.nasa.microsloth.corp.

Offline

Board footer

Powered by FluxBB