<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    
    <title>Raymond P. Burkholder - Things I Do - Vagrant</title>
    <link>http://blog.raymond.burkholder.net/</link>
    <description>In And Around Technology and The Arts</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.7.2 - http://www.s9y.org/</generator>
    <pubDate>Sun, 11 Dec 2016 23:48:03 GMT</pubDate>

    <image>
        <url>http://blog.raymond.burkholder.net/templates/bulletproof/img/s9y_banner_small.png</url>
        <title>RSS: Raymond P. Burkholder - Things I Do - Vagrant - In And Around Technology and The Arts</title>
        <link>http://blog.raymond.burkholder.net/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>VirtualBox/Vagrant Test Environment for Dustin Spinhirne's OVN Tutorial</title>
    <link>http://blog.raymond.burkholder.net/index.php?/archives/701-VirtualBoxVagrant-Test-Environment-for-Dustin-Spinhirnes-OVN-Tutorial.html</link>
            <category>Vagrant</category>
    
    <comments>http://blog.raymond.burkholder.net/index.php?/archives/701-VirtualBoxVagrant-Test-Environment-for-Dustin-Spinhirnes-OVN-Tutorial.html#comments</comments>
    <wfw:comment>http://blog.raymond.burkholder.net/wfwcomment.php?cid=701</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.raymond.burkholder.net/rss.php?version=2.0&amp;type=comments&amp;cid=701</wfw:commentRss>
    

    <author>nospam@example.com (Raymond P. Burkholder)</author>
    <content:encoded>
    &lt;p&gt;&lt;a href=&quot;http://blog.spinhirne.com/p/blog-series.html&quot; target=_blank&gt;
Dustin Spinhirne&#039;s OVN tutorial&lt;/a&gt; was recently mentioned on the OVS mailing list.  His examples use a single host in an ESXi environment with virtual hosts simulated through namespace commands.

&lt;p&gt;As an excuse to try out Vagrant automation skills, I created a Vagrant multi-host test environment running in VirtualBox.  Interfaces are automatically created, ip addresses automatically assigned, and guests can have readable names.  Previous articles here explain how I built a recent custom kernel and how I built the latest version of OVS/OVN.  The resulting kernel and packages are used to spool up this Vagrant/VirtualBox test environment for playing with OVN.

&lt;p&gt;&lt;a href=&quot;https://github.com/rburkholder/vagrant&quot; target=_blank&gt;OVS/OVN Vagrant on GitHub&lt;/a&gt; is an environment I have for building with current kernels, generating current OVS/OVN packages, and using them in an OVN Lab type environment.



 &lt;br /&gt;&lt;a href=&quot;http://blog.raymond.burkholder.net/index.php?/archives/701-VirtualBoxVagrant-Test-Environment-for-Dustin-Spinhirnes-OVN-Tutorial.html#extended&quot;&gt;Continue reading &quot;VirtualBox/Vagrant Test Environment for Dustin Spinhirne&#039;s OVN Tutorial&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Wed, 02 Nov 2016 16:57:54 +0000</pubDate>
    <guid isPermaLink="false">http://blog.raymond.burkholder.net/index.php?/archives/701-guid.html</guid>
    
</item>
<item>
    <title>Multiple Provisioners in Vagrant</title>
    <link>http://blog.raymond.burkholder.net/index.php?/archives/699-Multiple-Provisioners-in-Vagrant.html</link>
            <category>Vagrant</category>
    
    <comments>http://blog.raymond.burkholder.net/index.php?/archives/699-Multiple-Provisioners-in-Vagrant.html#comments</comments>
    <wfw:comment>http://blog.raymond.burkholder.net/wfwcomment.php?cid=699</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.raymond.burkholder.net/rss.php?version=2.0&amp;type=comments&amp;cid=699</wfw:commentRss>
    

    <author>nospam@example.com (Raymond P. Burkholder)</author>
    <content:encoded>
    &lt;p&gt;A little bit more automation:  with each new kernel version that comes out, I need to update my base Vagrant image, and as a result, update the VirtualBox Guest Additions as well.

&lt;p&gt;Here is my Vagrantfile to control the process.  The VM is started three times, of which only two are really necessary (the first two).  These are the steps:

 &lt;br /&gt;&lt;a href=&quot;http://blog.raymond.burkholder.net/index.php?/archives/699-Multiple-Provisioners-in-Vagrant.html#extended&quot;&gt;Continue reading &quot;Multiple Provisioners in Vagrant&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Tue, 01 Nov 2016 21:52:43 +0000</pubDate>
    <guid isPermaLink="false">http://blog.raymond.burkholder.net/index.php?/archives/699-guid.html</guid>
    
</item>
<item>
    <title>Building a Network with Vagrant</title>
    <link>http://blog.raymond.burkholder.net/index.php?/archives/686-Building-a-Network-with-Vagrant.html</link>
            <category>Vagrant</category>
    
    <comments>http://blog.raymond.burkholder.net/index.php?/archives/686-Building-a-Network-with-Vagrant.html#comments</comments>
    <wfw:comment>http://blog.raymond.burkholder.net/wfwcomment.php?cid=686</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.raymond.burkholder.net/rss.php?version=2.0&amp;type=comments&amp;cid=686</wfw:commentRss>
    

    <author>nospam@example.com (Raymond P. Burkholder)</author>
    <content:encoded>
    &lt;p&gt;Having gone through the exercise of getting Vagrant to build machines with multiple interfaces consistently, I am now ready for the next step.

&lt;p&gt;The next step is being able create multiple interconnected machines.  I tested the basic configuration of two machines in a previous blog entry.  I could continue on with manually defining machines and their relationships, which becomes a lot of manual editing and book-keeping.  

&lt;p&gt;Instead, I wanted to be able to see if it could be done with some simple lists and some code.  So... having not programmed in Ruby before (upon which Vagrant relies), I picked up the third edition of &#039;Beginning Ruby&#039;, took a read through, figured out the basics of the language, and was able to successfully program an auto-build configuration.

&lt;p&gt;Two sets of definitions are required.  A machine list, and a list of connections between each machine.  My test example:

&lt;blockquote&gt;&lt;pre&gt;
# a list of machines to create within VirtualBox
machineNames = [&#039;edge01&#039;,&#039;edge02&#039;,&#039;core01&#039;,&#039;core02&#039;,&#039;host01&#039;]

# a list of connections to be made between machines
#   this example makes use of a series of point to point links
vlans = [
  [&#039;edge01&#039;,&#039;core01&#039;],[&#039;edge01&#039;,&#039;core02&#039;],
  [&#039;edge02&#039;,&#039;core01&#039;],[&#039;edge02&#039;,&#039;core02&#039;],
  [&#039;core01&#039;,&#039;core02&#039;],
  [&#039;host01&#039;,&#039;core01&#039;],[&#039;host01&#039;,&#039;core02&#039;]
  ]
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;In the example, there are a number of links, and each link is defined by identifying the machines taking part.  For example, one link contains edge01 and core01.  This link will have an ip subnet automatically assigned and will have a unique VirtualBox internal network.

&lt;p&gt;By changing the machineNames list and the vlans list, a network of desired topology will be provisioned enabled with the &#039;vagrant up&#039; command.

&lt;p&gt;Here is the full Vagrantfile listing for the example:

&lt;pre&gt;&lt;blockquote&gt;
# -*- mode: ruby -*-
# vi: set ft=ruby :

require &#039;ipaddr&#039;

# a list of machines to create within VirtualBox
machineNames = [&#039;edge01&#039;,&#039;edge02&#039;,&#039;core01&#039;,&#039;core02&#039;,&#039;host01&#039;]

# a list of connections to be made between machines
#   this example makes use of a series of point to point links
vlans = [
  [&#039;edge01&#039;,&#039;core01&#039;],[&#039;edge01&#039;,&#039;core02&#039;],
  [&#039;edge02&#039;,&#039;core01&#039;],[&#039;edge02&#039;,&#039;core02&#039;],
  [&#039;core01&#039;,&#039;core02&#039;],
  [&#039;host01&#039;,&#039;core01&#039;],[&#039;host01&#039;,&#039;core02&#039;]
  ]

# track the vlans to be used on each machine
class Machine
  attr_accessor :name, :interfaces
  def initialize(name)
    @name = name
    @interfaces = []
  end
end

# create each machine with an empty set of interfaces
machines = {}
machineNames.each do |name|
  puts &#039;machine name exists: #{name}, over-writing&#039; if machines.has_key?(name)
  machines[name] = Machine.new( name )
end

# the subnet isn&#039;t used at the moment, but the class does provide a sequence of addresses
class IPAddressing
  attr_accessor :subnet
  def initialize(subnet)
    @subnet = subnet
    @nextAddress = subnet.succ  # don&#039;t use .1 as Vagrant emits warning messages
  end
  def next
    @nextAddress = @nextAddress.succ
  end
end

# assign vlan names and ip address ranges for each connection
ipAddresses = {}

ixNet = 101 #provide each link with a unique number
vlans.each do |vlan|
  net = &quot;vlan#{ixNet}&quot;
  ipAddresses[net] = IPAddressing.new( IPAddr.new &quot;10.0.#{ixNet}.0/24&quot; )
  vlan.each do |endPoint|
    if machines.has_key?(endPoint)
      machines[endPoint].interfaces &lt;&lt; net
    else
      puts &quot;endPoint #{endPoint} doesn&#039;t exist&quot; if !machines.has_key?(endPoint)
    end
  end
  ixNet += 1
end

# generate connectivity information
maxConnections = 0
machines.values.each do |machine|
  maxConnections = (maxConnections &gt; machine.interfaces.length) ? maxConnections : machine.interfaces.length
  out = &quot;#{machine.name}: &quot;
  out += machine.interfaces.join(&#039;, &#039;)
  puts out
end

puts &quot;maxConnections: #{maxConnections}&quot;

Vagrant.configure(&quot;2&quot;) do |config|

  config.vm.box = &quot;stretch&quot;

  config.vm.box_url = &quot;file://boxes/stretch.box&quot;

  # ensure all connections are virtio
  config.vm.provider &quot;virtualbox&quot; do |v|

    cnt = 1; while ( cnt &lt;= (maxConnections + 1) ) # the extra one is for the NAT interface
      v.customize [&quot;modifyvm&quot;, :id, &quot;--nictype#{cnt}&quot;, &quot;virtio&quot;]
      cnt += 1
    end
  end

  # provision the machines, NAT is automatically provisioned, and is not listed
  machines.values.each do |machine|
    config.vm.define machine.name do |instance|
      instance.vm.hostname = machine.name
      machine.interfaces.each do |interface|
        ipAddress = ipAddresses[interface].next.to_string
        instance.vm.network :private_network, virtualbox__intnet: interface, ip: ipAddress
        puts &quot;#{machine.name}: #{interface} = #{ipAddress}&quot;
      end
    end
  end

end
&lt;/blockquote&gt;&lt;/pre&gt;

&lt;p&gt;Here is the initial part of the output during &#039;vagrant up&#039;:

&lt;pre&gt;&lt;blockquote&gt;
$ vagrant up
edge01: vlan101, vlan102
edge02: vlan103, vlan104
core01: vlan101, vlan103, vlan105, vlan106
core02: vlan102, vlan104, vlan105, vlan107
host01: vlan106, vlan107
maxConnections: 4
edge01: vlan101 = 10.0.101.2
edge01: vlan102 = 10.0.102.2
edge02: vlan103 = 10.0.103.2
edge02: vlan104 = 10.0.104.2
core01: vlan101 = 10.0.101.3
core01: vlan103 = 10.0.103.3
core01: vlan105 = 10.0.105.2
core01: vlan106 = 10.0.106.2
core02: vlan102 = 10.0.102.3
core02: vlan104 = 10.0.104.3
core02: vlan105 = 10.0.105.3
core02: vlan107 = 10.0.107.2
host01: vlan106 = 10.0.106.3
host01: vlan107 = 10.0.107.3
Bringing machine &#039;edge01&#039; up with &#039;virtualbox&#039; provider...
Bringing machine &#039;edge02&#039; up with &#039;virtualbox&#039; provider...
Bringing machine &#039;core01&#039; up with &#039;virtualbox&#039; provider...
Bringing machine &#039;core02&#039; up with &#039;virtualbox&#039; provider...
Bringing machine &#039;host01&#039; up with &#039;virtualbox&#039; provider...
... more stuff follows as the machines are built ....
&lt;/blockquote&gt;&lt;/pre&gt; 
    </content:encoded>

    <pubDate>Thu, 13 Oct 2016 23:56:42 +0000</pubDate>
    <guid isPermaLink="false">http://blog.raymond.burkholder.net/index.php?/archives/686-guid.html</guid>
    
</item>
<item>
    <title>Vagrant Summary</title>
    <link>http://blog.raymond.burkholder.net/index.php?/archives/685-Vagrant-Summary.html</link>
            <category>Vagrant</category>
    
    <comments>http://blog.raymond.burkholder.net/index.php?/archives/685-Vagrant-Summary.html#comments</comments>
    <wfw:comment>http://blog.raymond.burkholder.net/wfwcomment.php?cid=685</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.raymond.burkholder.net/rss.php?version=2.0&amp;type=comments&amp;cid=685</wfw:commentRss>
    

    <author>nospam@example.com (Raymond P. Burkholder)</author>
    <content:encoded>
    &lt;p&gt;After having gone through the basics of a Vagrant install, with more to do yet, I need to record some of the commands I used to get things going.

&lt;p&gt;This solution is based upon using Debian Stretch/Testing as the &#039;box&#039;.  Which I build in a minimal configuration.  I create a &#039;vagrant&#039; user during the build process.  Also ensure that the first network card is of type &#039;Paravirtualized Network (virtio-net)&#039; when being built under VirtualBox.

&lt;p&gt;Once built, and rebooted, login as &#039;vagrant&#039;:

&lt;blockquote&gt;&lt;pre&gt;
mkdir /home/vagrant/.ssh
chmod 700 /home/vagrant/.ssh
pushd /home/vagrant/.ssh
wget --no-check-certificate \
  &#039;https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub&#039; \
  -O authorized_keys
chmod 600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant /home/vagrant/.ssh
popd
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;In order to clear the way for vagrant automation, create the following file, as root (sudo doesn&#039;t appear to work):

&lt;blockquote&gt;&lt;pre&gt;
cat &amp;lt;&amp;lt;EOT &amp;gt;&amp;gt; /etc/sudoers.d/10-sudo-overrides
Defaults      env_keep += &quot;GIT_*&quot;
Defaults&gt;root env_keep += SSH_AUTH_SOCK
Defaults&gt;root !requiretty
%sudo         ALL=NOPASSWD: ALL
EOT

&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;VirtualBox extensions are required.  They can be installed in one of two ways.  The first is by using the gui to mount the cd and then run:

&lt;blockquote&gt;&lt;pre&gt;
apt-get install linux-headers-$(uname -r) build-essential
# attach guest extensions
mount /dev/cdrom /media/cdrom
KERN_DIR=/usr/src/linux-headers-$(uname -r)/ \
  sh /media/cdrom/VBoxLinuxAdditions.runsh /media/cdrom/VBoxLinuxAdditions.run
umount /media/cdrom
apt-get remove binutils build-essential bzip2 cpp cpp-5 cpp-6 dpkg-dev fakeroot \
   g++ g++-6 gcc gcc-5 gcc-6 libalgorithm-diff-perl libalgorithm-diff-xs-perl \
  libalgorithm-merge-perl libasan2 libasan3 libatomic1 libc-dev-bin libc6-dev \
  libcc1-0 libcilkrts5 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-5-dev \
  libgcc-6-dev libgomp1 libisl15 libitm1 liblsan0 libmpc3 libmpfr4 libmpx0 libmpx2 \
  libperl5.24 libquadmath0 libstdc++-6-dev libtsan0 libubsan0 \
  linux-compiler-gcc-5-x86 linux-headers-4.7.0-1-amd64 \
  linux-headers-4.7.0-1-common linux-kbuild-4.7 \
  linux-libc-dev make manpages manpages-dev patch perl
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;The other way, courtesy of &lt;a href=&quot;https://www.vagrantup.com/docs/virtualbox/boxes.html&quot; target=_blank&gt;Creating a Base Box&lt;/a&gt; (and substituting the correct iso version):

&lt;blockquote&gt;&lt;pre&gt;
wget http://download.virtualbox.org/virtualbox/4.3.8/VBoxGuestAdditions_4.3.8.iso
sudo mkdir /media/VBoxGuestAdditions
sudo mount -o loop,ro VBoxGuestAdditions_4.3.8.iso /media/VBoxGuestAdditions
sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run
rm VBoxGuestAdditions_4.3.8.iso
sudo umount /media/VBoxGuestAdditions
sudo rmdir /media/VBoxGuestAdditions
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;Minimize the resulting box by removing packages and zeroing out unused space:

&lt;blockquote&gt;&lt;pre&gt;
apt-get autoremove
apt-get purge
apt-get clean

dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;Shutdown the template.  Remove the boot cd if one is attached.  Ensure the first network port is of type NAT.

&lt;p&gt;Inside a vagrant project directory, I create a template file, it has a default config, but if I need to diddle adjustments later, it is available:

&lt;blockquote&gt;&lt;pre&gt;
# stretch.vf:
Vagrant::Config.run do |config|
  config.ssh.username = &quot;vagrant&quot;
end
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;I create a package, a place it in place I can reach it.  It is local, but could be put in a remote repository if desired.

&lt;pre&gt;&lt;blockquote&gt;
vagrant package --base stretch --vagrantfile stretch.vf
mkdir boxes
mv package.box boxes/stretch.box
&lt;/blockquote&gt;&lt;/pre&gt;

&lt;p&gt;These commands are the key to a re-usable environment:

&lt;blockquote&gt;&lt;pre&gt;
vagrant init stretch file://boxes/stretch.box
vagrant up
vagrant ssh
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;Some other useful commands:

&lt;blockquote&gt;&lt;pre&gt;
vagrant reload (after changing Vagrantfile), page 29
vagrant halt
vagrant suspend
vagrant destroy
vagrant box list
vagrant box remove &lt;boxname&gt;
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;And as a bonus check, once ssh&#039;d into a guest, and a suitable port forward is in place, then check communication (without having to install a web server):

&lt;blockquote&gt;&lt;pre&gt;
sudo python -m SimpleHTTPServer 80
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;Some Vagrant documentation:

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.vagrantup.com/docs/&quot; target=_blank&gt;Vagrant by HashiCorp&lt;/a&gt;
  &lt;li&gt;&lt;a href=&quot;https://friendsofvagrant.github.io/v1/docs/index.html&quot; target=_blank&gt;Friends of Vagrant&lt;/a&gt;
  &lt;/ul&gt;

 
    </content:encoded>

    <pubDate>Tue, 11 Oct 2016 16:28:03 +0000</pubDate>
    <guid isPermaLink="false">http://blog.raymond.burkholder.net/index.php?/archives/685-guid.html</guid>
    
</item>
<item>
    <title>Vagrant, VirtualBox, and NAT Revisited</title>
    <link>http://blog.raymond.burkholder.net/index.php?/archives/684-Vagrant,-VirtualBox,-and-NAT-Revisited.html</link>
            <category>Vagrant</category>
    
    <comments>http://blog.raymond.burkholder.net/index.php?/archives/684-Vagrant,-VirtualBox,-and-NAT-Revisited.html#comments</comments>
    <wfw:comment>http://blog.raymond.burkholder.net/wfwcomment.php?cid=684</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.raymond.burkholder.net/rss.php?version=2.0&amp;type=comments&amp;cid=684</wfw:commentRss>
    

    <author>nospam@example.com (Raymond P. Burkholder)</author>
    <content:encoded>
    &lt;p&gt;In my previous post, I indeed do VirtualBox networking the hard way.  I also hinted that there was a simpler solution.  I tried out the alternate solution, and was successful.

&lt;p&gt;The solution is to use VirtualBox Paravirtualized Network (virtio) drivers.  They appear to be applied in ascending order to the PCI bus, and are numbered that way:

&lt;blockquote&gt;&lt;pre&gt;
vagrant@test01:~$ dmesg | grep eth
[    4.444193] virtio_net virtio0 enp0s3: renamed from eth0
[    4.454983] virtio_net virtio1 enp0s8: renamed from eth1
[    4.488878] virtio_net virtio2 enp0s9: renamed from eth2
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;blockquote&gt;&lt;pre&gt;
vagrant@test01:~$ lspci
00:03.0 Ethernet controller: Red Hat, Inc Virtio network device
00:08.0 Ethernet controller: Red Hat, Inc Virtio network device
00:09.0 Ethernet controller: Red Hat, Inc Virtio network device
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;This is the Vagrantfile to ensure that additional network interfaces are applied with the appropriate type:

&lt;blockquote&gt;&lt;pre&gt;
Vagrant.configure(&quot;2&quot;) do |config|
  config.vm.box = &quot;stretch&quot;

  config.vm.box_url = &quot;file://boxes/stretch.box&quot;

  config.vm.provider &quot;virtualbox&quot; do |v|
    #v.memory = VM_MEM_SIZE
    #v.cpus = VM_CPU_COUNT
    #v.customize [&quot;modifyvm&quot;, :id, &quot;--cpuexecutioncap&quot;, &quot;#{VM_CPU_CAP}&quot;]
    v.customize [&quot;modifyvm&quot;, :id, &quot;--nictype1&quot;, &quot;virtio&quot;]
    v.customize [&quot;modifyvm&quot;, :id, &quot;--nictype2&quot;, &quot;virtio&quot;]
    v.customize [&quot;modifyvm&quot;, :id, &quot;--nictype3&quot;, &quot;virtio&quot;]
    #v.customize [&quot;storagectl&quot;, :id, &quot;--name&quot;, &quot;SATA Controller&quot;, &quot;--hostiocache&quot;, &quot;off&quot;]
  end

  config.vm.define &quot;test01&quot; do |test01|
        test01.vm.hostname = &quot;test01&quot;
        test01.vm.network &quot;private_network&quot;, virtualbox__intnet: &quot;net1&quot;, ip: &quot;192.168.35.23&quot;
        test01.vm.network &quot;private_network&quot;, virtualbox__intnet: &quot;net2&quot;, ip: &quot;192.168.45.34&quot;
    end
  config.vm.define &quot;test02&quot; do |test02|
        test02.vm.hostname = &quot;test02&quot;
        test02.vm.network &quot;private_network&quot;, virtualbox__intnet: &quot;net1&quot;, ip: &quot;192.168.35.24&quot;
        test02.vm.network &quot;private_network&quot;, virtualbox__intnet: &quot;net2&quot;, ip: &quot;192.168.45.33&quot;

    end
end
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;With an acknowledgement to &lt;a href=&quot;https://github.com/mitchellh/vagrant/issues/2389&quot; target=_blank&gt;github comments for #2389&lt;/a&gt;

&lt;p&gt;Link to &lt;a href=&quot;https://www.virtualbox.org/manual/ch06.html&quot; target=_blank&gt;VirtualBox&lt;/a&gt;: Chapter 6 - Virtual Networking 
    </content:encoded>

    <pubDate>Tue, 11 Oct 2016 12:56:16 +0000</pubDate>
    <guid isPermaLink="false">http://blog.raymond.burkholder.net/index.php?/archives/684-guid.html</guid>
    
</item>
<item>
    <title>Vagrant, VirtualBox, NAT, and Out Of Order Network Ports</title>
    <link>http://blog.raymond.burkholder.net/index.php?/archives/683-Vagrant,-VirtualBox,-NAT,-and-Out-Of-Order-Network-Ports.html</link>
            <category>Vagrant</category>
    
    <comments>http://blog.raymond.burkholder.net/index.php?/archives/683-Vagrant,-VirtualBox,-NAT,-and-Out-Of-Order-Network-Ports.html#comments</comments>
    <wfw:comment>http://blog.raymond.burkholder.net/wfwcomment.php?cid=683</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.raymond.burkholder.net/rss.php?version=2.0&amp;type=comments&amp;cid=683</wfw:commentRss>
    

    <author>nospam@example.com (Raymond P. Burkholder)</author>
    <content:encoded>
    &lt;p&gt;When using Vagrant to provision a test environment where each guest has a single network interface, life is good.  However, when running Debian Stretch/Testing as a guest with multiple interfaces, the interactions between Vagrant and VirtualBox networking get a little weird.

&lt;p&gt;As I write this, and thinking ahead a bit, I will need to try the virtio driver and see if I get something different, ie, a better result which doesn&#039;t require a work-a-round.

&lt;p&gt;Anyway, fundamentally, VirtualBox, when emulating Intel network adapters, like the PRO/1000 MT, will assign them to PCI bus numbers in high number first.  On boot up, these are the default assignments in the guest prior to renaming:

&lt;blockquote&gt;&lt;pre&gt;
[    4.647350] e1000 0000:00:08.0 eth0: (PCI:33MHz:32-bit) 08:00:27:3f:00:28
[    4.647355] e1000 0000:00:08.0 eth0: Intel(R) PRO/1000 Network Connection
[    5.435048] e1000 0000:00:09.0 eth1: (PCI:33MHz:32-bit) 08:00:27:0e:e3:92
[    5.435051] e1000 0000:00:09.0 eth1: Intel(R) PRO/1000 Network Connection
[    6.097368] e1000 0000:00:11.0 eth2: (PCI:33MHz:32-bit) 08:00:27:22:7d:7c
[    6.097372] e1000 0000:00:11.0 eth2: Intel(R) PRO/1000 Network Connection
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;You can see that the PCI 00:11.0 is labelled as eth2, but is actually &#039;adapter 1&#039; in the VirtualBox Network configuration list.  This gets in the way of Vagrant&#039;s requirement of the first interface to be type of NAT.  Under Stretch&#039; standard renaming convention, eth0 will be renamed as enp0s8, and eth2 will be renamed as enp0s17.  Due to lexical ordering, Vagrant will pick up eth0/enp0s8 as the first interface, which in fact, matches with &#039;Adapter 3&#039; in the VirtualBox Network list, and therefore, won&#039;t be assigned a NAT address, and therefore results in no connectivity between Vagrant and the guest.

&lt;p&gt;Here is a sample Vagrantfile used to generate the example:

&lt;blockquote&gt;&lt;pre&gt;
Vagrant.configure(&quot;2&quot;) do |config|
  config.vm.box = &quot;stretch&quot;

  config.vm.box_url = &quot;file://boxes/stretch.box&quot;

  config.vm.define &quot;test01&quot; do |test01|
        test01.vm.hostname = &quot;test01&quot;
        test01.vm.network &quot;private_network&quot;, virtualbox__intnet: &quot;net1&quot;, ip: &quot;192.168.35.23&quot;
        test01.vm.network &quot;private_network&quot;, virtualbox__intnet: &quot;net2&quot;, ip: &quot;192.168.45.34&quot;
    end
  config.vm.define &quot;test02&quot; do |test02|
        test02.vm.hostname = &quot;test02&quot;
        test02.vm.network &quot;private_network&quot;, virtualbox__intnet: &quot;net1&quot;, ip: &quot;192.168.35.24&quot;
        test02.vm.network &quot;private_network&quot;, virtualbox__intnet: &quot;net2&quot;, ip: &quot;192.168.45.33&quot;

    end
end
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;The first port is an implied &#039;:forwarded_port&#039;.  The two port definitions, one set for each test guest, create VirtualBox internal networks &#039;net1&#039; and &#039;net2&#039; on Adapters 2 and 3.  When using &#039;virtualbox__intnet&#039;, be sure to put the ip address after &#039;virtualbox__intnet&#039;, otherwise a :hostonly network will be created.  The &lt;a href=&quot;https://www.vagrantup.com/docs/virtualbox/networking.html&quot; target=_blank&gt;VIRTUALBOX INTERNAL NETWORK&lt;/a&gt; documentation could therefore be deemed slightly in-accurate.

&lt;p&gt;I am sure there is a better way to do it, but to do things the hard way, I ended up using udev in Stretch to rename the interfaces to the opposite order.  These changes are put in the &#039;box&#039; file so they are automatically available each time.  This requires two changes in /etc/udev/rules.d:

&lt;blockquote&gt;&lt;pre&gt;
vagrant@test02:~$ ls -alt /etc/udev/rules.d/
total 16
drwxr-xr-x 2 root root 4096 Oct 10 21:13 .
-rw-r--r-- 1 root root  196 Oct 10 21:13 76-net-names.rules
lrwxrwxrwx 1 root root    9 Oct 10 18:05 80-net-setup-link.rules -&gt; /dev/null
-rw-r--r-- 1 root root  134 Oct 10 13:08 60-vboxadd.rules
drwxr-xr-x 4 root root 4096 Oct  7 15:40 ..
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;The first change is to add an &#039;over-ride the default&#039; link to /dev/null for 80-net-setup-link.rules:

&lt;blockquote&gt;&lt;pre&gt;
ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;The default for that rule is at:

&lt;blockquote&gt;&lt;pre&gt;
vagrant@test02:~$ sudo find / -name 80-net-setup-link.rules -print
/etc/udev/rules.d/80-net-setup-link.rules
/lib/udev/rules.d/80-net-setup-link.rules
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;You can see the original in /lib/udev/rules.d, with the over-ride in /etc/udev/rules.d.

&lt;p&gt;The second change is with the content of /etc/udev/rules.d/76-net-names.rules:

&lt;blockquote&gt;&lt;pre&gt;
vagrant@test02:~$ cat /etc/udev/rules.d/76-net-names.rules
SUBSYSTEM==&quot;net&quot;, ACTION==&quot;add&quot;, ATTR{ifindex}==&quot;2&quot;, NAME=&quot;eth2&quot;
SUBSYSTEM==&quot;net&quot;, ACTION==&quot;add&quot;, ATTR{ifindex}==&quot;3&quot;, NAME=&quot;eth1&quot;
SUBSYSTEM==&quot;net&quot;, ACTION==&quot;add&quot;, ATTR{ifindex}==&quot;4&quot;, NAME=&quot;eth0&quot;
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;Because the ifindex is hardcoded, and backwards, the box file needs a special configuration depending upon the number of interfaces to be expected.  A bit painful.  According to 

&lt;blockquote&gt;&lt;pre&gt;
 man /usr/share/doc/udev/README.Debian.gz
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;the following command is needed to update configurations:

&lt;pre&gt;&lt;blockquote&gt;
update-initramfs -u
&lt;/blockquote&gt;&lt;/pre&gt;

&lt;p&gt;To obtain the ifindex attribute, this command proved useful (shown on a one interface system [the original box]):

&lt;blockquote&gt;&lt;pre&gt;
root@stretch:/home/vagrant# apt-get install sysfsutils

root@stretch:/home/vagrant# systool -c net -v
Class = &quot;net&quot;

  Class Device = &quot;eth0&quot;
  Class Device path = &quot;/sys/devices/pci0000:00/0000:00:11.0/net/eth0&quot;
    addr_assign_type    = &quot;0&quot;
    addr_len            = &quot;6&quot;
    address             = &quot;08:00:27:22:7d:7c&quot;
    broadcast           = &quot;ff:ff:ff:ff:ff:ff&quot;
    carrier_changes     = &quot;2&quot;
    carrier             = &quot;1&quot;
    dev_id              = &quot;0x0&quot;
    dev_port            = &quot;0&quot;
    dormant             = &quot;0&quot;
    duplex              = &quot;full&quot;
    flags               = &quot;0x1003&quot;
    gro_flush_timeout   = &quot;0&quot;
    ifalias             =
    ifindex             = &quot;2&quot;
    iflink              = &quot;2&quot;
    link_mode           = &quot;0&quot;
    mtu                 = &quot;1500&quot;
    netdev_group        = &quot;0&quot;
    operstate           = &quot;up&quot;
    proto_down          = &quot;0&quot;
    speed               = &quot;1000&quot;
    tx_queue_len        = &quot;1000&quot;
    type                = &quot;1&quot;
    uevent              = &quot;INTERFACE=eth0
IFINDEX=2&quot;

    Device = &quot;0000:00:11.0&quot;
    Device path = &quot;/sys/devices/pci0000:00/0000:00:11.0&quot;
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;Some additional systool information:

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://fibrevillage.com/storage/61-systool-a-useful-tool-for-san-as-well-for-sysfs-devices&quot; target=_blank&gt;systool, a useful tool for SAN, as well for sysfs devices&lt;/a&gt;

  &lt;/ul&gt;

&lt;p&gt;Another diagnostic command, which shows some additional information, but I couldn&#039;t get the &#039;DEVPATH&#039; to match properly.  I don&#039;t know how to properly debug commands to find what matches and what doesn&#039;t.

&lt;blockquote&gt;&lt;pre&gt;
root@stretch:/home/vagrant# udevadm info /sys/class/net/eth0
P: /devices/pci0000:00/0000:00:11.0/net/eth0
E: DEVPATH=/devices/pci0000:00/0000:00:11.0/net/eth0
E: ID_BUS=pci
E: ID_MODEL_FROM_DATABASE=82545EM Gigabit Ethernet Controller (Copper) (PRO/1000 MT Single Port Adapter)
E: ID_MODEL_ID=0x100f
E: ID_NET_NAME_MAC=enx080027227d7c
E: ID_NET_NAME_PATH=enp0s17
E: ID_OUI_FROM_DATABASE=Cadmus Computer Systems
E: ID_PCI_CLASS_FROM_DATABASE=Network controller
E: ID_PCI_SUBCLASS_FROM_DATABASE=Ethernet controller
E: ID_VENDOR_FROM_DATABASE=Intel Corporation
E: ID_VENDOR_ID=0x8086
E: IFINDEX=2
E: INTERFACE=eth0
E: SUBSYSTEM=net
E: SYSTEMD_ALIAS=/sys/subsystem/net/devices/eth0
E: TAGS=:systemd:
E: USEC_INITIALIZED=4238875
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;One udev command which did show some syntax errors:

&lt;blockquote&gt;&lt;pre&gt;
root@test01:/home/vagrant# udevadm test /sys/class/pci_bus/0000\:00/device/0000:00:09.0
calling: test
version 231
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

=== trie on-disk ===
tool version:          231
file size:         7055294 bytes
header size             80 bytes
strings            1810454 bytes
nodes              5244760 bytes
Load module index
Found container virtualization none
timestamp of &#039;/etc/systemd/network&#039; changed
Parsed configuration file /lib/systemd/network/99-default.link
Parsed configuration file /etc/systemd/network/30-internet.link
Parsed configuration file /etc/systemd/network/20-internet.link
Parsed configuration file /etc/systemd/network/10-internet.link
Created link configuration context.
timestamp of &#039;/etc/udev/rules.d&#039; changed
Skipping overridden file: /lib/udev/rules.d/80-net-setup-link.rules.
Reading rules file: /lib/udev/rules.d/50-firmware.rules
Reading rules file: /lib/udev/rules.d/50-udev-default.rules
Reading rules file: /lib/udev/rules.d/55-dm.rules
Reading rules file: /lib/udev/rules.d/60-block.rules
Reading rules file: /lib/udev/rules.d/60-cdrom_id.rules
Reading rules file: /lib/udev/rules.d/60-drm.rules
Reading rules file: /lib/udev/rules.d/60-evdev.rules
Reading rules file: /lib/udev/rules.d/60-persistent-alsa.rules
Reading rules file: /lib/udev/rules.d/60-persistent-input.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage-dm.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage-tape.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage.rules
Reading rules file: /lib/udev/rules.d/60-persistent-v4l.rules
Reading rules file: /lib/udev/rules.d/60-serial.rules
Reading rules file: /etc/udev/rules.d/60-vboxadd.rules
Reading rules file: /lib/udev/rules.d/64-btrfs.rules
Reading rules file: /lib/udev/rules.d/70-debian-uaccess.rules
Reading rules file: /lib/udev/rules.d/70-mouse.rules
Reading rules file: /lib/udev/rules.d/70-power-switch.rules
Reading rules file: /lib/udev/rules.d/70-touchpad.rules
Reading rules file: /lib/udev/rules.d/70-uaccess.rules
Reading rules file: /lib/udev/rules.d/71-seat.rules
Reading rules file: /lib/udev/rules.d/73-seat-late.rules
Reading rules file: /lib/udev/rules.d/73-special-net-names.rules
Reading rules file: /lib/udev/rules.d/73-usb-net-by-mac.rules
Reading rules file: /lib/udev/rules.d/75-net-description.rules
Reading rules file: /lib/udev/rules.d/75-probe_mtd.rules
Reading rules file: /etc/udev/rules.d/76-net-names.rules
Reading rules file: /lib/udev/rules.d/78-sound-card.rules
Reading rules file: /lib/udev/rules.d/80-debian-compat.rules
Reading rules file: /lib/udev/rules.d/80-drivers.rules
Reading rules file: /lib/udev/rules.d/80-ifupdown.rules
Skipping empty file: /etc/udev/rules.d/80-net-setup-link.rules
Reading rules file: /lib/udev/rules.d/85-hwclock.rules
Reading rules file: /lib/udev/rules.d/90-console-setup.rules
Reading rules file: /lib/udev/rules.d/99-systemd.rules
rules contain 24576 bytes tokens (2048 * 12 bytes), 11090 bytes strings
1545 strings (19300 bytes), 982 de-duplicated (8774 bytes), 564 trie nodes used
IMPORT builtin &#039;hwdb&#039; /lib/udev/rules.d/50-udev-default.rules:15
RUN &#039;kmod load $env{MODALIAS}&#039; /lib/udev/rules.d/80-drivers.rules:5
created db file &#039;/run/udev/data/+pci:0000:00:09.0&#039; for &#039;/devices/pci0000:00/0000:00:09.0&#039;
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:09.0
DRIVER=e1000
ID_MODEL_FROM_DATABASE=82540EM Gigabit Ethernet Controller (PRO/1000 MT Desktop Adapter)
ID_PCI_CLASS_FROM_DATABASE=Network controller
ID_PCI_SUBCLASS_FROM_DATABASE=Ethernet controller
ID_VENDOR_FROM_DATABASE=Intel Corporation
MODALIAS=pci:v00008086d0000100Esv00008086sd0000001Ebc02sc00i00
PCI_CLASS=20000
PCI_ID=8086:100E
PCI_SLOT_NAME=0000:00:09.0
PCI_SUBSYS_ID=8086:001E
SUBSYSTEM=pci
USEC_INITIALIZED=3699833
run: &#039;kmod load pci:v00008086d0000100Esv00008086sd0000001Ebc02sc00i00&#039;
Unload module index
Unloaded link configuration context.
root@test01:/home/vagrant# ls /run/udev/
control           data/             link.dvd          links/            static_node-tags/ tags/             watch/
root@test01:/home/vagrant# ls /run/udev/links
\x2fcdrom
\x2fdisk\x2fby-id\x2fata-VBOX_CD-ROM_VB2-01700376
\x2fdisk\x2fby-id\x2fata-VBOX_HARDDISK_VBa68e3639-072af7a0
\x2fdisk\x2fby-id\x2fata-VBOX_HARDDISK_VBa68e3639-072af7a0-part1
\x2fdisk\x2fby-id\x2fata-VBOX_HARDDISK_VBa68e3639-072af7a0-part2
\x2fdisk\x2fby-id\x2fata-VBOX_HARDDISK_VBa68e3639-072af7a0-part5
\x2fdisk\x2fby-partuuid\x2ff3491df3-01
\x2fdisk\x2fby-partuuid\x2ff3491df3-02
\x2fdisk\x2fby-partuuid\x2ff3491df3-05
\x2fdisk\x2fby-path\x2fpci-0000:00:01.1-ata-2
\x2fdisk\x2fby-path\x2fpci-0000:00:0d.0-ata-1
\x2fdisk\x2fby-path\x2fpci-0000:00:0d.0-ata-1-part1
\x2fdisk\x2fby-path\x2fpci-0000:00:0d.0-ata-1-part2
\x2fdisk\x2fby-path\x2fpci-0000:00:0d.0-ata-1-part5
\x2fdisk\x2fby-uuid\x2f326eca33-565a-4e9c-990d-f3393fde3b43
\x2fdisk\x2fby-uuid\x2fdba71b3f-d578-48b0-99f9-c2cc9945760b
\x2fdvd
\x2finput\x2fby-id\x2fusb-VirtualBox_USB_Tablet-event-mouse
\x2finput\x2fby-id\x2fusb-VirtualBox_USB_Tablet-mouse
\x2finput\x2fby-path\x2fpci-0000:00:04.0-event-mouse
\x2finput\x2fby-path\x2fpci-0000:00:04.0-mouse
\x2finput\x2fby-path\x2fpci-0000:00:06.0-usb-0:1:1.0-event-mouse
\x2finput\x2fby-path\x2fpci-0000:00:06.0-usb-0:1:1.0-mouse
\x2finput\x2fby-path\x2fplatform-pcspkr-event-spkr
\x2frtc
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;With some information supplied at:

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.jpichon.net/blog/2011/12/debugging-udev-rules/&quot; target=_blank&gt;Debugging udev rules&lt;/a&gt;
  &lt;li&gt;&lt;a href=&quot;http://unix.stackexchange.com/questions/200194/how-to-debug-an-udev-rule-in-etc-udev-rules-d&quot; target=_blank&gt;How to debug an udev rule (in /etc/udev/rules.d/…)&lt;/a&gt;
  &lt;li&gt;&lt;a href=&quot;http://superuser.com/questions/677106/how-to-check-if-a-udev-rule-fired&quot; target=_blank&gt;How to check if a udev rule fired&lt;/a&gt;: which might be useful to see the properties when a network card is hot wired into a guest.
  &lt;li&gt;&lt;a href=&quot;http://www.reactivated.net/writing_udev_rules.html&quot; target=_blank&gt;writing udev rules&lt;/a&gt;: some useful background information
  &lt;li&gt;&lt;a href=&quot;https://forums.opensuse.org/showthread.php/476905-udev-rule-not-triggered&quot; target=_blank&gt;opensuse&lt;/a&gt;: udev rule not triggered - good troubleshooting examples
  &lt;li&gt;&lt;a href=&quot;http://www.held.org.il/blog/2009/12/udev-debugging-toolbox/&quot; target=_blank&gt;udev debugging toolbox&lt;/a&gt;: interesting command: &#039;udevadm info -e&#039;
  &lt;li&gt;&lt;a href=&quot;http://www.crashcourse.ca/wiki/index.php/Udev&quot; target=_blank&gt;wiki with lots of tricks&lt;/a&gt;
  &lt;li&gt;&#039;man udev.conf&#039; and adjust for more debug info, which should end up in syslog
  &lt;li&gt;&lt;a href=&quot;http://jasonwryan.com/blog/2014/01/20/udev/&quot; target=_blank&gt;Scripting with udev&lt;/a&gt;
  &lt;li&gt;&lt;a href=&quot;https://wiki.debian.org/udev&quot; target=_blank&gt;Debian&#039;s Wiki on udev&lt;/a&gt;
  &lt;li&gt;&lt;a href=&quot;http://packetpushers.net/udev/&quot; target=_blank&gt;PacketPusher&#039;s comments on udev&lt;/a&gt;
  &lt;/ul&gt;

&lt;p&gt;From &lt;a href=&quot;http://techblogsearch.com/a/debugging-udev-rules-running-udev-in-debug-mode.html&quot; target=_blank&gt;debugging udev rules, running udev in debug mode&lt;/a&gt;:

&lt;blockquote&gt;&lt;pre&gt;
user@ubuntu:~$ sudo service udev stop
user@ubuntu:~$ sudo /lib/systemd/systemd-udevd --debug
&lt;/pre&gt;&lt;/blockquote&gt;

 
    </content:encoded>

    <pubDate>Tue, 11 Oct 2016 12:24:19 +0000</pubDate>
    <guid isPermaLink="false">http://blog.raymond.burkholder.net/index.php?/archives/683-guid.html</guid>
    
</item>

</channel>
</rss>
