How to create a multi NIC Ubuntu cloud image ?

Cloud images are enabled with only 1 NIC.

So, irrespective of the number of networks we attach to VMs in OpenStack, the VM will have only 1 NIC enabled.

I know there are different ways to create Ubuntu cloud image which supports multiple NICs.

In this post, I will describe how to use a simple cron job to enable multiple NICs.

  • Upload cloud image to glance
  • Launch VM using the cloud image
  • Login to the VM
  • Create a script file /home/ubuntu/multinic.sh
  • #!/bin/bash
    hname=$(hostname)
    cat /etc/hosts | grep $hname >> /dev/null
    if [ $? -ne 0 ];then
     sudo bash -c "echo '127.0.0.1 $hname' >> /etc/hosts"
    fi
    netfile=$(find /etc/network/interfaces.d -name "*.cfg")
    for interface in $(ls -1 /sys/class/net | grep ens) ;do
       cat $netfile | grep $interface >> /dev/null
       if [ $? -ne 0 ];then
         sudo bash -c "echo 'auto $interface' >> ${netfile}"
         sudo bash -c "echo 'iface $interface inet dhcp' >> ${netfile}"
         sudo ifup $interface
      fi
    done
  • Create cron job file /var/spool/cron/crontabs/root
  • @reboot /home/ubuntu/multinic.sh
  • Set user, group and permissions for the script and cron files
  • chown ubuntu:ubuntu /home/ubuntu/multinic.sh
    chmod +x /home/ubuntu/multinic.sh
    chown root:crontab /var/spool/cron/crontabs/root
    chmod 600 /var/spool/cron/crontabs/root
  • Create snapshot of the VM
  • Use the snapshot image to launch VMs with multiple NICs.

 

Advertisements

One thought on “How to create a multi NIC Ubuntu cloud image ?

  1. Pingback: Attach Multiple Network Interfaces to Instance OpenStack – ROAR

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s