{"id":4177,"date":"2012-07-25T09:24:42","date_gmt":"2012-07-25T07:24:42","guid":{"rendered":"https:\/\/ingmarverheij.com\/?p=4177"},"modified":"2012-07-25T09:37:55","modified_gmt":"2012-07-25T07:37:55","slug":"configure-hostname-via-dhcp","status":"publish","type":"post","link":"https:\/\/ingmarverheij.com\/en\/configure-hostname-via-dhcp\/","title":{"rendered":"Configure hostname via DHCP"},"content":{"rendered":"<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/Windows-8-Hostname.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Windows 8 - Hostname\" border=\"0\" alt=\"Windows 8 - Hostname\" align=\"left\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/Windows-8-Hostname_thumb.png\" width=\"118\" height=\"92\" \/><\/a>A system can be identified on a network with a <a href=\"https:\/\/en.wikipedia.org\/wiki\/MAC_address\" target=\"_blank\">MAC address<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/IP_address\" target=\"_blank\">IP address<\/a> or its <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hostname\" target=\"_blank\">hostname<\/a>. The hostname is the most readable form for humans, especially because you have the ability to change the hostname (unlike a MAC address and only partially for an IP address).<\/p>\n<p>Giving the device a human readable hostname makes it easier to troubleshoot issues and is sometimes required to to apply to a naming convention. Having an asset tag on the device makes it easier for a user to explain what device he\/she is using.<\/p>\n<p>But what if you\u2019re unable to change the hostname of a device or don\u2019t want to specify this for each device? Think of thin clients (or zero clients) like a <a href=\"https:\/\/ingmarverheij.com\/en\/2012\/07\/hp-smart-zero-client-a-first-impression\/\" target=\"_blank\">HP Smart Zero Client<\/a> where you can\u2019t (or want) to configure the hostname per device. <\/p>\n<p>Well, you can push the hostname via the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dhcp\" target=\"_blank\">Dynamic Host Configuration Protocol (DHCP)<\/a>.<\/p>\n<p><!--more--><\/p>\n<h2>DHCP<\/h2>\n<p>A client can be configured with static or dynamic IP configuration, by default all systems are configured with a dynamic configuration. This means that a client requests an IP configuration from a server on the network, the DHCP server. DHCP works basically works in three phases:<\/p>\n<ol>\n<li>Initialization <\/li>\n<li>Renewing <\/li>\n<li>Rebinding <\/li>\n<\/ol>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/dhcp.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 0px 0px 5px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" align=\"right\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/dhcp_thumb.jpg\" width=\"154\" height=\"111\" \/><\/a>During the startup process of a system (or actually the network stack) there is no IP configuration and therefore it needs to initialize. During this phase (at least) 4 packets are broadcasted,<\/p>\n<p>After receiving (and confirming) an IP configuration, a DHCP lease, a timer monitors when the half of the lease time T1 (typical lease time is 8 hours, so T1 is 4 hours) is expired. A unicast is sent to the DHCP server to renew the configuration. If the renewing phase fails (for what ever reason) the same request is sent as a broadcast the Rebinding phase). After the lease expires the whole process starts from the Initialization phase.<\/p>\n<p><strong><\/strong><\/p>\n<p><strong>DHCP options<\/strong><\/p>\n<p>Besides offering an IP address the DHCPOFFER packet contains a list op DHCP options. The most common used are:<\/p>\n<p>&#160;&#160;&#160;&#160; 001 \u2013 Subnet Mask<\/p>\n<p>&#160;&#160;&#160;&#160; 003 \u2013 Router<\/p>\n<p>&#160;&#160;&#160;&#160; 006 \u2013 Domain Name Server<\/p>\n<p>&#160;&#160;&#160;&#160; 015 \u2013 Domain Name<\/p>\n<p>With <a href=\"https:\/\/www.networksorcery.com\/enp\/protocol\/bootp\/option012.htm\" target=\"_blank\">BOOTP \/ DHCP option 012<\/a> a host name can be supplied, but only if the client requests a hostname.<\/p>\n<p>&#160;<\/p>\n<h2><\/h2>\n<h2>Server configuration<\/h2>\n<p>On the DHCP server you need to specify what name (hostname) you need to give to what device (MAC address), this is done with a reservation. You need to create a reserveration for <em>each <\/em>device and therefore you need to know the MAC address of all of those device.<\/p>\n<h4>&#160;<\/h4>\n<h4>Linux<\/h4>\n<p>If your using a linux server as your DHCP server you\u2019re probable using <a href=\"https:\/\/linux.die.net\/man\/8\/dhcpd\"><em>dhcpd<\/em><\/a><em> (DHCP daemon)<\/em>. You can add a reservation with the following lines in <a href=\"https:\/\/linux.die.net\/man\/5\/dhcpd.conf\" target=\"_blank\">dhcpd.conf<\/a><strong>.<\/strong><\/p>\n<pre lang=\"bash\">host LAPTOP_IV { \n   hardware ethernet 60:6B:BD:0B:67:3F; \n   fixed-address 192.168.0.101;\n   option host-name &quot;LAPTOP_IV&quot;;\n}\n\nhost THN-WG-2012 { \n   hardware ethernet 9C:8E:99:E7:1A:B8; \n   fixed-address 192.168.0.102;\n   option host-name &quot;THN-WG-2012&quot;;\n}<\/pre>\n<p><strong><\/strong><\/p>\n<p><strong><\/strong><\/p>\n<h4>&#160;<\/h4>\n<h4>Windows<\/h4>\n<p>The following procedure explains how to add a reservation for a device and specify a hostname in a Windows 2008 R2 Server.<\/p>\n<ol>\n<li>In the left pane, select the <strong>Address Leases <\/strong>in the scope where the device has a DHCP lease<\/li>\n<li>Right-click the <strong>DHCP lease<\/strong>, and then select <strong>Add to Reservation<br \/>\n      <br clear=\"all\" \/><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/Microsoft-DHCP-1.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/Microsoft-DHCP-1_thumb.png\" width=\"154\" height=\"25\" \/><\/a><\/strong><\/li>\n<li>In the left pane, select the <strong>Reservations<\/strong> in the scope where the device has a DHCP lease<a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/Microsoft-DHCP-2.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/Microsoft-DHCP-2_thumb.png\" width=\"154\" height=\"74\" \/><\/a><\/li>\n<li>Right-click the <strong>Reservations<\/strong>, and then click <strong>Configure Options<br \/>\n      <br clear=\"all\" \/><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/Microsoft-DHCP-3.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/Microsoft-DHCP-3_thumb.png\" width=\"154\" height=\"54\" \/><\/a><\/strong><\/li>\n<li>Select option <strong>012 Host Name<\/strong> and enter the name of the device in the <strong>Data entry<\/strong> field\n<p>    <br clear=\"all\" \/><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/Microsoft-DHCP-4.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/Microsoft-DHCP-4_thumb.png\" width=\"154\" height=\"171\" \/><\/a><\/li>\n<li>Verify the information is correct and click <strong>OK<br \/>\n      <br clear=\"all\" \/><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/Microsoft-DHCP-5.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/Microsoft-DHCP-5_thumb.png\" width=\"154\" height=\"46\" \/><\/a><\/strong><\/li>\n<\/ol>\n<p>\n  <br clear=\"all\" \/><\/p>\n<h2>Client configuration<\/h2>\n<h4>Linux <\/h4>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/032.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 0px 0px 5px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" align=\"right\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/032_thumb.jpg\" width=\"154\" height=\"22\" \/><\/a>On a a device with a Linux operating system the <a href=\"https:\/\/linux.die.net\/man\/8\/dhclient\" target=\"_blank\">dhclient<\/a>&#160; provides a means for configuring network interfaces using DHCP (or BOOTP). The configuration is <a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/033.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; margin: 0px 0px 0px 5px; padding-left: 0px; padding-right: 0px; display: inline; float: right; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" align=\"right\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/033_thumb.jpg\" width=\"154\" height=\"104\" \/><\/a>stored in the dhclient.conf file (which can be found in <strong>\/etc\/dhcp<\/strong>). <\/p>\n<p>In this configuration file you can specify which DHCP options the client should request (and honor) with the DHCPREQUEST packet. One of the options you can specify is:<\/p>\n<pre>request host-name<\/pre>\n<h4>&#160;<\/h4>\n<h4>Windows <\/h4>\n<p>Unfortunately Microsoft has not implemented DHCP option 012 (Host Name) in the DHCP client.<\/p>\n<ul>\n<li><a href=\"https:\/\/support.microsoft.com\/kb\/121005\/en-us\" target=\"_blank\">KB121005 \u2013 DHCP Options Supported by Clients<\/a><\/li>\n<li><a href=\"https:\/\/www.pcreview.co.uk\/forums\/dhcp-client-service-option-12-a-t3465363.html\" target=\"_blank\">PCreview &#8211; DHCP client service with option 12<\/a><\/li>\n<\/ul>\n<p>I\u2019d like to be proven <strong>wrong<\/strong>, so if you know how to configure the Windows DHCP client to receive a host name let me know in the <strong>comments<\/strong>.<\/p>\n<p>&#160;<\/p>\n<h2>Result<\/h2>\n<p>In this example a <a href=\"https:\/\/ingmarverheij.com\/en\/2012\/07\/hp-smart-zero-client-a-first-impression\/\" target=\"_blank\">HP t510<\/a> thin client with MAC address 9C:8E:99:E7:1A:B8 got a default hostname of HP9c8e99e71ab8. If all is configured well the device requests the hostname from the DHCP server, resulting in the hostname THN-WG-2012.<\/p>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/HP-t510-Before.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/HP-t510-Before_thumb.jpg\" width=\"254\" height=\"176\" \/><\/a>&#160; &gt;&#160;&#160; &gt;&#160;&#160; &gt;&#160;&#160; &gt;&#160;&#160; <a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/HP-t510-After.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px\" title=\"\" border=\"0\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/07\/HP-t510-After_thumb.jpg\" width=\"254\" height=\"180\" \/><\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>A system can be identified on a network with a MAC address, IP address or its hostname. The hostname is the most readable form for humans, especially because you have the ability to change the hostname (unlike a MAC address and only partially for an IP address). Giving the device a human readable hostname makes [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[288],"tags":[355,490,489],"class_list":["post-4177","post","type-post","status-publish","format-standard","hentry","category-other","tag-dhcp","tag-dhcpd","tag-hostname"],"_links":{"self":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/4177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/comments?post=4177"}],"version-history":[{"count":5,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/4177\/revisions"}],"predecessor-version":[{"id":4186,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/4177\/revisions\/4186"}],"wp:attachment":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/media?parent=4177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/categories?post=4177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/tags?post=4177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}