Saturday, July 22, 2017

VM networking with VirtualBox on Ubuntu

Last week just finished an awesome training session on docker. Granted our corporate networks were sort of a hurdle for the training. But VirtualBox enabled us to carry on with the training. So I went home and installed virtualbox on my ubuntu machine; created a few VMs and thought I could get them networking. To my dismay I couldn’t get my host to talk to any of my guest virtual machines…

So I tinkered around and finally narrowed down the minimal stuff you need to do.

Here are some assumptions before going forward:
  1. You have a freshly installed virtualbox in ubuntu
  2. You have gone ahead with the creation of two (or more) virtual machines. Ultimately you need two to start with. Whether you have cloned virtual machines or created from scratch is irrelevant.
  3. You have at least tried to ssh from your host machine to the guest. So the assumption is that you have installed some ssh server on the guest machine.
  4. (This may not be necessary) You may have tried adding another network adapter - a host-only adapter, but you find that you cannot set the adapter name.

Scope of this post

I am only going to show you networking between the host and the guest machine. These steps should enable guest-to-guest networking in the host. Now if inside a VM you can’t connect to the internet…I can’t help you there. So hoping that is not the case.

Further, this post only deals with plain host to guest networking and vice versa. It does not cover how you can make those guest machines participate in the host VLAN network. In other words, it does not cover networking between other hosts in the same VLAN network as our specific host, with these guest machines.

Getting started

1. Setting up the host-only adapter.

Chances are you need to explicitly setup this one.

1.1 Finding the host network interface

You need to do this on your host and the guest machine.

Type the following

ls /sys/class/net

This will list the interfaces on your machine. Its a good idea to do this on both machines. However, on the host machine, this helps us in figuring out whether virtualbox has created a network interface for you. Suppose your host gave you an output like follows:

$ ls /sys/class/net
docker0  eth0  lo  wlan0

It probably means VirtualBox isn’t running…
…OR…
VirtualBox hasn’t created a network interface for you.

If latter is the case, you can re-verify this (assumption #4)

If however, virtualbox is running and you see an entry like vboxnet0 - I guess you are okay and you can skip the next step

1.2 Setting up the VirtualBox network interface.

This is fairly simple. Follow the steps given here -> https://askubuntu.com/a/198467/1123

2. Setting up an extra network adapter for your virtual machine.

We need a way to tell VirtualBox to setup an interface for our virtual machine. VirtualBox will give it a unique IP address via which you can at least begin to ping the guest machine. But this is not so straight forward.

Make sure you have powered-off your VM.

(While you are at it, you can also verify with exercise 1.1 for the host - if there is no network interface - you are in a big soup)

Follow the steps here to add the extra network adapter -> http://deostroll-developer.blogspot.com/2017/07/how-to-add-new-network-adapter-to.html

After this boot into your VM (in shell) and login as root

Hopefully based on the VM you are using there is probably a command to list the “active” network interfaces - Say if you are using ubuntu its ifconfig; if its a pure debian based os its ip address.

Go ahead and try the command out.

Note, the emphasis is on “active”. Your OS will detect your network interfaces, but won’t activate all of them. In other words, you can list the set of interfaces your OS is aware of. But you have to take the additional effort of activating them.

How to list all the network interfaces? See exercise 1.1

3. Activating the VM network interface in the guest

So you are inside your VM.

(Just for the heck of it. Simply verify exercise 2 was done correctly, that means carry out exercise 1.1 for the guest machine).

So the output of exercise 1.1 (on the guest) looks like this:

$ ls /sys/class/net
eth0 eth1 lo

Listing active interfaces (ifconfig) will probably have a private ip for eth0. There won’t be an entry for eth1. Here is how to set it:

Using a text editor like vi or nano, edit the /etc/network/interfaces file append the following lines to the file

# this is the secondary interface
auto eth1
iface eth1 inet dhcp

Now type

$ ifup eth1

If all goes well you will see and output the last line of which says you’ve obtained a lease of an ip address.

Verify again with command to list active network iterfaces

$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:91:02:83  
          inet addr:10.0.2.15  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe91:283/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

eth1      Link encap:Ethernet  HWaddr 08:00:27:70:A2:B5  
          inet addr:192.168.56.102  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe70:a2b5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

At this point, from the host you should be able to ping the guest machine. You can do a similar set of exercises for the other VM, and then ping the 2nd VM from the first one. But that is left to you as homework.

Hope this article helps you getting started with networking. Now you are hopefully ready to experiment with docker swarm at least.

How to add a new network adapter to an existing VM (Oracle VirtualBox)

This same post is available here -> http://imgur.com/a/4FRET

If for what ever reason you cannot access the above, continue reading this post.

This post is only meant to supplement this post.

Step 1: open the settings dialog for your VM

Step 2 : go to the network option in the sidebar - click on the Adapter 2 tab

Step 3: on the adapter 2 tab, notice that the UI is disabled. We have to check the checkbox to specify this adapter


step 4: after you've done so we have to specify a value for "Attached to:" - Select "Host only Adapter" here

Step 5: Select a value for the "Name" select field. Notice it says vboxnet0 - that is the default. That is it. Click OK and you are done. Now power-on your VM and verify if the adapter is detectable by your OS
 

Thursday, February 2, 2017

learn programming (or to become a programmer)

Programming is an interesting exercise. Sometimes at work, I discover a problem. And a good chunk of my time goes into figuring out a solution to fix it. When I discover a challenge in the piece of code I am writing or the solution I am implementing, it becomes more exciting.

But programming isn't everyone's cup of tea. There are good many articles and forum posts which say what the programming profession is and if programming is the right job for you. Here are few links to that effect:
  1. http://www.makeuseof.com/tag/6-signs-meant-programmer/
  2. https://www.theguardian.com/info/developer-blog/2011/oct/07/programming-developer-journalist
  3. https://www.youtube.com/watch?v=0MJUpEkxteE

I highly recommend you continue reading this post after visiting the above links.

Here are some less-mentioned guides about how to go about learning programming:

1. The more you realize what a computer actually is, the more comfortable you might be with learning how to write programs. Its not really writing code or compiling programs...it more of figuring out the answer to why write programs?

2. It also helps to think of a computer as an IO (input/output) machine. It is designed to accept certain kinds of input, do some processing and calculations, and output to a set of destinations. The most common of destinations is a computer terminal (or a computer monitor).

3. Get a general sense of how software works? Is it interactive? Does it require human interaction? If the software does not need human interaction, and it works, how the hell does it work?

4. Its not about a language, or the best language. The language is only a vehicle for you to get programming. The language alone doesn't tell the computer what to do. But it is important to figure out what the computer is capable of...and how that language can achieve all that. Step 3 is sort of important here. As you do this, you slowly figure out how a computer actually works.

Now if all this sounds like something you are not bound to like...then don't get into programming. Its not your thing. There are loads of other career choices to make - it need not have to be related with what you studied in college. But it has to be something you enjoy doing.


If you are a novice programmer probably the best place to get started might be
CodeAcademy. Most of the programming languages come with a developer environment (or an IDE). Here you can learn any language without that hassle. If you are just starting out, keep the next thing as a to-do item at the back of your mind...probably when you achieve a certain level of proficiency writing simple programs you can have a go at this: find an answer to what makes a web application different from a desktop application?

All the best.

Tuesday, January 3, 2017

konva js - a fork of kineticjs - a javascript 2d graphics/animation library

I've been exploring KonvaJs for a while. And I like it. I've done some pretty awesome animations using this library too.

https://plus.google.com/+ArunJayapal/posts/BRqib53sHK6
http://jsbin.com/fulujeceti/1/edit?js,output

The more you use the library, the more you'd want to make a custom shape. And there is a solution for that. However, that talks about manually drawing shapes using the 2d canvas primitives. But, you'd also want to re-use what is already offered by the library. Konva docs currently don't have a say about how to do this.

I may have found a hack. It may not be elegant when you think it. But it will do...

Here is my git repo if you are interested in code for an example.

https://github.com/deostroll/konva-graph-generator

Ps: you'll need npm and gulp to run it.