<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akshay Moghe</title>
    <description>The latest articles on DEV Community by Akshay Moghe (@amoghe).</description>
    <link>https://dev.to/amoghe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F133650%2F7be7e8f1-6d58-4115-ae0b-74f462f6a894.jpeg</url>
      <title>DEV Community: Akshay Moghe</title>
      <link>https://dev.to/amoghe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amoghe"/>
    <language>en</language>
    <item>
      <title>Default route not set on Ubuntu VM in Azure (via DHCP)</title>
      <dc:creator>Akshay Moghe</dc:creator>
      <pubDate>Sat, 02 Feb 2019 02:01:52 +0000</pubDate>
      <link>https://dev.to/amoghe/default-route-not-set-on-ubuntu-vm-in-azure-via-dhcp-4bg5</link>
      <guid>https://dev.to/amoghe/default-route-not-set-on-ubuntu-vm-in-azure-via-dhcp-4bg5</guid>
      <description>&lt;h2&gt;
  
  
  Misadventures in bringing up the same Ubuntu image on different hypervisors
&lt;/h2&gt;

&lt;p&gt;I recently stumbled upon a couple of rather nasty issues when bringing up a server on a variety of hypervisors (and cloud IaaS). Now, admittedly, I was doing something "not normal" - i.e - trying to bring up a VM that was a replica of one that had worked on VMWare ESX (using a &lt;code&gt;dd&lt;/code&gt; copy of the disk) on other platforms. What struck me was that the VM would:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;boot up normally on VMWare (obviously), networking configured via DHCP&lt;/li&gt;
&lt;li&gt;boot up normally on AWS, networking configured, instance was SSH'able&lt;/li&gt;
&lt;li&gt;boot up normally on Azure, but would not get any default routes, so &lt;em&gt;no SSH&lt;/em&gt;!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After some poking around, I learnt a couple of lessons&lt;/p&gt;

&lt;h2&gt;
  
  
  1. &lt;code&gt;dhclient&lt;/code&gt; has multiple ways in which it will set a default route
&lt;/h2&gt;

&lt;p&gt;These are based off the response from the DHCP server. Now,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;some DHCP servers return &lt;code&gt;Classless Static Routes&lt;/code&gt; option&lt;/li&gt;
&lt;li&gt;some DHCP servers return &lt;code&gt;Router&lt;/code&gt; option&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After a lot of debugging (which is excruciatingly painful, since the only real "debug tool" available for these issues is using the &lt;code&gt;debug&lt;/code&gt; script in &lt;code&gt;/etc/dhcp/dhclient-exit-hooks&lt;/code&gt;) I figured out that one environment worked fine because it was using the &lt;code&gt;Router&lt;/code&gt; option whereas on Azure the DHCP server sends back the &lt;code&gt;Classless Static Routes&lt;/code&gt; option.&lt;/p&gt;

&lt;p&gt;And dhclient prefers the &lt;code&gt;Classless Static Routes&lt;/code&gt; option (see &lt;a href="https://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg1363827.html"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On VMWare, and on AWS the DHCP server actually uses the &lt;code&gt;Router&lt;/code&gt; option, which is why it worked fine across those 2 environments.&lt;/p&gt;

&lt;p&gt;Okay, so that solves one mystery - but given that dhclient should know how to handle both options - why wasn't it working for my VM on Azure?&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;code&gt;dhclient-exit-hook&lt;/code&gt; scripts are sourced
&lt;/h2&gt;

&lt;p&gt;On further investigation, it turned out that one of my dhclient-exit-hook scripts was doing the "wrong thing" and terminating early due to a misplaced &lt;code&gt;exit 0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It is not clearly mentioned anywhere (neither man-pages, nor on the interwebz) that the dhclient-exit-hook scripts are actually sourced rather than executed.&lt;/p&gt;

&lt;p&gt;It turned out that one of my custom scripts was "exiting" the execution, thus causing some of the remaining scripts to not run. Most notably, there is a default script on Ubuntu that deals with the &lt;code&gt;Classless Static Routes&lt;/code&gt; option (called &lt;code&gt;rfc3442-classless-routes&lt;/code&gt;) that actually handles this correctly. However since the scripts are sourced in lexicographical order, this script would never run because of my aforementioned problem.&lt;/p&gt;

&lt;p&gt;One last thing of note - this &lt;a href="https://serverfault.com/questions/780604/dhclient-doesnt-set-default-gateway/780739#780739"&gt;post&lt;/a&gt; on StackExchange was immensely helpful in me finding the root cause of my problems.&lt;/p&gt;

</description>
      <category>dhcp</category>
      <category>linux</category>
      <category>networking</category>
      <category>azure</category>
    </item>
  </channel>
</rss>
