How to get the hostname from a DHCP serverHow to set hostnames to specific range of IP addresses on DHCP Server?What is the option “host-name” for in /etc/dhcp/dhcpd.conf?different hosnames for vm clonesDomain name isn't assigned from DHCP when booting from Live CDCasper set hostname via dhcpISC-DHCP: Battling to get the host name from the dhcp scriptLocal hostname resolution with local Ubuntu DNS server failsdns server assigned from dhcp is equal to the address of the clientWhat's wrong with my isc-dhcp-server configuration?How to get the hostname from /etc/hostname & DNS domain name?

Diminished seventh cadence, is this an IAC or a PAC?

What is the narrative difference between a Charisma and Wisdom saving throw?

What license do I use when I don't want evil companies charging people money for photos?

How to calculate my anticipated peak amperage load?

Students using the same flawed online solution sheet as the grading TA

I’m 18 years old and want to finance a £30,000 car

What Lego set has the biggest box?

Why is Trump not being impeached for bribery?

No transit zone at Linate airport. Couldn't get on connecting flight. Whose responsibility is it?

Why are the Democrats & Republicans so homogeneous in their opinions of impeaching Trump?

Sudden cheap travel?

Predicting y from log y as the dependent variable

I've never seen this before. Is this primarily a "rote computational trick" for multiplication by 9 ...?

How do I force `sudo` to ask for a password each time when a specific command is used?

Why are bicycle tires incapable of maintaining pressure over time, while car tyres seem to have less of a problem?

How to scientifically explain racial weapons?

An Ailing Assassin

I am ask to complete my withdrawal transaction with COT fee of 1200 dollars

BASH print question (printf \$(printf '%03o' $1))

How to deal with this fundamental problem with the advice: "Don't trust obscure PHP libraries that nobody uses!"?

8 registers in the 9440?

What's the greatest number of hands I can have to annoy my mother-in-law with?

What would the shape of orbits of planets be if hypothetically the gravitational force be proportional to the inverse of cube of distance from Sun?

Moon's unusual gravity



How to get the hostname from a DHCP server


How to set hostnames to specific range of IP addresses on DHCP Server?What is the option “host-name” for in /etc/dhcp/dhcpd.conf?different hosnames for vm clonesDomain name isn't assigned from DHCP when booting from Live CDCasper set hostname via dhcpISC-DHCP: Battling to get the host name from the dhcp scriptLocal hostname resolution with local Ubuntu DNS server failsdns server assigned from dhcp is equal to the address of the clientWhat's wrong with my isc-dhcp-server configuration?How to get the hostname from /etc/hostname & DNS domain name?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









17


















I want Ubuntu to get the hostname and DNS name from a DHCP client. The default installation of Ubuntu 11.10 (Oneiric Ocelot) does not do that.



The same question was asked and is unsolved on Ubuntu Forums.










share|improve this question

































    17


















    I want Ubuntu to get the hostname and DNS name from a DHCP client. The default installation of Ubuntu 11.10 (Oneiric Ocelot) does not do that.



    The same question was asked and is unsolved on Ubuntu Forums.










    share|improve this question





























      17













      17









      17


      7






      I want Ubuntu to get the hostname and DNS name from a DHCP client. The default installation of Ubuntu 11.10 (Oneiric Ocelot) does not do that.



      The same question was asked and is unsolved on Ubuntu Forums.










      share|improve this question
















      I want Ubuntu to get the hostname and DNS name from a DHCP client. The default installation of Ubuntu 11.10 (Oneiric Ocelot) does not do that.



      The same question was asked and is unsolved on Ubuntu Forums.







      networking dns dhcp hostname






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 7 '15 at 21:36









      Peter Mortensen

      1,0262 gold badges11 silver badges17 bronze badges




      1,0262 gold badges11 silver badges17 bronze badges










      asked Feb 17 '12 at 1:05









      Oguz BilgicOguz Bilgic

      2731 gold badge2 silver badges7 bronze badges




      2731 gold badge2 silver badges7 bronze badges























          9 Answers
          9






          active

          oldest

          votes


















          6



















          There is a way to do it with a little script for a dhcp hook as described here.



          Create a new file:



          sudoedit /etc/dhcp/dhclient-exit-hooks.d/hostname


          and paste the following code:



          #!/bin/sh
          # Filename: /etc/dhcp/dhclient-exit-hooks.d/hostname
          # Purpose: Used by dhclient-script to set the hostname of the system
          # to match the DNS information for the host as provided by
          # DHCP.
          #


          # Do not update hostname for virtual machine IP assignments
          if [ "$interface" != "eth0" ] && [ "$interface" != "wlan0" ]
          then
          return
          fi


          if [ "$reason" != BOUND ] && [ "$reason" != RENEW ]
          && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
          then
          return
          fi

          echo dhclient-exit-hooks.d/hostname: Dynamic IP address = $new_ip_address
          hostname=$(host $new_ip_address | cut -d ' ' -f 5 | sed -r 's/((.*)[^.]).?/1/g' )
          echo $hostname > /etc/hostname
          hostname $hostname
          echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname


          Replace eth0 and wlan0 with the names of the interfaces from which you want to obtain the hostname. In most cases eth0 and wlan0 should stay the same.



          Make sure it is readable...



          chmod a+r /etc/dhcp/dhclient-exit-hooks.d/hostname


          That's all. On the next dhcp response your hostname will update automatically.






          share|improve this answer



























          • this script actually uses a DNS query (using the host command) to extract the hostname associated with the assigned IP address. DHCP servers can actually explicitly set a host name option (option 12), which can potentially be different from the hostname you obtain from a DNS query on the IP (this could potentially also fail, if no PTR record for the IP exists on the DNS)

            – Ale
            Feb 12 '15 at 10:21



















          4



















          You can get your hostname from your DHCP server - it is part of the DHCP specification.



          https://tools.ietf.org/html/rfc1533#section-3.14



          "This option specifies the name of the client"






          share|improve this answer




















          • 3





            How do you get the server to send it?

            – Olathe
            Oct 24 '13 at 12:18


















          3



















          d_inevitable's answer almost solved my problem, but not completely. The problem was that although:




          1. The DHCP server was sending a hostname (by adding the



            option host name 'client1' 


            in the dhcpd.conf) and I actually verified it by capturing and analyzing the contents of the DHCP offer with wireshark




          2. The DHCP client was expecting the hostname from DHCP server (by adding



            request host-name 


            in the dhclient.conf)



          The client was not getting a new hostname (easily verified by typing



          hostname


          in terminal and getting the old hostname, or no hostname if I had deleted the contents/file). As a result, the proposed solution by d_inevitable was only copying an empty string.



          To solve that, I applied a crud solution, that generally should not be followed unless you are desperate to make it work, like I was.



          First, open with edit capability the DHCP client control script:



          sudo vi /sbin/dhclient-script


          There, you will have to locate the function



          set_hostname()


          Just use the search and it should come right up. Now, at least on my computer, this function has three if-then-else conditions, encapsulated to each other:




          # set host name set_hostname()
          local current_hostname



          if [ -n "$new_host_name" ]; then
          current_hostname=$(hostname)

          # current host name is empty, '(none)' or 'localhost' or differs from new one from DHCP
          if [ -z "$current_hostname" ]



          Now, what you need is to force the assignment of the new hostname to your host, no matter what. Therefore you want to comment out the two encapsulated if-then-else. The result should look something like:




          # set host name set_hostname()
          # [ "$current_hostname" = 'localhost' ]



          Now the d_inevitable's or this should work as expected. Hope that helps if you are in a similar desperate frustration as I was.






          share|improve this answer
































            3



















            Oli's answer is demonstrably false ("You don't get your hostname from the DHCP server"), as evidenced by the other answers here, and also by my recent experience on a RHEL7 system. Said system got its host name from the DHCP server.



            And, indeed, there are things in the DHCP configuration files that are supposed to make it happen. For example:



            host host4 # verified 
            hardware ethernet 41:88:22:11:33:22;
            fixed-address 192.168.0.4;
            option host-name "host4";



            Is supposed to tell that host that his name is host4.



            As it turns out, isc's dhclient DOES NOT APPEAR TO SUPPORT THIS!



            However, dhcpcd5 does, out of the box. Stop dhclient, install dhcpcd5, run dhcpcd, renew your lease, and poof, your hostname on your DHCP client is set to the name sent from the DHCP server. No dhclient-exit-hooks.d scripting, no hacks in rc.local, nothing.



            As an end-note, I've spent a lot of time trying to get this to work using ISC's dhclient. Absolutely no joy, even when the server sends the host name.



            My initial solution to the problem was writing some cute code in rc.local to detect when the network came up and forcing a (in my case) search of /etc/hosts to get the hostname and then running hostname with that host name. It works, but until the network comes up your hostname is probably wrong (when first deploying a host, I remove /etc/hostname, so the host name is localhost until I can run /etc/init.d/hostname.sh start once the network comes up - so when first getting a new name you need to boot twice - once to get your hostname, and once to have that name available when everything starts up...).






            share|improve this answer


































              1



















              You don't get your hostname from the DHCP server.



              You can send your hostname to the server, which may change the IP you're assigned. You can change what name is sent either by editing your Network Manager connection (the field is called DHCP Client ID) or you can edit (as root) /etc/dhcp/dhclient.conf. Look for the line that says:



              send host-name "<hostname>";


              ... and change <hostname> to whatever you like.




              By default Ubuntu will get its DNS settings from the router (if it sends them) but I suspect you're talking about local DNS/mDNS where you can access other computers by their hostname. This is called Ahavi or Zeroconf in Ubuntu and it's installed by default.



              You should be able to access your computer by <hostname>.local






              share|improve this answer

























              • I have dns and dhcp (windows 2008) server on my network. Ant it assigns hostname and dns name to each ip, but ubuntu does not update it's hostname and dns name. I should be able to see this assigned hostname by typing hostname and domain by typing hostname -d. so it's fqdn should be hostname.domain

                – Oguz Bilgic
                Feb 17 '12 at 1:31












              • AFAIR if the client is not joined to the Windows domain, the Windows DHCP server will not dynamically update the Windows DNS entries. I'm not really sure though... depends on the Windows DHCP/DNS configuration

                – oddfellow
                Feb 17 '12 at 20:54











              • By default 12.04 has this line "send host-name = gethostname();" and you can see that value by typing "hostname" on the command line. By default, this will not have any effect on a windows network. As per the original question.

                – Móż
                Nov 22 '13 at 3:09











              • Although zeroconf is installed by default, it's horribly unreliable. I'm frankly surprised when it works, as pinging hostname or hostname.local rarely results in success even though nothing's changed on my network in months.

                – Cerin
                Apr 18 '15 at 19:14






              • 1





                This is not quite true. While you can send your host name to DHCP server with send host-name "example.com"; in order to obtain a specific IP address, you can just as well request one with request host-name;.

                – Dmitry Grigoryev
                Nov 17 '15 at 10:33


















              1



















              If found that can be a dhcpclient scripts bug. http://blog.schlomo.schapiro.org/2013/11/setting-hostname-from-dhcp-in-debian.html



              Try to clean $old_host_name on ip renew




              echo unset old_host_name > /etc/dhcp/dhclient-enter-hooks.d/unset_old_hostname




              Also static /etc/hostname seems to has prority over dhcp answer so leave it empty




              > /etc/hostname




              Tested on ubuntu 14.04 and dnsmasq server.






              share|improve this answer


































                1



















                Note that when using Ubuntu 18.04 the tie-in scripts are no longer necessary. If the hostname of the install is set to localhost in /etc/hostname the DHCP client will set the hostname automatically at startup using the name issued by DHCP, if present. When running hostnamectl it will list localhost as the permanent hostname, and whatever DHCP issues as a transient hostname.



                testaccount@dhcp-hostname:~$ hostnamectl
                Static hostname: localhost
                Transient hostname: dhcp-hostname





                share|improve this answer
































                  0



















                  The answer depends on whether or not you are using static leases on your DHCP server. If you are, it is unnecessary to get the hostname from DNS. You can change this line in d_inevitable's solution



                  hostname=$(host $new_ip_address | cut -d ' ' -f 5)


                  to



                  hostname=$new_host_name


                  But this should happen automatically if your hostname is originally set to localhost.localdomain, so you don't have to write a script. However, if you want to set the hostname to the FQDN, you'll need to change d_inevitable's script to



                  hostname=$new_host_name.$new_domain_name


                  Again, all this only works if you're using static leases.






                  share|improve this answer


































                    0



















                    Don't have enough reputation to comment, but I'd like to piggy-back on the previous answer as it almost solved the problem for me using a dhclient hook.



                    I've found that using the standard ISC DHCP Server for some reason, the aforementioned hook outputs a host name with a '.' period character at the end of the hostname for some reason.



                    So, in the previous answer you might need "cut out" the extraneous period with a sed:



                    hostname=$(host $new_ip_address | cut -d ' ' -f 5)


                    Would become:



                    hostname=$(host $new_ip_address | cut -d ' ' -f 5 | sed -e "s/.$//g")





                    share|improve this answer




























                      Your Answer








                      StackExchange.ready(function()
                      var channelOptions =
                      tags: "".split(" "),
                      id: "89"
                      ;
                      initTagRenderer("".split(" "), "".split(" "), channelOptions);

                      StackExchange.using("externalEditor", function()
                      // Have to fire editor after snippets, if snippets enabled
                      if (StackExchange.settings.snippets.snippetsEnabled)
                      StackExchange.using("snippets", function()
                      createEditor();
                      );

                      else
                      createEditor();

                      );

                      function createEditor()
                      StackExchange.prepareEditor(
                      heartbeatType: 'answer',
                      autoActivateHeartbeat: false,
                      convertImagesToLinks: true,
                      noModals: true,
                      showLowRepImageUploadWarning: true,
                      reputationToPostImages: 10,
                      bindNavPrevention: true,
                      postfix: "",
                      imageUploader:
                      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                      allowUrls: true
                      ,
                      onDemand: true,
                      discardSelector: ".discard-answer"
                      ,immediatelyShowMarkdownHelp:true
                      );



                      );














                      draft saved

                      draft discarded
















                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f104918%2fhow-to-get-the-hostname-from-a-dhcp-server%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown


























                      9 Answers
                      9






                      active

                      oldest

                      votes








                      9 Answers
                      9






                      active

                      oldest

                      votes









                      active

                      oldest

                      votes






                      active

                      oldest

                      votes









                      6



















                      There is a way to do it with a little script for a dhcp hook as described here.



                      Create a new file:



                      sudoedit /etc/dhcp/dhclient-exit-hooks.d/hostname


                      and paste the following code:



                      #!/bin/sh
                      # Filename: /etc/dhcp/dhclient-exit-hooks.d/hostname
                      # Purpose: Used by dhclient-script to set the hostname of the system
                      # to match the DNS information for the host as provided by
                      # DHCP.
                      #


                      # Do not update hostname for virtual machine IP assignments
                      if [ "$interface" != "eth0" ] && [ "$interface" != "wlan0" ]
                      then
                      return
                      fi


                      if [ "$reason" != BOUND ] && [ "$reason" != RENEW ]
                      && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
                      then
                      return
                      fi

                      echo dhclient-exit-hooks.d/hostname: Dynamic IP address = $new_ip_address
                      hostname=$(host $new_ip_address | cut -d ' ' -f 5 | sed -r 's/((.*)[^.]).?/1/g' )
                      echo $hostname > /etc/hostname
                      hostname $hostname
                      echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname


                      Replace eth0 and wlan0 with the names of the interfaces from which you want to obtain the hostname. In most cases eth0 and wlan0 should stay the same.



                      Make sure it is readable...



                      chmod a+r /etc/dhcp/dhclient-exit-hooks.d/hostname


                      That's all. On the next dhcp response your hostname will update automatically.






                      share|improve this answer



























                      • this script actually uses a DNS query (using the host command) to extract the hostname associated with the assigned IP address. DHCP servers can actually explicitly set a host name option (option 12), which can potentially be different from the hostname you obtain from a DNS query on the IP (this could potentially also fail, if no PTR record for the IP exists on the DNS)

                        – Ale
                        Feb 12 '15 at 10:21
















                      6



















                      There is a way to do it with a little script for a dhcp hook as described here.



                      Create a new file:



                      sudoedit /etc/dhcp/dhclient-exit-hooks.d/hostname


                      and paste the following code:



                      #!/bin/sh
                      # Filename: /etc/dhcp/dhclient-exit-hooks.d/hostname
                      # Purpose: Used by dhclient-script to set the hostname of the system
                      # to match the DNS information for the host as provided by
                      # DHCP.
                      #


                      # Do not update hostname for virtual machine IP assignments
                      if [ "$interface" != "eth0" ] && [ "$interface" != "wlan0" ]
                      then
                      return
                      fi


                      if [ "$reason" != BOUND ] && [ "$reason" != RENEW ]
                      && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
                      then
                      return
                      fi

                      echo dhclient-exit-hooks.d/hostname: Dynamic IP address = $new_ip_address
                      hostname=$(host $new_ip_address | cut -d ' ' -f 5 | sed -r 's/((.*)[^.]).?/1/g' )
                      echo $hostname > /etc/hostname
                      hostname $hostname
                      echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname


                      Replace eth0 and wlan0 with the names of the interfaces from which you want to obtain the hostname. In most cases eth0 and wlan0 should stay the same.



                      Make sure it is readable...



                      chmod a+r /etc/dhcp/dhclient-exit-hooks.d/hostname


                      That's all. On the next dhcp response your hostname will update automatically.






                      share|improve this answer



























                      • this script actually uses a DNS query (using the host command) to extract the hostname associated with the assigned IP address. DHCP servers can actually explicitly set a host name option (option 12), which can potentially be different from the hostname you obtain from a DNS query on the IP (this could potentially also fail, if no PTR record for the IP exists on the DNS)

                        – Ale
                        Feb 12 '15 at 10:21














                      6















                      6











                      6









                      There is a way to do it with a little script for a dhcp hook as described here.



                      Create a new file:



                      sudoedit /etc/dhcp/dhclient-exit-hooks.d/hostname


                      and paste the following code:



                      #!/bin/sh
                      # Filename: /etc/dhcp/dhclient-exit-hooks.d/hostname
                      # Purpose: Used by dhclient-script to set the hostname of the system
                      # to match the DNS information for the host as provided by
                      # DHCP.
                      #


                      # Do not update hostname for virtual machine IP assignments
                      if [ "$interface" != "eth0" ] && [ "$interface" != "wlan0" ]
                      then
                      return
                      fi


                      if [ "$reason" != BOUND ] && [ "$reason" != RENEW ]
                      && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
                      then
                      return
                      fi

                      echo dhclient-exit-hooks.d/hostname: Dynamic IP address = $new_ip_address
                      hostname=$(host $new_ip_address | cut -d ' ' -f 5 | sed -r 's/((.*)[^.]).?/1/g' )
                      echo $hostname > /etc/hostname
                      hostname $hostname
                      echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname


                      Replace eth0 and wlan0 with the names of the interfaces from which you want to obtain the hostname. In most cases eth0 and wlan0 should stay the same.



                      Make sure it is readable...



                      chmod a+r /etc/dhcp/dhclient-exit-hooks.d/hostname


                      That's all. On the next dhcp response your hostname will update automatically.






                      share|improve this answer
















                      There is a way to do it with a little script for a dhcp hook as described here.



                      Create a new file:



                      sudoedit /etc/dhcp/dhclient-exit-hooks.d/hostname


                      and paste the following code:



                      #!/bin/sh
                      # Filename: /etc/dhcp/dhclient-exit-hooks.d/hostname
                      # Purpose: Used by dhclient-script to set the hostname of the system
                      # to match the DNS information for the host as provided by
                      # DHCP.
                      #


                      # Do not update hostname for virtual machine IP assignments
                      if [ "$interface" != "eth0" ] && [ "$interface" != "wlan0" ]
                      then
                      return
                      fi


                      if [ "$reason" != BOUND ] && [ "$reason" != RENEW ]
                      && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
                      then
                      return
                      fi

                      echo dhclient-exit-hooks.d/hostname: Dynamic IP address = $new_ip_address
                      hostname=$(host $new_ip_address | cut -d ' ' -f 5 | sed -r 's/((.*)[^.]).?/1/g' )
                      echo $hostname > /etc/hostname
                      hostname $hostname
                      echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname


                      Replace eth0 and wlan0 with the names of the interfaces from which you want to obtain the hostname. In most cases eth0 and wlan0 should stay the same.



                      Make sure it is readable...



                      chmod a+r /etc/dhcp/dhclient-exit-hooks.d/hostname


                      That's all. On the next dhcp response your hostname will update automatically.







                      share|improve this answer















                      share|improve this answer




                      share|improve this answer








                      edited Dec 16 '14 at 23:26









                      Dmitriusan

                      3092 silver badges11 bronze badges




                      3092 silver badges11 bronze badges










                      answered May 7 '13 at 21:15









                      d_inevitabled_inevitable

                      1,6222 gold badges18 silver badges35 bronze badges




                      1,6222 gold badges18 silver badges35 bronze badges















                      • this script actually uses a DNS query (using the host command) to extract the hostname associated with the assigned IP address. DHCP servers can actually explicitly set a host name option (option 12), which can potentially be different from the hostname you obtain from a DNS query on the IP (this could potentially also fail, if no PTR record for the IP exists on the DNS)

                        – Ale
                        Feb 12 '15 at 10:21


















                      • this script actually uses a DNS query (using the host command) to extract the hostname associated with the assigned IP address. DHCP servers can actually explicitly set a host name option (option 12), which can potentially be different from the hostname you obtain from a DNS query on the IP (this could potentially also fail, if no PTR record for the IP exists on the DNS)

                        – Ale
                        Feb 12 '15 at 10:21

















                      this script actually uses a DNS query (using the host command) to extract the hostname associated with the assigned IP address. DHCP servers can actually explicitly set a host name option (option 12), which can potentially be different from the hostname you obtain from a DNS query on the IP (this could potentially also fail, if no PTR record for the IP exists on the DNS)

                      – Ale
                      Feb 12 '15 at 10:21






                      this script actually uses a DNS query (using the host command) to extract the hostname associated with the assigned IP address. DHCP servers can actually explicitly set a host name option (option 12), which can potentially be different from the hostname you obtain from a DNS query on the IP (this could potentially also fail, if no PTR record for the IP exists on the DNS)

                      – Ale
                      Feb 12 '15 at 10:21














                      4



















                      You can get your hostname from your DHCP server - it is part of the DHCP specification.



                      https://tools.ietf.org/html/rfc1533#section-3.14



                      "This option specifies the name of the client"






                      share|improve this answer




















                      • 3





                        How do you get the server to send it?

                        – Olathe
                        Oct 24 '13 at 12:18















                      4



















                      You can get your hostname from your DHCP server - it is part of the DHCP specification.



                      https://tools.ietf.org/html/rfc1533#section-3.14



                      "This option specifies the name of the client"






                      share|improve this answer




















                      • 3





                        How do you get the server to send it?

                        – Olathe
                        Oct 24 '13 at 12:18













                      4















                      4











                      4









                      You can get your hostname from your DHCP server - it is part of the DHCP specification.



                      https://tools.ietf.org/html/rfc1533#section-3.14



                      "This option specifies the name of the client"






                      share|improve this answer














                      You can get your hostname from your DHCP server - it is part of the DHCP specification.



                      https://tools.ietf.org/html/rfc1533#section-3.14



                      "This option specifies the name of the client"







                      share|improve this answer













                      share|improve this answer




                      share|improve this answer










                      answered Jan 10 '13 at 7:28









                      Dave MorrisDave Morris

                      492 bronze badges




                      492 bronze badges










                      • 3





                        How do you get the server to send it?

                        – Olathe
                        Oct 24 '13 at 12:18












                      • 3





                        How do you get the server to send it?

                        – Olathe
                        Oct 24 '13 at 12:18







                      3




                      3





                      How do you get the server to send it?

                      – Olathe
                      Oct 24 '13 at 12:18





                      How do you get the server to send it?

                      – Olathe
                      Oct 24 '13 at 12:18











                      3



















                      d_inevitable's answer almost solved my problem, but not completely. The problem was that although:




                      1. The DHCP server was sending a hostname (by adding the



                        option host name 'client1' 


                        in the dhcpd.conf) and I actually verified it by capturing and analyzing the contents of the DHCP offer with wireshark




                      2. The DHCP client was expecting the hostname from DHCP server (by adding



                        request host-name 


                        in the dhclient.conf)



                      The client was not getting a new hostname (easily verified by typing



                      hostname


                      in terminal and getting the old hostname, or no hostname if I had deleted the contents/file). As a result, the proposed solution by d_inevitable was only copying an empty string.



                      To solve that, I applied a crud solution, that generally should not be followed unless you are desperate to make it work, like I was.



                      First, open with edit capability the DHCP client control script:



                      sudo vi /sbin/dhclient-script


                      There, you will have to locate the function



                      set_hostname()


                      Just use the search and it should come right up. Now, at least on my computer, this function has three if-then-else conditions, encapsulated to each other:




                      # set host name set_hostname()
                      local current_hostname



                      if [ -n "$new_host_name" ]; then
                      current_hostname=$(hostname)

                      # current host name is empty, '(none)' or 'localhost' or differs from new one from DHCP
                      if [ -z "$current_hostname" ]



                      Now, what you need is to force the assignment of the new hostname to your host, no matter what. Therefore you want to comment out the two encapsulated if-then-else. The result should look something like:




                      # set host name set_hostname()
                      # [ "$current_hostname" = 'localhost' ]



                      Now the d_inevitable's or this should work as expected. Hope that helps if you are in a similar desperate frustration as I was.






                      share|improve this answer





























                        3



















                        d_inevitable's answer almost solved my problem, but not completely. The problem was that although:




                        1. The DHCP server was sending a hostname (by adding the



                          option host name 'client1' 


                          in the dhcpd.conf) and I actually verified it by capturing and analyzing the contents of the DHCP offer with wireshark




                        2. The DHCP client was expecting the hostname from DHCP server (by adding



                          request host-name 


                          in the dhclient.conf)



                        The client was not getting a new hostname (easily verified by typing



                        hostname


                        in terminal and getting the old hostname, or no hostname if I had deleted the contents/file). As a result, the proposed solution by d_inevitable was only copying an empty string.



                        To solve that, I applied a crud solution, that generally should not be followed unless you are desperate to make it work, like I was.



                        First, open with edit capability the DHCP client control script:



                        sudo vi /sbin/dhclient-script


                        There, you will have to locate the function



                        set_hostname()


                        Just use the search and it should come right up. Now, at least on my computer, this function has three if-then-else conditions, encapsulated to each other:




                        # set host name set_hostname()
                        local current_hostname



                        if [ -n "$new_host_name" ]; then
                        current_hostname=$(hostname)

                        # current host name is empty, '(none)' or 'localhost' or differs from new one from DHCP
                        if [ -z "$current_hostname" ]



                        Now, what you need is to force the assignment of the new hostname to your host, no matter what. Therefore you want to comment out the two encapsulated if-then-else. The result should look something like:




                        # set host name set_hostname()
                        # [ "$current_hostname" = 'localhost' ]



                        Now the d_inevitable's or this should work as expected. Hope that helps if you are in a similar desperate frustration as I was.






                        share|improve this answer



























                          3















                          3











                          3









                          d_inevitable's answer almost solved my problem, but not completely. The problem was that although:




                          1. The DHCP server was sending a hostname (by adding the



                            option host name 'client1' 


                            in the dhcpd.conf) and I actually verified it by capturing and analyzing the contents of the DHCP offer with wireshark




                          2. The DHCP client was expecting the hostname from DHCP server (by adding



                            request host-name 


                            in the dhclient.conf)



                          The client was not getting a new hostname (easily verified by typing



                          hostname


                          in terminal and getting the old hostname, or no hostname if I had deleted the contents/file). As a result, the proposed solution by d_inevitable was only copying an empty string.



                          To solve that, I applied a crud solution, that generally should not be followed unless you are desperate to make it work, like I was.



                          First, open with edit capability the DHCP client control script:



                          sudo vi /sbin/dhclient-script


                          There, you will have to locate the function



                          set_hostname()


                          Just use the search and it should come right up. Now, at least on my computer, this function has three if-then-else conditions, encapsulated to each other:




                          # set host name set_hostname()
                          local current_hostname



                          if [ -n "$new_host_name" ]; then
                          current_hostname=$(hostname)

                          # current host name is empty, '(none)' or 'localhost' or differs from new one from DHCP
                          if [ -z "$current_hostname" ]



                          Now, what you need is to force the assignment of the new hostname to your host, no matter what. Therefore you want to comment out the two encapsulated if-then-else. The result should look something like:




                          # set host name set_hostname()
                          # [ "$current_hostname" = 'localhost' ]



                          Now the d_inevitable's or this should work as expected. Hope that helps if you are in a similar desperate frustration as I was.






                          share|improve this answer














                          d_inevitable's answer almost solved my problem, but not completely. The problem was that although:




                          1. The DHCP server was sending a hostname (by adding the



                            option host name 'client1' 


                            in the dhcpd.conf) and I actually verified it by capturing and analyzing the contents of the DHCP offer with wireshark




                          2. The DHCP client was expecting the hostname from DHCP server (by adding



                            request host-name 


                            in the dhclient.conf)



                          The client was not getting a new hostname (easily verified by typing



                          hostname


                          in terminal and getting the old hostname, or no hostname if I had deleted the contents/file). As a result, the proposed solution by d_inevitable was only copying an empty string.



                          To solve that, I applied a crud solution, that generally should not be followed unless you are desperate to make it work, like I was.



                          First, open with edit capability the DHCP client control script:



                          sudo vi /sbin/dhclient-script


                          There, you will have to locate the function



                          set_hostname()


                          Just use the search and it should come right up. Now, at least on my computer, this function has three if-then-else conditions, encapsulated to each other:




                          # set host name set_hostname()
                          local current_hostname



                          if [ -n "$new_host_name" ]; then
                          current_hostname=$(hostname)

                          # current host name is empty, '(none)' or 'localhost' or differs from new one from DHCP
                          if [ -z "$current_hostname" ]



                          Now, what you need is to force the assignment of the new hostname to your host, no matter what. Therefore you want to comment out the two encapsulated if-then-else. The result should look something like:




                          # set host name set_hostname()
                          # [ "$current_hostname" = 'localhost' ]



                          Now the d_inevitable's or this should work as expected. Hope that helps if you are in a similar desperate frustration as I was.







                          share|improve this answer













                          share|improve this answer




                          share|improve this answer










                          answered Feb 8 '14 at 3:01









                          GeorgeGeorge

                          4175 silver badges13 bronze badges




                          4175 silver badges13 bronze badges
























                              3



















                              Oli's answer is demonstrably false ("You don't get your hostname from the DHCP server"), as evidenced by the other answers here, and also by my recent experience on a RHEL7 system. Said system got its host name from the DHCP server.



                              And, indeed, there are things in the DHCP configuration files that are supposed to make it happen. For example:



                              host host4 # verified 
                              hardware ethernet 41:88:22:11:33:22;
                              fixed-address 192.168.0.4;
                              option host-name "host4";



                              Is supposed to tell that host that his name is host4.



                              As it turns out, isc's dhclient DOES NOT APPEAR TO SUPPORT THIS!



                              However, dhcpcd5 does, out of the box. Stop dhclient, install dhcpcd5, run dhcpcd, renew your lease, and poof, your hostname on your DHCP client is set to the name sent from the DHCP server. No dhclient-exit-hooks.d scripting, no hacks in rc.local, nothing.



                              As an end-note, I've spent a lot of time trying to get this to work using ISC's dhclient. Absolutely no joy, even when the server sends the host name.



                              My initial solution to the problem was writing some cute code in rc.local to detect when the network came up and forcing a (in my case) search of /etc/hosts to get the hostname and then running hostname with that host name. It works, but until the network comes up your hostname is probably wrong (when first deploying a host, I remove /etc/hostname, so the host name is localhost until I can run /etc/init.d/hostname.sh start once the network comes up - so when first getting a new name you need to boot twice - once to get your hostname, and once to have that name available when everything starts up...).






                              share|improve this answer































                                3



















                                Oli's answer is demonstrably false ("You don't get your hostname from the DHCP server"), as evidenced by the other answers here, and also by my recent experience on a RHEL7 system. Said system got its host name from the DHCP server.



                                And, indeed, there are things in the DHCP configuration files that are supposed to make it happen. For example:



                                host host4 # verified 
                                hardware ethernet 41:88:22:11:33:22;
                                fixed-address 192.168.0.4;
                                option host-name "host4";



                                Is supposed to tell that host that his name is host4.



                                As it turns out, isc's dhclient DOES NOT APPEAR TO SUPPORT THIS!



                                However, dhcpcd5 does, out of the box. Stop dhclient, install dhcpcd5, run dhcpcd, renew your lease, and poof, your hostname on your DHCP client is set to the name sent from the DHCP server. No dhclient-exit-hooks.d scripting, no hacks in rc.local, nothing.



                                As an end-note, I've spent a lot of time trying to get this to work using ISC's dhclient. Absolutely no joy, even when the server sends the host name.



                                My initial solution to the problem was writing some cute code in rc.local to detect when the network came up and forcing a (in my case) search of /etc/hosts to get the hostname and then running hostname with that host name. It works, but until the network comes up your hostname is probably wrong (when first deploying a host, I remove /etc/hostname, so the host name is localhost until I can run /etc/init.d/hostname.sh start once the network comes up - so when first getting a new name you need to boot twice - once to get your hostname, and once to have that name available when everything starts up...).






                                share|improve this answer





























                                  3















                                  3











                                  3









                                  Oli's answer is demonstrably false ("You don't get your hostname from the DHCP server"), as evidenced by the other answers here, and also by my recent experience on a RHEL7 system. Said system got its host name from the DHCP server.



                                  And, indeed, there are things in the DHCP configuration files that are supposed to make it happen. For example:



                                  host host4 # verified 
                                  hardware ethernet 41:88:22:11:33:22;
                                  fixed-address 192.168.0.4;
                                  option host-name "host4";



                                  Is supposed to tell that host that his name is host4.



                                  As it turns out, isc's dhclient DOES NOT APPEAR TO SUPPORT THIS!



                                  However, dhcpcd5 does, out of the box. Stop dhclient, install dhcpcd5, run dhcpcd, renew your lease, and poof, your hostname on your DHCP client is set to the name sent from the DHCP server. No dhclient-exit-hooks.d scripting, no hacks in rc.local, nothing.



                                  As an end-note, I've spent a lot of time trying to get this to work using ISC's dhclient. Absolutely no joy, even when the server sends the host name.



                                  My initial solution to the problem was writing some cute code in rc.local to detect when the network came up and forcing a (in my case) search of /etc/hosts to get the hostname and then running hostname with that host name. It works, but until the network comes up your hostname is probably wrong (when first deploying a host, I remove /etc/hostname, so the host name is localhost until I can run /etc/init.d/hostname.sh start once the network comes up - so when first getting a new name you need to boot twice - once to get your hostname, and once to have that name available when everything starts up...).






                                  share|improve this answer
















                                  Oli's answer is demonstrably false ("You don't get your hostname from the DHCP server"), as evidenced by the other answers here, and also by my recent experience on a RHEL7 system. Said system got its host name from the DHCP server.



                                  And, indeed, there are things in the DHCP configuration files that are supposed to make it happen. For example:



                                  host host4 # verified 
                                  hardware ethernet 41:88:22:11:33:22;
                                  fixed-address 192.168.0.4;
                                  option host-name "host4";



                                  Is supposed to tell that host that his name is host4.



                                  As it turns out, isc's dhclient DOES NOT APPEAR TO SUPPORT THIS!



                                  However, dhcpcd5 does, out of the box. Stop dhclient, install dhcpcd5, run dhcpcd, renew your lease, and poof, your hostname on your DHCP client is set to the name sent from the DHCP server. No dhclient-exit-hooks.d scripting, no hacks in rc.local, nothing.



                                  As an end-note, I've spent a lot of time trying to get this to work using ISC's dhclient. Absolutely no joy, even when the server sends the host name.



                                  My initial solution to the problem was writing some cute code in rc.local to detect when the network came up and forcing a (in my case) search of /etc/hosts to get the hostname and then running hostname with that host name. It works, but until the network comes up your hostname is probably wrong (when first deploying a host, I remove /etc/hostname, so the host name is localhost until I can run /etc/init.d/hostname.sh start once the network comes up - so when first getting a new name you need to boot twice - once to get your hostname, and once to have that name available when everything starts up...).







                                  share|improve this answer















                                  share|improve this answer




                                  share|improve this answer








                                  edited Jul 28 at 17:04









                                  Community

                                  1




                                  1










                                  answered Jun 14 '18 at 20:08









                                  RustyCarRustyCar

                                  461 bronze badge




                                  461 bronze badge
























                                      1



















                                      You don't get your hostname from the DHCP server.



                                      You can send your hostname to the server, which may change the IP you're assigned. You can change what name is sent either by editing your Network Manager connection (the field is called DHCP Client ID) or you can edit (as root) /etc/dhcp/dhclient.conf. Look for the line that says:



                                      send host-name "<hostname>";


                                      ... and change <hostname> to whatever you like.




                                      By default Ubuntu will get its DNS settings from the router (if it sends them) but I suspect you're talking about local DNS/mDNS where you can access other computers by their hostname. This is called Ahavi or Zeroconf in Ubuntu and it's installed by default.



                                      You should be able to access your computer by <hostname>.local






                                      share|improve this answer

























                                      • I have dns and dhcp (windows 2008) server on my network. Ant it assigns hostname and dns name to each ip, but ubuntu does not update it's hostname and dns name. I should be able to see this assigned hostname by typing hostname and domain by typing hostname -d. so it's fqdn should be hostname.domain

                                        – Oguz Bilgic
                                        Feb 17 '12 at 1:31












                                      • AFAIR if the client is not joined to the Windows domain, the Windows DHCP server will not dynamically update the Windows DNS entries. I'm not really sure though... depends on the Windows DHCP/DNS configuration

                                        – oddfellow
                                        Feb 17 '12 at 20:54











                                      • By default 12.04 has this line "send host-name = gethostname();" and you can see that value by typing "hostname" on the command line. By default, this will not have any effect on a windows network. As per the original question.

                                        – Móż
                                        Nov 22 '13 at 3:09











                                      • Although zeroconf is installed by default, it's horribly unreliable. I'm frankly surprised when it works, as pinging hostname or hostname.local rarely results in success even though nothing's changed on my network in months.

                                        – Cerin
                                        Apr 18 '15 at 19:14






                                      • 1





                                        This is not quite true. While you can send your host name to DHCP server with send host-name "example.com"; in order to obtain a specific IP address, you can just as well request one with request host-name;.

                                        – Dmitry Grigoryev
                                        Nov 17 '15 at 10:33















                                      1



















                                      You don't get your hostname from the DHCP server.



                                      You can send your hostname to the server, which may change the IP you're assigned. You can change what name is sent either by editing your Network Manager connection (the field is called DHCP Client ID) or you can edit (as root) /etc/dhcp/dhclient.conf. Look for the line that says:



                                      send host-name "<hostname>";


                                      ... and change <hostname> to whatever you like.




                                      By default Ubuntu will get its DNS settings from the router (if it sends them) but I suspect you're talking about local DNS/mDNS where you can access other computers by their hostname. This is called Ahavi or Zeroconf in Ubuntu and it's installed by default.



                                      You should be able to access your computer by <hostname>.local






                                      share|improve this answer

























                                      • I have dns and dhcp (windows 2008) server on my network. Ant it assigns hostname and dns name to each ip, but ubuntu does not update it's hostname and dns name. I should be able to see this assigned hostname by typing hostname and domain by typing hostname -d. so it's fqdn should be hostname.domain

                                        – Oguz Bilgic
                                        Feb 17 '12 at 1:31












                                      • AFAIR if the client is not joined to the Windows domain, the Windows DHCP server will not dynamically update the Windows DNS entries. I'm not really sure though... depends on the Windows DHCP/DNS configuration

                                        – oddfellow
                                        Feb 17 '12 at 20:54











                                      • By default 12.04 has this line "send host-name = gethostname();" and you can see that value by typing "hostname" on the command line. By default, this will not have any effect on a windows network. As per the original question.

                                        – Móż
                                        Nov 22 '13 at 3:09











                                      • Although zeroconf is installed by default, it's horribly unreliable. I'm frankly surprised when it works, as pinging hostname or hostname.local rarely results in success even though nothing's changed on my network in months.

                                        – Cerin
                                        Apr 18 '15 at 19:14






                                      • 1





                                        This is not quite true. While you can send your host name to DHCP server with send host-name "example.com"; in order to obtain a specific IP address, you can just as well request one with request host-name;.

                                        – Dmitry Grigoryev
                                        Nov 17 '15 at 10:33













                                      1















                                      1











                                      1









                                      You don't get your hostname from the DHCP server.



                                      You can send your hostname to the server, which may change the IP you're assigned. You can change what name is sent either by editing your Network Manager connection (the field is called DHCP Client ID) or you can edit (as root) /etc/dhcp/dhclient.conf. Look for the line that says:



                                      send host-name "<hostname>";


                                      ... and change <hostname> to whatever you like.




                                      By default Ubuntu will get its DNS settings from the router (if it sends them) but I suspect you're talking about local DNS/mDNS where you can access other computers by their hostname. This is called Ahavi or Zeroconf in Ubuntu and it's installed by default.



                                      You should be able to access your computer by <hostname>.local






                                      share|improve this answer














                                      You don't get your hostname from the DHCP server.



                                      You can send your hostname to the server, which may change the IP you're assigned. You can change what name is sent either by editing your Network Manager connection (the field is called DHCP Client ID) or you can edit (as root) /etc/dhcp/dhclient.conf. Look for the line that says:



                                      send host-name "<hostname>";


                                      ... and change <hostname> to whatever you like.




                                      By default Ubuntu will get its DNS settings from the router (if it sends them) but I suspect you're talking about local DNS/mDNS where you can access other computers by their hostname. This is called Ahavi or Zeroconf in Ubuntu and it's installed by default.



                                      You should be able to access your computer by <hostname>.local







                                      share|improve this answer













                                      share|improve this answer




                                      share|improve this answer










                                      answered Feb 17 '12 at 1:23









                                      OliOli

                                      248k98 gold badges601 silver badges784 bronze badges




                                      248k98 gold badges601 silver badges784 bronze badges















                                      • I have dns and dhcp (windows 2008) server on my network. Ant it assigns hostname and dns name to each ip, but ubuntu does not update it's hostname and dns name. I should be able to see this assigned hostname by typing hostname and domain by typing hostname -d. so it's fqdn should be hostname.domain

                                        – Oguz Bilgic
                                        Feb 17 '12 at 1:31












                                      • AFAIR if the client is not joined to the Windows domain, the Windows DHCP server will not dynamically update the Windows DNS entries. I'm not really sure though... depends on the Windows DHCP/DNS configuration

                                        – oddfellow
                                        Feb 17 '12 at 20:54











                                      • By default 12.04 has this line "send host-name = gethostname();" and you can see that value by typing "hostname" on the command line. By default, this will not have any effect on a windows network. As per the original question.

                                        – Móż
                                        Nov 22 '13 at 3:09











                                      • Although zeroconf is installed by default, it's horribly unreliable. I'm frankly surprised when it works, as pinging hostname or hostname.local rarely results in success even though nothing's changed on my network in months.

                                        – Cerin
                                        Apr 18 '15 at 19:14






                                      • 1





                                        This is not quite true. While you can send your host name to DHCP server with send host-name "example.com"; in order to obtain a specific IP address, you can just as well request one with request host-name;.

                                        – Dmitry Grigoryev
                                        Nov 17 '15 at 10:33

















                                      • I have dns and dhcp (windows 2008) server on my network. Ant it assigns hostname and dns name to each ip, but ubuntu does not update it's hostname and dns name. I should be able to see this assigned hostname by typing hostname and domain by typing hostname -d. so it's fqdn should be hostname.domain

                                        – Oguz Bilgic
                                        Feb 17 '12 at 1:31












                                      • AFAIR if the client is not joined to the Windows domain, the Windows DHCP server will not dynamically update the Windows DNS entries. I'm not really sure though... depends on the Windows DHCP/DNS configuration

                                        – oddfellow
                                        Feb 17 '12 at 20:54











                                      • By default 12.04 has this line "send host-name = gethostname();" and you can see that value by typing "hostname" on the command line. By default, this will not have any effect on a windows network. As per the original question.

                                        – Móż
                                        Nov 22 '13 at 3:09











                                      • Although zeroconf is installed by default, it's horribly unreliable. I'm frankly surprised when it works, as pinging hostname or hostname.local rarely results in success even though nothing's changed on my network in months.

                                        – Cerin
                                        Apr 18 '15 at 19:14






                                      • 1





                                        This is not quite true. While you can send your host name to DHCP server with send host-name "example.com"; in order to obtain a specific IP address, you can just as well request one with request host-name;.

                                        – Dmitry Grigoryev
                                        Nov 17 '15 at 10:33
















                                      I have dns and dhcp (windows 2008) server on my network. Ant it assigns hostname and dns name to each ip, but ubuntu does not update it's hostname and dns name. I should be able to see this assigned hostname by typing hostname and domain by typing hostname -d. so it's fqdn should be hostname.domain

                                      – Oguz Bilgic
                                      Feb 17 '12 at 1:31






                                      I have dns and dhcp (windows 2008) server on my network. Ant it assigns hostname and dns name to each ip, but ubuntu does not update it's hostname and dns name. I should be able to see this assigned hostname by typing hostname and domain by typing hostname -d. so it's fqdn should be hostname.domain

                                      – Oguz Bilgic
                                      Feb 17 '12 at 1:31














                                      AFAIR if the client is not joined to the Windows domain, the Windows DHCP server will not dynamically update the Windows DNS entries. I'm not really sure though... depends on the Windows DHCP/DNS configuration

                                      – oddfellow
                                      Feb 17 '12 at 20:54





                                      AFAIR if the client is not joined to the Windows domain, the Windows DHCP server will not dynamically update the Windows DNS entries. I'm not really sure though... depends on the Windows DHCP/DNS configuration

                                      – oddfellow
                                      Feb 17 '12 at 20:54













                                      By default 12.04 has this line "send host-name = gethostname();" and you can see that value by typing "hostname" on the command line. By default, this will not have any effect on a windows network. As per the original question.

                                      – Móż
                                      Nov 22 '13 at 3:09





                                      By default 12.04 has this line "send host-name = gethostname();" and you can see that value by typing "hostname" on the command line. By default, this will not have any effect on a windows network. As per the original question.

                                      – Móż
                                      Nov 22 '13 at 3:09













                                      Although zeroconf is installed by default, it's horribly unreliable. I'm frankly surprised when it works, as pinging hostname or hostname.local rarely results in success even though nothing's changed on my network in months.

                                      – Cerin
                                      Apr 18 '15 at 19:14





                                      Although zeroconf is installed by default, it's horribly unreliable. I'm frankly surprised when it works, as pinging hostname or hostname.local rarely results in success even though nothing's changed on my network in months.

                                      – Cerin
                                      Apr 18 '15 at 19:14




                                      1




                                      1





                                      This is not quite true. While you can send your host name to DHCP server with send host-name "example.com"; in order to obtain a specific IP address, you can just as well request one with request host-name;.

                                      – Dmitry Grigoryev
                                      Nov 17 '15 at 10:33





                                      This is not quite true. While you can send your host name to DHCP server with send host-name "example.com"; in order to obtain a specific IP address, you can just as well request one with request host-name;.

                                      – Dmitry Grigoryev
                                      Nov 17 '15 at 10:33











                                      1



















                                      If found that can be a dhcpclient scripts bug. http://blog.schlomo.schapiro.org/2013/11/setting-hostname-from-dhcp-in-debian.html



                                      Try to clean $old_host_name on ip renew




                                      echo unset old_host_name > /etc/dhcp/dhclient-enter-hooks.d/unset_old_hostname




                                      Also static /etc/hostname seems to has prority over dhcp answer so leave it empty




                                      > /etc/hostname




                                      Tested on ubuntu 14.04 and dnsmasq server.






                                      share|improve this answer































                                        1



















                                        If found that can be a dhcpclient scripts bug. http://blog.schlomo.schapiro.org/2013/11/setting-hostname-from-dhcp-in-debian.html



                                        Try to clean $old_host_name on ip renew




                                        echo unset old_host_name > /etc/dhcp/dhclient-enter-hooks.d/unset_old_hostname




                                        Also static /etc/hostname seems to has prority over dhcp answer so leave it empty




                                        > /etc/hostname




                                        Tested on ubuntu 14.04 and dnsmasq server.






                                        share|improve this answer





























                                          1















                                          1











                                          1









                                          If found that can be a dhcpclient scripts bug. http://blog.schlomo.schapiro.org/2013/11/setting-hostname-from-dhcp-in-debian.html



                                          Try to clean $old_host_name on ip renew




                                          echo unset old_host_name > /etc/dhcp/dhclient-enter-hooks.d/unset_old_hostname




                                          Also static /etc/hostname seems to has prority over dhcp answer so leave it empty




                                          > /etc/hostname




                                          Tested on ubuntu 14.04 and dnsmasq server.






                                          share|improve this answer
















                                          If found that can be a dhcpclient scripts bug. http://blog.schlomo.schapiro.org/2013/11/setting-hostname-from-dhcp-in-debian.html



                                          Try to clean $old_host_name on ip renew




                                          echo unset old_host_name > /etc/dhcp/dhclient-enter-hooks.d/unset_old_hostname




                                          Also static /etc/hostname seems to has prority over dhcp answer so leave it empty




                                          > /etc/hostname




                                          Tested on ubuntu 14.04 and dnsmasq server.







                                          share|improve this answer















                                          share|improve this answer




                                          share|improve this answer








                                          edited Apr 30 '15 at 23:06

























                                          answered Apr 30 '15 at 21:53









                                          AdamAdam

                                          112 bronze badges




                                          112 bronze badges
























                                              1



















                                              Note that when using Ubuntu 18.04 the tie-in scripts are no longer necessary. If the hostname of the install is set to localhost in /etc/hostname the DHCP client will set the hostname automatically at startup using the name issued by DHCP, if present. When running hostnamectl it will list localhost as the permanent hostname, and whatever DHCP issues as a transient hostname.



                                              testaccount@dhcp-hostname:~$ hostnamectl
                                              Static hostname: localhost
                                              Transient hostname: dhcp-hostname





                                              share|improve this answer





























                                                1



















                                                Note that when using Ubuntu 18.04 the tie-in scripts are no longer necessary. If the hostname of the install is set to localhost in /etc/hostname the DHCP client will set the hostname automatically at startup using the name issued by DHCP, if present. When running hostnamectl it will list localhost as the permanent hostname, and whatever DHCP issues as a transient hostname.



                                                testaccount@dhcp-hostname:~$ hostnamectl
                                                Static hostname: localhost
                                                Transient hostname: dhcp-hostname





                                                share|improve this answer



























                                                  1















                                                  1











                                                  1









                                                  Note that when using Ubuntu 18.04 the tie-in scripts are no longer necessary. If the hostname of the install is set to localhost in /etc/hostname the DHCP client will set the hostname automatically at startup using the name issued by DHCP, if present. When running hostnamectl it will list localhost as the permanent hostname, and whatever DHCP issues as a transient hostname.



                                                  testaccount@dhcp-hostname:~$ hostnamectl
                                                  Static hostname: localhost
                                                  Transient hostname: dhcp-hostname





                                                  share|improve this answer














                                                  Note that when using Ubuntu 18.04 the tie-in scripts are no longer necessary. If the hostname of the install is set to localhost in /etc/hostname the DHCP client will set the hostname automatically at startup using the name issued by DHCP, if present. When running hostnamectl it will list localhost as the permanent hostname, and whatever DHCP issues as a transient hostname.



                                                  testaccount@dhcp-hostname:~$ hostnamectl
                                                  Static hostname: localhost
                                                  Transient hostname: dhcp-hostname






                                                  share|improve this answer













                                                  share|improve this answer




                                                  share|improve this answer










                                                  answered Oct 1 at 0:46









                                                  Justin ScottJustin Scott

                                                  1431 silver badge6 bronze badges




                                                  1431 silver badge6 bronze badges
























                                                      0



















                                                      The answer depends on whether or not you are using static leases on your DHCP server. If you are, it is unnecessary to get the hostname from DNS. You can change this line in d_inevitable's solution



                                                      hostname=$(host $new_ip_address | cut -d ' ' -f 5)


                                                      to



                                                      hostname=$new_host_name


                                                      But this should happen automatically if your hostname is originally set to localhost.localdomain, so you don't have to write a script. However, if you want to set the hostname to the FQDN, you'll need to change d_inevitable's script to



                                                      hostname=$new_host_name.$new_domain_name


                                                      Again, all this only works if you're using static leases.






                                                      share|improve this answer































                                                        0



















                                                        The answer depends on whether or not you are using static leases on your DHCP server. If you are, it is unnecessary to get the hostname from DNS. You can change this line in d_inevitable's solution



                                                        hostname=$(host $new_ip_address | cut -d ' ' -f 5)


                                                        to



                                                        hostname=$new_host_name


                                                        But this should happen automatically if your hostname is originally set to localhost.localdomain, so you don't have to write a script. However, if you want to set the hostname to the FQDN, you'll need to change d_inevitable's script to



                                                        hostname=$new_host_name.$new_domain_name


                                                        Again, all this only works if you're using static leases.






                                                        share|improve this answer





























                                                          0















                                                          0











                                                          0









                                                          The answer depends on whether or not you are using static leases on your DHCP server. If you are, it is unnecessary to get the hostname from DNS. You can change this line in d_inevitable's solution



                                                          hostname=$(host $new_ip_address | cut -d ' ' -f 5)


                                                          to



                                                          hostname=$new_host_name


                                                          But this should happen automatically if your hostname is originally set to localhost.localdomain, so you don't have to write a script. However, if you want to set the hostname to the FQDN, you'll need to change d_inevitable's script to



                                                          hostname=$new_host_name.$new_domain_name


                                                          Again, all this only works if you're using static leases.






                                                          share|improve this answer
















                                                          The answer depends on whether or not you are using static leases on your DHCP server. If you are, it is unnecessary to get the hostname from DNS. You can change this line in d_inevitable's solution



                                                          hostname=$(host $new_ip_address | cut -d ' ' -f 5)


                                                          to



                                                          hostname=$new_host_name


                                                          But this should happen automatically if your hostname is originally set to localhost.localdomain, so you don't have to write a script. However, if you want to set the hostname to the FQDN, you'll need to change d_inevitable's script to



                                                          hostname=$new_host_name.$new_domain_name


                                                          Again, all this only works if you're using static leases.







                                                          share|improve this answer















                                                          share|improve this answer




                                                          share|improve this answer








                                                          edited Feb 16 '14 at 15:01









                                                          Eric Carvalho

                                                          45.1k18 gold badges122 silver badges153 bronze badges




                                                          45.1k18 gold badges122 silver badges153 bronze badges










                                                          answered Feb 16 '14 at 14:42









                                                          user248850user248850

                                                          11 bronze badge




                                                          11 bronze badge
























                                                              0



















                                                              Don't have enough reputation to comment, but I'd like to piggy-back on the previous answer as it almost solved the problem for me using a dhclient hook.



                                                              I've found that using the standard ISC DHCP Server for some reason, the aforementioned hook outputs a host name with a '.' period character at the end of the hostname for some reason.



                                                              So, in the previous answer you might need "cut out" the extraneous period with a sed:



                                                              hostname=$(host $new_ip_address | cut -d ' ' -f 5)


                                                              Would become:



                                                              hostname=$(host $new_ip_address | cut -d ' ' -f 5 | sed -e "s/.$//g")





                                                              share|improve this answer































                                                                0



















                                                                Don't have enough reputation to comment, but I'd like to piggy-back on the previous answer as it almost solved the problem for me using a dhclient hook.



                                                                I've found that using the standard ISC DHCP Server for some reason, the aforementioned hook outputs a host name with a '.' period character at the end of the hostname for some reason.



                                                                So, in the previous answer you might need "cut out" the extraneous period with a sed:



                                                                hostname=$(host $new_ip_address | cut -d ' ' -f 5)


                                                                Would become:



                                                                hostname=$(host $new_ip_address | cut -d ' ' -f 5 | sed -e "s/.$//g")





                                                                share|improve this answer





























                                                                  0















                                                                  0











                                                                  0









                                                                  Don't have enough reputation to comment, but I'd like to piggy-back on the previous answer as it almost solved the problem for me using a dhclient hook.



                                                                  I've found that using the standard ISC DHCP Server for some reason, the aforementioned hook outputs a host name with a '.' period character at the end of the hostname for some reason.



                                                                  So, in the previous answer you might need "cut out" the extraneous period with a sed:



                                                                  hostname=$(host $new_ip_address | cut -d ' ' -f 5)


                                                                  Would become:



                                                                  hostname=$(host $new_ip_address | cut -d ' ' -f 5 | sed -e "s/.$//g")





                                                                  share|improve this answer
















                                                                  Don't have enough reputation to comment, but I'd like to piggy-back on the previous answer as it almost solved the problem for me using a dhclient hook.



                                                                  I've found that using the standard ISC DHCP Server for some reason, the aforementioned hook outputs a host name with a '.' period character at the end of the hostname for some reason.



                                                                  So, in the previous answer you might need "cut out" the extraneous period with a sed:



                                                                  hostname=$(host $new_ip_address | cut -d ' ' -f 5)


                                                                  Would become:



                                                                  hostname=$(host $new_ip_address | cut -d ' ' -f 5 | sed -e "s/.$//g")






                                                                  share|improve this answer















                                                                  share|improve this answer




                                                                  share|improve this answer








                                                                  edited Feb 16 '14 at 15:01









                                                                  Eric Carvalho

                                                                  45.1k18 gold badges122 silver badges153 bronze badges




                                                                  45.1k18 gold badges122 silver badges153 bronze badges










                                                                  answered Jan 4 '14 at 7:25









                                                                  Michael R. HinesMichael R. Hines

                                                                  3812 silver badges4 bronze badges




                                                                  3812 silver badges4 bronze badges































                                                                      draft saved

                                                                      draft discarded















































                                                                      Thanks for contributing an answer to Ask Ubuntu!


                                                                      • Please be sure to answer the question. Provide details and share your research!

                                                                      But avoid


                                                                      • Asking for help, clarification, or responding to other answers.

                                                                      • Making statements based on opinion; back them up with references or personal experience.

                                                                      To learn more, see our tips on writing great answers.




                                                                      draft saved


                                                                      draft discarded














                                                                      StackExchange.ready(
                                                                      function ()
                                                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f104918%2fhow-to-get-the-hostname-from-a-dhcp-server%23new-answer', 'question_page');

                                                                      );

                                                                      Post as a guest















                                                                      Required, but never shown





















































                                                                      Required, but never shown














                                                                      Required, but never shown












                                                                      Required, but never shown







                                                                      Required, but never shown

































                                                                      Required, but never shown














                                                                      Required, but never shown












                                                                      Required, but never shown







                                                                      Required, but never shown









                                                                      Popular posts from this blog

                                                                      Tamil (spriik) Luke uk diar | Nawigatjuun

                                                                      Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

                                                                      Where does the image of a data connector as a sharp metal spike originate from?Where does the concept of infected people turning into zombies only after death originate from?Where does the motif of a reanimated human head originate?Where did the notion that Dragons could speak originate?Where does the archetypal image of the 'Grey' alien come from?Where did the suffix '-Man' originate?Where does the notion of being injured or killed by an illusion originate?Where did the term “sophont” originate?Where does the trope of magic spells being driven by advanced technology originate from?Where did the term “the living impaired” originate?