How to get the DHCP-controlled DNS domain name for my Ubuntu machines in a Windows network?

8,530

You need to configure your DHCP server so it set on the DHCP client the domain-search

http://linux.die.net/man/5/dhcp-options

option domain-search domain-list; The domain-search option specifies a 'search list' of Domain Names to be used by the client to locate not-fully-qualified domain names. The difference between this option and historic use of the domain-name option for the same ends is that this option is encoded in RFC1035 compressed labels on the wire. For example:

option domain-search "example.com", "sales.example.com", "eng.example.com";

This way when you perform an nslookup it will try with all the specified domains until it finds a valid response (or until loop through all them).

So if you perform nslookup server1 if will try to query dns for

  1. server1.example.com
  2. server1.sales.example.com
  3. eng.example.com
Share:
8,530

Related videos on Youtube

Urhixidur
Author by

Urhixidur

Started programming back in the late 1970s (FORTRAN and APL at first, later C and Pascal) on mainframes, then my own 8-bit Atari (BASIC, 6502 assembler) and so on ever since. I'm also quite active in various Wikimedia projects, using the same handle.

Updated on September 18, 2022

Comments

  • Urhixidur
    Urhixidur over 1 year

    I've been going in circles for a while trying to figure this out. I have a number of Ubuntu machines (some virtual) on a Windows network. From a Windows machine, I can ping or nslookup the Ubuntu machines, but not the reverse unless the Ubuntu machines specify fully qualified DNS names. But I can't seem to get the qualification suffix from the Ubuntu environment.

    An example will clarify what is going on. Assume the Windows machine is called Win1, the Ubuntu machine Ubu1, and the network suffix is .notlocalatall.

    On Win1:
    $ echo %USERDNSDOMAINNAME%
    notlocalatall
    $ nslookup Ubu1
    [...]
    Name:    Ubu1.notlocalatall
    Address: 131.132.32.14
    $ nslookup Ubu1.notlocalatall
    [...]
    Name:    Ubu1.notlocalatall
    Address: 131.132.32.14
    $ ping Ubu1
    [works normally, with 0% packet loss]
    $ ping Ubu1.notlocalatall
    [works normally, with 0% packet loss]
    

    On Ubu1:
    $ hostname -d
    [blank]
    $ nslookup Win1
    [...]
    ** server can't find Win1: SERVFAIL
    $ nslookup Win1.notlocalatall
    [...]
    Name:    Win1.notlocalatall
    Address: 131.132.32.167
    $ ping Win1
    ping: unknown host Win1
    $ ping Win1.notlocalatall
    [works normally, with 0% packet loss]
    

    For ssh purposes, I could live with having to specify the DNS suffix, but I need to get it from some command or bit of script.

    And no, the solution is not to edit /etc/hosts, because the whole thing runs under DHCP.

    Ubu1 is running Ubuntu 12.04.5 LTS and the Network control panel's Options: IPv4 Parameters are set to "Automatic (DHCP)".

    • Stuart Smith
      Stuart Smith about 9 years
      On the Ubuntu client side, you can try this: askubuntu.com/questions/52001/…
    • Urhixidur
      Urhixidur about 9 years
      That was it! I edited my networking connection to specify the suffix as the search domain, and now nslookup works the same with and without the suffix.
    • Urhixidur
      Urhixidur about 9 years
      askubuntu.com/questions/52001/… Use Jim Hume's answer, currently the second one.
  • Urhixidur
    Urhixidur about 9 years
    I cannot configure the DHCP server. I can configure the Ubuntu clients, however. Could you give an actual example of the command line expected? Something like $ sudo dhclient option domain-search "notlocalatall", I suppose?
  • alphamikevictor
    alphamikevictor about 9 years
    You can try this askubuntu.com/a/141193
  • Urhixidur
    Urhixidur about 9 years
    Tried it, didn't work. Jim Hurne's answer, right below the one at the other end of that link, turns out to be the right one.