Difference between revisions of "VirtualBox Network Configuration"

From DAVE Developer's Wiki
Jump to: navigation, search
(Created page with "{{InfoBoxTop}} {{Applies_To_DVDK}} {{InfoBoxBottom}} {{WorkInProgress}}")
 
(VirtualBox Network Configuration Primer)
 
(25 intermediate revisions by 4 users not shown)
Line 3: Line 3:
 
{{InfoBoxBottom}}
 
{{InfoBoxBottom}}
  
{{WorkInProgress}}
+
{{ImportantMessage|text=Different versions of the MVM may use different graphical interfaces (GNOME Unity, LXDE etc.). Hence, the screenshots shown in this page may not look like the same across all of the MVM versions or releases. However, the concepts here described have a general validity.}}
 +
 
 +
=== VirtualBox Network Configuration Primer ===
 +
 
 +
VirtualBox networking supports different configurations. For a in-depth discussion regarding virtual networking see VBox official documentation [http://www.virtualbox.org/manual/ch06.html here].
 +
 
 +
For developing purpose, we are interested in two configuration:
 +
* NAT, which is the default provided with [[:Category:DVDK|DVDK]], and
 +
* Bridged Networking
 +
 
 +
=== Network Address Translation (NAT) ===
 +
 
 +
[[Wikipedia:Network address translation|Network Address Translation]] is a tecnique used in IP networking that modify IP packet header, by changing IP address, while the routing device processes the packet.
 +
 
 +
Only the IP address of the routing device (in case of a Virtual Machine, the host ack at router for the guest) is seen from outside. Usually the routed device (in our case, the guest machine) has an IP address that belongs to a completely different IP subnet.
 +
 
 +
NAT make easy to use a virtual machine because:
 +
* it does not require to configure guest network parameters (the router act as DHCP server and give all the needed information to the guest)
 +
* it guarantees that the VM can be executed in any network environment without breaking the existing network.
 +
 
 +
However it's really hard to configure NAT to let the VM to act as a server (e.g. as NFS or TFTP server), for this reason the developer usually choose a bridged configuration, with proper IP parameter assignments.
 +
 
 +
=== Bridged configuration ===
 +
 
 +
 
 +
In brief, [[Wikipedia:Bridge (networking)|Bridge Networking]] configure host's physical network interface and guest's virtual network interface as if they are connected with a Ethernet Switch.
 +
 
 +
In this way:
 +
* guest (DVDK Virtual Machine) has it's own IP address, usually on the same subnet of the host
 +
* guest is directly accessible (apart from firewall rules that may be configured on the host) from any device on the same subnet
 +
 
 +
To change from NAT to Bridge configuration user have to:
 +
* change Virtual Box network setting
 +
* configure, if needed, guest networking. Guest by default uses DHCP so, if DHCP server is available on your network, no additional configuration is needed.
 +
 
 +
The procedure here described makes use of graphical tools to configure network interface. To do that, please ensure <code>network-manager</code> applet is installed by issuing this command on a terminal shell:
 +
<pre>
 +
dpkg -l network-manager
 +
</pre>
 +
If it is not installed, use these commands to install it:
 +
<pre>
 +
sudo apt-get update
 +
sudo apt-get install network-manager
 +
</pre>
 +
After installing it, please reboot the MVM in order to make the changes to take effect.
 +
==== VirtualBox Bridged configuration ====
 +
 
 +
It's easy to change Virtual Box Network configuration:
 +
* open VBox application and start DVDK VM
 +
* from the VBox main window, select your VM and choose ''Settings'' from the toolbar
 +
 
 +
 
 +
[[File:DVDK_Bridge_Configuration_1.png]]
 +
 
 +
 
 +
* Choose ''Network'' item and, from the ''Attached To:'' dropdown choose ''Bridged Adapter''
 +
 
 +
 
 +
[[File:DVDK_Bridge_Configuration_2.png]]
 +
 
 +
* Now the ''Name'' dropdown should be enabled. If you have more than one network interface, choose the right one to connect the bridge too
 +
 
 +
[[File:DVDK_Bridge_Configuration_3.png]]
 +
 
 +
* That's all, click Ok to apply changes.
 +
 
 +
----
 +
 
 +
An advanced setup is to add another network adapter to be used as ''Bridged Adapter'', while keeping the first network interface with NAT
 +
 
 +
This is a useful setup, for example if your're working on a laptop connected to Internet via Wi-Fi, while you're developing using the bridged network adapter on Ethernet. In this case the VM will be able to access the public network using the NATed interface (via host WiFi) while serving TFTP/NFS file to the Embedded Linux system
 +
 
 +
To add a new network adapter:
 +
* shutdown the VM
 +
* open the VM <code>Settings</code> dialog
 +
* go to the <code>Network</code> page
 +
* select <code>Adapter 2</code> tab
 +
* tick the <code>Enable Network Adapter</code> checkbox
 +
* select the host network interface to bridge to in the <code>Name</code> dropdown
 +
* hit <code>OK</code>
 +
[[File:DVDK adding network adapter.png|none|thumb|699x699px]]
 +
 
 +
==== Network Configuration of the VM (guest) ====
 +
By default, the virtual machine image provided with DVDK is configured with DHCP. If you don't have a DHCP server available on your network, you should configure the interface manually.
 +
 
 +
 
 +
{{ImportantMessage|text=If the configuration is changed from NAT to bridged and no DHCP servers are available on the network, the virtual machine will "hang" for few minutes during the boot process before starting the graphical environment.
 +
 
 +
[[File:MVM-bridged-network-DHCP.png|thumb|center|600px]]
 +
}}
 +
 
 +
 
 +
=====Creation of the network connection=====
 +
The procedure may differ from one graphical environment to the other.
 +
======Unity======
 +
Once the graphical interface is ready, right-click on the NetworkManager Applet on the top Panel and choose ''Edit Connections''
 +
 
 +
[[File:DVDK_Ubuntu_Network_Configuration_1.png]]
 +
 
 +
 
 +
 
 +
Now ''Add'' new connection
 +
 
 +
[[File:DVDK_Ubuntu_Network_Configuration_2.png]]
 +
 
 +
 
 +
 
 +
Fill all the required fields (name and IPv4 configuration) and hit ''Apply'' button.
 +
 
 +
[[File:DVDK_Ubuntu_Network_Configuration_3.png]]
 +
 
 +
 
 +
 
 +
Now the new configuration is added and the Network Manager Applet should tell you that the connection with your network is established
 +
 
 +
For more information about ubuntu take a look at its [https://help.ubuntu.com/10.04/index.html official documentation]
 +
======LXDE======
 +
To configure the network connection, the following approaches are available:
 +
*Edit the configuration files as described [https://help.ubuntu.com/community/NetworkConfigurationCommandLine here]
 +
*Using a script like the following:
 +
<pre>
 +
#!/bin/bash
 +
ifconfig eth0 192.168.0.82 netmask 255.255.255.0 up
 +
route add default gw 192.168.0.254 eth0
 +
echo "nameserver 8.8.8.8" > /etc/resolv.conf
 +
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
 +
</pre>
 +
 
 +
===== NFS Configuration =====
 +
 
 +
{{ImportantMessage|text=Latest DVDK/MVM use a different default configuration which exports <code>/home</code> directory for all IPs. Even if this is a security hole, it allows using NFS without changing the default configuration on any network
 +
<pre>
 +
/home 0.0.0.0/0.0.0.0(rw,sync,no_root_squash,no_subtree_check,crossmnt)
 +
</pre>
 +
}}
 +
 
 +
[[w:Network_File_System|NFS]] is commonly used to network mount the target root file system. NFS Server is already installed on [[:Category:DVDK|DVDK]] but needs to be configured before using it.
 +
 
 +
User just need to edit <code>/etc/exports</code> file to allow the local network to mount NFS shares.
 +
 
 +
If the default configuration does not fit your needs just edit <code>/etc/exports</code> and update the latest line, e.g. if you're on a private class A network 10.0.0.0/8, change the line as:
 +
 
 +
<pre>
 +
/home    10.0.0.0/8(rw,sync,no_subtree_check,no_root_squash,no_all_squash,crossmnt)
 +
</pre>
 +
 
 +
Changes are applied by running <code>exportfs -a</code> as root, and can be verified with <code>exportfs</code>
 +
 
 +
<pre class="workstation-terminal">
 +
nelk@nelk-desktop:~$ sudo exportfs -a
 +
nelk@nelk-desktop:~$ sudo exportfs
 +
/home/shared  192.168.0.0/24
 +
</pre>
 +
 
 +
For more information regarding NFS server and /etc/exports see ''exports'' man page or, for example, [http://linux.die.net/man/5/exports]
 +
 
 +
===== TFTP Configuration =====
 +
 
 +
[http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol TFTP] is used by the target to download files from the host machine, in particular to retrieve the u-boot and kernel images. On the DVDK the TFTP service is properly configured to serve files stored in the <code>/srv/tftp</code> directory. For more information about the tftp service in Ubuntu, please refer to https://help.ubuntu.com/community/UbuntuLTSP/Troubleshooting/TFTP

Latest revision as of 17:11, 8 February 2021

Info Box
VirtualMachine.png Applies to DVDK


200px-Emblem-important.svg.png

Different versions of the MVM may use different graphical interfaces (GNOME Unity, LXDE etc.). Hence, the screenshots shown in this page may not look like the same across all of the MVM versions or releases. However, the concepts here described have a general validity.

VirtualBox Network Configuration Primer[edit | edit source]

VirtualBox networking supports different configurations. For a in-depth discussion regarding virtual networking see VBox official documentation here.

For developing purpose, we are interested in two configuration:

  • NAT, which is the default provided with DVDK, and
  • Bridged Networking

Network Address Translation (NAT)[edit | edit source]

Network Address Translation is a tecnique used in IP networking that modify IP packet header, by changing IP address, while the routing device processes the packet.

Only the IP address of the routing device (in case of a Virtual Machine, the host ack at router for the guest) is seen from outside. Usually the routed device (in our case, the guest machine) has an IP address that belongs to a completely different IP subnet.

NAT make easy to use a virtual machine because:

  • it does not require to configure guest network parameters (the router act as DHCP server and give all the needed information to the guest)
  • it guarantees that the VM can be executed in any network environment without breaking the existing network.

However it's really hard to configure NAT to let the VM to act as a server (e.g. as NFS or TFTP server), for this reason the developer usually choose a bridged configuration, with proper IP parameter assignments.

Bridged configuration[edit | edit source]

In brief, Bridge Networking configure host's physical network interface and guest's virtual network interface as if they are connected with a Ethernet Switch.

In this way:

  • guest (DVDK Virtual Machine) has it's own IP address, usually on the same subnet of the host
  • guest is directly accessible (apart from firewall rules that may be configured on the host) from any device on the same subnet

To change from NAT to Bridge configuration user have to:

  • change Virtual Box network setting
  • configure, if needed, guest networking. Guest by default uses DHCP so, if DHCP server is available on your network, no additional configuration is needed.

The procedure here described makes use of graphical tools to configure network interface. To do that, please ensure network-manager applet is installed by issuing this command on a terminal shell:

dpkg -l network-manager

If it is not installed, use these commands to install it:

sudo apt-get update
sudo apt-get install network-manager

After installing it, please reboot the MVM in order to make the changes to take effect.

VirtualBox Bridged configuration[edit | edit source]

It's easy to change Virtual Box Network configuration:

  • open VBox application and start DVDK VM
  • from the VBox main window, select your VM and choose Settings from the toolbar


DVDK Bridge Configuration 1.png


  • Choose Network item and, from the Attached To: dropdown choose Bridged Adapter


DVDK Bridge Configuration 2.png

  • Now the Name dropdown should be enabled. If you have more than one network interface, choose the right one to connect the bridge too

DVDK Bridge Configuration 3.png

  • That's all, click Ok to apply changes.

An advanced setup is to add another network adapter to be used as Bridged Adapter, while keeping the first network interface with NAT

This is a useful setup, for example if your're working on a laptop connected to Internet via Wi-Fi, while you're developing using the bridged network adapter on Ethernet. In this case the VM will be able to access the public network using the NATed interface (via host WiFi) while serving TFTP/NFS file to the Embedded Linux system

To add a new network adapter:

  • shutdown the VM
  • open the VM Settings dialog
  • go to the Network page
  • select Adapter 2 tab
  • tick the Enable Network Adapter checkbox
  • select the host network interface to bridge to in the Name dropdown
  • hit OK
DVDK adding network adapter.png

Network Configuration of the VM (guest)[edit | edit source]

By default, the virtual machine image provided with DVDK is configured with DHCP. If you don't have a DHCP server available on your network, you should configure the interface manually.


200px-Emblem-important.svg.png

If the configuration is changed from NAT to bridged and no DHCP servers are available on the network, the virtual machine will "hang" for few minutes during the boot process before starting the graphical environment.

MVM-bridged-network-DHCP.png


Creation of the network connection[edit | edit source]

The procedure may differ from one graphical environment to the other.

Unity[edit | edit source]

Once the graphical interface is ready, right-click on the NetworkManager Applet on the top Panel and choose Edit Connections

DVDK Ubuntu Network Configuration 1.png


Now Add new connection

DVDK Ubuntu Network Configuration 2.png


Fill all the required fields (name and IPv4 configuration) and hit Apply button.

DVDK Ubuntu Network Configuration 3.png


Now the new configuration is added and the Network Manager Applet should tell you that the connection with your network is established

For more information about ubuntu take a look at its official documentation

LXDE[edit | edit source]

To configure the network connection, the following approaches are available:

  • Edit the configuration files as described here
  • Using a script like the following:
#!/bin/bash
ifconfig eth0 192.168.0.82 netmask 255.255.255.0 up
route add default gw 192.168.0.254 eth0
echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
NFS Configuration[edit | edit source]
200px-Emblem-important.svg.png

Latest DVDK/MVM use a different default configuration which exports /home directory for all IPs. Even if this is a security hole, it allows using NFS without changing the default configuration on any network

/home 0.0.0.0/0.0.0.0(rw,sync,no_root_squash,no_subtree_check,crossmnt)

NFS is commonly used to network mount the target root file system. NFS Server is already installed on DVDK but needs to be configured before using it.

User just need to edit /etc/exports file to allow the local network to mount NFS shares.

If the default configuration does not fit your needs just edit /etc/exports and update the latest line, e.g. if you're on a private class A network 10.0.0.0/8, change the line as:

/home    10.0.0.0/8(rw,sync,no_subtree_check,no_root_squash,no_all_squash,crossmnt)

Changes are applied by running exportfs -a as root, and can be verified with exportfs

nelk@nelk-desktop:~$ sudo exportfs -a
nelk@nelk-desktop:~$ sudo exportfs 
/home/shared  	192.168.0.0/24

For more information regarding NFS server and /etc/exports see exports man page or, for example, [1]

TFTP Configuration[edit | edit source]

TFTP is used by the target to download files from the host machine, in particular to retrieve the u-boot and kernel images. On the DVDK the TFTP service is properly configured to serve files stored in the /srv/tftp directory. For more information about the tftp service in Ubuntu, please refer to https://help.ubuntu.com/community/UbuntuLTSP/Troubleshooting/TFTP