Popular Posts

Wednesday 16 March 2016

Virtual Networking

Virtual Networking is little bit difficult and confusing.
I will try to explain as much possible. I believe you saw my previous post “Creating Virtual machine in Virtual box
There are 5 types of virtual networking options are available.
  • Network Address Translation (NAT) – this networking is used when guest machine require internet
connection. Guest machine can access all the things which are accessible by Host machine. 
But no other machines including Host can’t access the guest.
  • Bridged networking – use this one when you require a separate IP address for your virtual machine. 
So that your laptop/Desktop is utilizing two Ip address of router,  one is used by host another one 
is by Guest. And other machines in network can access to guest machine.
  • Internal networking – This networking will be used when you want to establish a separate network
 for your virtual machines (Running in single host). But host is excluded in this network.
  • Host-only networking – In this networking, host and guest can communicate. No other machines in 
network can access guest machine.
  • NAT with Port-forwarding – Use when you want other machines to access guest machine without  
assigning a separate IP address to Guest. And guest machine wants access to outside.


In my last post (“Creating Virtual machine in Virtual box”), I demonstrated how to setup VM’s with NAT and
NAT with port forwarding.


  1. Bridged networking



Let us see how to configure Bridged networking.


I will use existing virtual machines for this example.
Open Virtual box.
Here we have two virtual machines:  Fedor20 and Fedora20-Clone.




Navigate to machine settings of Fedora 20. And click Network.




Change attached to option to Bridged Adapter.
And now start the machine.
Let us see Host machine IP settings of Host once.




And guest machines IP address is




My router allocated a separate IP address to Guest machine.
Let us see connectivity from
Host to guest
C:\Users\Naveen>ping 192.168.43.219
Pinging 192.168.43.219 with 32 bytes of data:
Reply from 192.168.43.219: bytes=32 time<1ms TTL=64
Reply from 192.168.43.219: bytes=32 time<1ms TTL=64
Reply from 192.168.43.219: bytes=32 time<1ms TTL=64
Reply from 192.168.43.219: bytes=32 time<1ms TTL=64


Ping statistics for 192.168.43.219:
   Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
   Minimum = 0ms, Maximum = 0ms, Average = 0ms
C:\Users\Naveen>


Guest to host




  1. Internal networking



Next we will see about internal network.
For this we need two machines.
We have fedora20 and fedrora20-Clone. Let us consider fedora20 as Guest1 and fedora20-Clone as Guest2, 
and create internal networking between them.


Go to Settings → Network in both machines and change ‘Attached to’ option to ‘Internal network’.




Make sure all the machines have different MAC address.
Now start the both machines.


Guest 1: ( 192.168.56.108)



Assign Static IP address if DHCP didn’t work.   Edit /etc/sysconfig/network-scripts/ifcfg-p2p1


Restart the network adapter using below commands.
Ifdown p2p1     (root user)
Ifup p2p1




Guest 2 : ( 192.168.56.106)



Do the same changes for second machine also.




Now check the connectivity between two machines.

From Guest1



From Guest2:





We successfully created the internal network between our two Guests.
The worst part we can’t connect (via network) the guest machines from host machine, only the guest 
machines have connectivity.


  1. Host-only network



Change the network ‘attached to’ option to Host-only adapter.




Now start the virtual machine.




IP address 192.168.56.101 was assigned to the guest machine. And host machine IP address is 192.168.56.1


Ethernet adapter VirtualBox Host-Only Network:



  Connection-specific DNS Suffix  . :
  Link-local IPv6 Address . . . . . : fe80::14f4:66d2:a3c6:5060%33
  IPv4 Address. . . . . . . . . . . : 192.168.56.1
  Subnet Mask . . . . . . . . . . . : 255.255.255.0
  Default Gateway . . . . . . . . . :


Let us test the connectivity between


Host → guest


C:\Users\Naveen>ping 192.168.56.101


Pinging 192.168.56.101 with 32 bytes of data:
Reply from 192.168.56.101: bytes=32 time<1ms TTL=64
Reply from 192.168.56.101: bytes=32 time<1ms TTL=64
Reply from 192.168.56.101: bytes=32 time<1ms TTL=64
Reply from 192.168.56.101: bytes=32 time<1ms TTL=64


Ping statistics for 192.168.56.101:
   Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
   Minimum = 0ms, Maximum = 0ms, Average = 0ms


C:\Users\Naveen>


Guest → Host


[root@localhost ~]# ping 192.168.56.101
PING 192.168.56.101 (192.168.56.101) 56(84) bytes of data.
64 bytes from 192.168.56.101: icmp_seq=1 ttl=64 time=0.031 ms
64 bytes from 192.168.56.101: icmp_seq=2 ttl=64 time=0.066 ms
64 bytes from 192.168.56.101: icmp_seq=3 ttl=64 time=0.070 ms
64 bytes from 192.168.56.101: icmp_seq=4 ttl=64 time=0.067 ms
64 bytes from 192.168.56.101: icmp_seq=5 ttl=64 time=0.069 ms
64 bytes from 192.168.56.101: icmp_seq=6 ttl=64 time=0.088 ms
^C
--- 192.168.56.101 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5001ms
rtt min/avg/max/mdev = 0.031/0.065/0.088/0.017 ms


[root@localhost ~]# ifconfig
p2p1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
       inet 192.168.56.101  netmask 255.255.255.0  broadcast 0.0.0.0
       inet6 fe80::a00:27ff:fe1e:a77b  prefixlen 64  scopeid 0x20<link>
       ether 08:00:27:1e:a7:7b  txqueuelen 1000  (Ethernet)
       RX packets 194  bytes 19918 (19.4 KiB)
       RX errors 0  dropped 0  overruns 0  frame 0
       TX packets 156  bytes 20122 (19.6 KiB)
       TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


We have connectivity between both guest and host.
Host-only networking is working fine.


In case if you want virtual machine to connect from host and at the same time it should have access to the 
outside world. Then enable another network adapter for that virtual machine. One network adapter should
be Host only and another should be NAT.
By that you will have two adapters for your virtual machine, then you can access host and outside world also.






We will see more about virtual box on my next post.




No comments:

Post a Comment