Wednesday, October 18, 2017

Creating a Network Topology using VMs in VirtualBox


In my earlier posts, I covered How to - Create a Ubuntu VM in Virtualboxtopics related that and Networking for VirtualBox VMs.

In this post, I will provide steps to create the following simple network topology using VirtualBox VMs:

                     H1  <----->  R1  <----->  R2  <----->  H2

As we need only interconnectivity among the VMs, we can use "Internal Networking" mode as detailed in Networking for VirtualBox VMs. Also, I am going to leave the default NAT mode enabled VM adapters as-is. Instead, I will use the remaining VM adapters to create the above topology.
  • Right click VM H1, select "Settings", select "Network" tab, select "Adapter2", check "Enable Network Adapter", choose "Internal Network" in "Attached to". Then provide a name in "Name" field. This name & the name we provide in VM R1's Adapter should match. The VM adapters with matching names will be connected.

             

  • Right click VM R1, select "Settings", select "Network" tab, select "Adapter2", check "Enable Network Adapter", choose "Internal Network" in "Attached to". Then provide a name in "Name" field. This name & the name we provide in VM H1's Adapter should match. The VM adapters with matching names will be connected.

             

  • Now the link "H1  <----->  R1" is established.
  • Similarly, I established the other two links: "R1  <----->  R2" & "R2  <----->  H2"


Now, I booted my VMs, configured IP addresses & ran ping tests to check whether work fine. Here, I am providing screenshots of H1 & R1 VM bash terminals:
              
             


References:



Networking for VirtualBox VMs


In my earlier posts, I covered How to - Create a Ubuntu VM in Virtualbox and topics related that. In this post, I will cover basics of networking techniques for VirtualBox VMs.

Networking is necessary to connect the VM to/from internet or establish connectivity among the VMs. The following are different ways of networking (copy-pasted from https://www.virtualbox.org/manual/ch06.html#networkingmodes):

"
VirtualBox provides up to eight virtual PCI Ethernet cards for each virtual machine. We can configure only four of these form GUI. CLI allows to configure all the eight interfaces.

Each of the eight networking adapters can be separately configured to operate in one of the following modes:
Not attached
In this mode, VirtualBox reports to the guest that a network card is present, but that there is no connection -- as if no Ethernet cable was plugged into the card. This way it is possible to "pull" the virtual Ethernet cable and disrupt the connection, which can be useful to inform a guest operating system that no network connection is available and enforce a reconfiguration.
Network Address Translation (NAT)
If all you want is to browse the Web, download files and view e-mail inside the guest, then this default mode should be sufficient for you, and you can safely skip the rest of this section. Please note that there are certain limitations when using Windows file sharing (see Section 6.3.3, “NAT limitations” for details).
NAT Network
The NAT network is a new NAT flavour introduced in VirtualBox 4.3. See 6.4 for details.
Bridged networking
This is for more advanced networking needs such as network simulations and running servers in a guest. When enabled, VirtualBox connects to one of your installed network cards and exchanges network packets directly, circumventing your host operating system's network stack.
Internal networking
This can be used to create a different kind of software-based network which is visible to selected virtual machines, but not to applications running on the host or to the outside world.
Host-only networking
This can be used to create a network containing the host and a set of virtual machines, without the need for the host's physical network interface. Instead, a virtual network interface (similar to a loopback interface) is created on the host, providing connectivity among virtual machines and the host.
Generic networking
Rarely used modes share the same generic network interface, by allowing the user to select a driver which can be included with VirtualBox or be distributed in an extension pack.
At the moment there are potentially two available sub-modes:
UDP Tunnel
This can be used to interconnect virtual machines running on different hosts directly, easily and transparently, over existing network infrastructure.
VDE (Virtual Distributed Ethernet) networking
This option can be used to connect to a Virtual Distributed Ethernet switch on a Linux or a FreeBSD host. At the moment this needs compiling VirtualBox from sources, as the Oracle packages do not include it.
The following table provides a quick overview of the most important networking modes:

Table 6.1. Overview
VM ↔ HostVM1 ↔ VM2VM → InternetVM ← Internet
Host-only++
Internal+
Bridged++++
NAT+Port forwarding
NAT Network++Port forwarding

"

After creating the VM, the default mode is NAT. So, I was able to connect to internet without any additional configuration. Select a VM & Right click, select "Settings", "Network" tab to see the VM's default networking config:
             



References:

Tuesday, October 17, 2017

How to manage VM groups in VirtualBox - Create/Rename/Delete Groups, Add/Delete VMs


In this post, I will provide steps to create and manage VM groups in VirtualBox. If I call for a VM creation in this post, please refer to my earlier blog: How to - Create a Ubuntu VM in Virtualbox

Why do we need a VM group?
I recently started creating a few network topologies & so grouping VMS belonging to one topology into one group made it easy for me to manage my topologies and VMs. Simply, grouping helps you organize your VMs better.

How to create a VM group?
  • Select the VMs to be grouped, right click & select "Group":
             

  • The above steps names the group as "New Group":
             

How to add a new VM to an existing VM group?
  • Drag and drop the VM into the new group.

How to delete a VM from an existing VM group?
  • Drag and drop the VM from the group to an empty place in the VM list menu

How to rename a VM group?
  • Right click on the group name & select "Rename Group":
             

How to ungroup a VM group?
  • Right click on the group name & select "Ungroup":
             


References:



"VirtualBox Guest Additions" Installation error - Unable to insert the virtual optical disk


To copy paste from Virtualbox guest to host & vice versa, I typically follow the steps listed in my earlier blog post - How to - copy/paste from VirtualBox guest to host & viceversa. Though it worked for me many times, I got the following error pop up recently when I clicked on the "Devices" in top bar menu and clicked on "Insert Guest Additions CD image...":
             

In this post, I will provide steps to install the "VirtualBox Guest Additions" in an alternate way.
  • Shut down the VM
  • I right clicked on my VM in Virtualbox Manager, clicked on the "Settings" displayed menu, selected "Storage" tab, right clicked on "VBoxGuestAdditions" & clicked on "Remove attachment":
             
  • Clicked the "+" icon next to "Controller: IDE" to add a new optical drive. Choose "Leave Empty --> Okay":
             
             



References:


Sunday, September 10, 2017

How to sync local repository sources from the github repository?


At times, the local sources repository could be obsolete as the gitgub repository changes after we imported. In this post, I will provide the command required to sync the local repository from the github repository.
babu@babu-VirtualBox:~/EKiD$ git pull origin master
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 3), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (5/5), done.
From https://github.com/babuneelam/EKiD
 * branch            master     -> FETCH_HEAD
   2005d11..46764be  master     -> origin/master
Updating 2005d11..46764be
Fast-forward
 .README.swp | Bin 12288 -> 0 bytes
 README      |  51 ++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 42 insertions(+), 9 deletions(-)
 delete mode 100644 .README.swp
babu@babu-VirtualBox:~/EKiD$


TBD: How are conflicts between local and remote changes handled?


Hope this helps.

How to import from and export changes to an existing github repository?


In this post, I will explain how to import sources from an existing github repository to a local directory, make changes locally as necessary and then export the changes back to the github repository.

  • Import from your github repository to local directory:
  • babu@babu-VirtualBox:~$ git clone https://github.com/babuneelam/EKiD.git
    Cloning into 'EKiD'...
    remote: Counting objects: 54, done.
    remote: Compressing objects: 100% (48/48), done.
    remote: Total 54 (delta 6), reused 46 (delta 4), pack-reused 0
    Unpacking objects: 100% (54/54), done.
    Checking connectivity... done.
    babu@babu-VirtualBox:~$ cd EKiD/
    babu@babu-VirtualBox:~/EKiD$ ls
    ConfigControls  LICENSE  README  SampleOutputs  Sources
    babu@babu-VirtualBox:~/EKiD$ 
  • Make change as necessary
  • See the diff
    • babu@babu-VirtualBox:~/EKiD$ git diff
      diff --git a/ConfigControls/EnvCfg b/ConfigControls/EnvCfg
      index 485a346..63a1976 100644
      --- a/ConfigControls/EnvCfg
      +++ b/ConfigControls/EnvCfg
      @@ -1,5 +1,5 @@
      -GECKO_DRV_PATH=/Users/babuneelam/Downloads/geckodriver
      -FONTS_FOLDER=/Library/Fonts
      +GECKO_DRV_PATH=/home/babu/bin/geckodriver
      +FONTS_FOLDER=/usr/share/fonts/truetype/msttcorefonts/
       #GECKO_DRV_LOG_FILE=RunTimeInfo/geckodriver.log
       #OUTPUT_DIR=RunTimeInfo/output
       #IMAGE_STORE_PATH=RunTimeInfo/google_images
      babu@babu-VirtualBox:~/EKiD$ 
      babu@babu-VirtualBox:~/EKiD$ git diff --name-only
      ConfigControls/EnvCfg
      babu@babu-VirtualBox:~/EKiD$ 
    • Tell git who you are:
          git config --global user.email "you@example.com"
          git config --global user.name "Your Name"
      • TBD: Add/Remove existing files from git repository
      • Export ALL the local changes to the github repository:
            babu@babu-VirtualBox:~/EKiD$ git commit -a
              [master 32a66e9] A few fixes
               2 files changed, 3 insertions(+), 3 deletions(-)
            babu@babu-VirtualBox:~/EKiD$
              babu@babu-VirtualBox:~/EKiD$ git pull origin master
              From https://github.com/babuneelam/EKiD
              * branch            master     -> FETCH_HEAD
              Already up-to-date.

            babu@babu-VirtualBox:~/EKiD$ 
            babu@babu-VirtualBox:~/EKiD$ git push -u origin master
              Username for 'https://github.com': babuneelam
              Password for 'https://babuneelam@github.com':
              Counting objects: 6, done.
              Compressing objects: 100% (6/6), done.
              Writing objects: 100% (6/6), 604 bytes | 0 bytes/s, done.
              Total 6 (delta 4), reused 0 (delta 0)
              remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
              To https://github.com/babuneelam/EKiD.git
                 46764be..32a66e9  master -> master
              Branch master set up to track remote branch master from origin.
            babu@babu-VirtualBox:~/EKiD$ 
      • Export only a few files of the local changes to the github repository:
      babu@babu-VirtualBox:~/EKiD$ git commit ConfigControls/AlgoCfg -m 'Documentation fixes'
      [master 4668ebb] Documentation fixes
      1 file changed, 8 insertions(+)
      babu@babu-VirtualBox:~/EKiD$ git commit ConfigControls/FontCfg -m 'Documentation fixes'
      [master a3437e1] Documentation fixes
      1 file changed, 5 insertions(+), 2 deletions(-)
      babu@babu-VirtualBox:~/EKiD$
      babu@babu-VirtualBox:~/EKiD$ git pull origin master
      From https://github.com/babuneelam/EKiD
      * branch            master     -> FETCH_HEAD
      Already up-to-date.
      babu@babu-VirtualBox:~/EKiD$ git push -u origin master
      Username for 'https://github.com': babuneelam
      Password for 'https://babuneelam@github.com':
      Counting objects: 8, done.
      Compressing objects: 100% (8/8), done.
      Writing objects: 100% (8/8), 1.02 KiB | 0 bytes/s, done.
      Total 8 (delta 3), reused 0 (delta 0)
      remote: Resolving deltas: 100% (3/3), completed with 1 local object.
      To https://github.com/babuneelam/EKiD.git
        b61c9a5..a3437e1  master -> master
      Branch master set up to track remote branch master from origin.

      babu@babu-VirtualBox:~/EKiD$

      Hope this helps.


      How to add collaborators to your github repository?


      Recently, I wanted to invite my friends to collaborate on a project I published on Github. In this post, I will provide steps I used to invite a collaborator for my github repository.
      • Click "Settings" Tab 
      • Click "Collaborators" on left hand side
      • In the text box, search by providing name or github username or email address of the collaborator you want to invite. It automatically displays matching github users. Select correct user from among the drop down entries.
      • Click "Add Collaborator"
      • Now, github sends the invite to the collaborator. Once the collaborator accepts the invite, he/she can start contributing !!


      Hope this helps.

      How to add local project sources to a new github repository?



      In this post, I will provide steps to publish source code from a local machine to github repository.

      • Create a new GitHub repository. Use "+ --> New Repository" at the top right & the follow the steps there after.
      • In the local machine containing your project source code, open a terminal.
      • Go to the project sources directory.
      • git init (initializes git repository locally)
      • Babus-MacBook-Pro:EKiD babuneelam$ git init
        Initialized empty Git repository in /Users/babuneelam/EKiD/.git/
        Babus-MacBook-Pro:EKiD babuneelam$ 
        • git add . (adds all the files to local git repository)
        • Babus-MacBook-Pro:EKiD babuneelam$ git add .
          Babus-MacBook-Pro:EKiD babuneelam$ 
        • git config --global user.name "Your Name"
        • git config --global user.email you@example.com
        • git commit -m "First Commit" (commits all the code to local repository)
                               Babus-MacBook-Pro:EKiD babuneelam$ git commit -m "First Commit"
                                          Committer: Babu Neelam <babuneelam@Babus-MacBook-Pro.local>
                                          Your name and email address were configured automatically based
                                          on your username and hostname. Please check that they are accurate.
                                          You can suppress this message by setting them explicitly. Run the
                                           following command and follow the instructions in your editor to edit
                                           your configuration file:
                                                 git config --global --edit
                                            After doing this, you may fix the identity used for this commit with:
                                                 git commit --amend --reset-author
                                          41 files changed, 674 insertions(+)

                                      create mode 100644 .README.swp
                                      ....
                                      .... ....
                             Babus-MacBook-Pro:EKiD babuneelam$ 
        • Go to the Github repository page. In "Clone or download" dropbox, copy the github web url. In my case, it was https://github.com/babuneelam/EKiD.git.
        • In the terminal, git remote add origin <github-web-url>
        • Babus-MacBook-Pro:EKiD babuneelam$ git remote add origin https://github.com/babuneelam/EKiD.git
          Babus-MacBook-Pro:EKiD babuneelam$ 
        • git merge origin/master --allow-unrelated-histories (pulls files from github-web-url to local repository
        • Babus-MacBook-Pro:EKiD babuneelam$ git merge origin/master --allow-unrelated-histories

          Merge made by the 'recursive' strategy.
           .gitignore | 101 +++++++++
           LICENSE    | 674 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
           2 files changed, 775 insertions(+)
           create mode 100644 .gitignore
           create mode 100644 LICENSE
          Babus-MacBook-Pro:EKiD babuneelam$
        • git push -u origin master (pushes the local project's changes to the github repository)
          Babus-MacBook-Pro:EKiD babuneelam$ git push -u origin master

          Username for 'https://github.com': babuneelam
          Password for 'https://babuneelam@github.com': 
          Counting objects: 43, done.
          Delta compression using up to 4 threads.
          Compressing objects: 100% (41/41), done.
          Writing objects: 100% (43/43), 10.96 MiB | 593.00 KiB/s, done.
          Total 43 (delta 1), reused 0 (delta 0)
          remote: Resolving deltas: 100% (1/1), done.
          To https://github.com/babuneelam/EKiD.git
             b447218..8d823bf  master -> master
          Branch master set up to track remote branch master from origin.
          Babus-MacBook-Pro:EKiD babuneelam$ 
        • Refresh the github repository to see the local changes on the github !!

        Hope this helps.


        References:
        https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
        https://help.github.com/articles/creating-a-new-repository/
        https://stackoverflow.com/questions/38255655/trying-to-pull-files-from-my-github-repository-refusing-to-merge-unrelated-his



        Wednesday, August 23, 2017

        Resources to learn Python language


        I am currently learning Python language. In this post, I will go over some resources (work in progress) that helped me pick up Python.


        Hope this helps.

        UA-48797665-1