The Queen's Gambit Declined... 1. d4 d5 2. c4 ...

Saturday Mar 01, 2008


The easiest way to setup a Networked Guest OS with VirtualBox is by using NAT (Network Address Translation).

In this situation, the VirtualBox network engine acts as a router and routes the network traffic between the guest OS and the Internet
(assuming the host is connected to the Internet). The disadvantage of using NAT is that the guest OS is part of its own local network
and is unreachable from outside even from the guest OS!

Fortunately, by using Port Forwarding, it's possible to make network services, from the Guest, accessible from the Host.

In this example, I'm going to setup a FTP server under Windows XP (Guest) and then access the server from Solaris (Host).

1. Install WindowsXP as a Guest OS and choose NAT as the network mode.

2. In WindowsXP, the network should be similar to this :


C:\> ipconfig /all

Windows IP Configuration

        Host Name . . . . . . . . . . . . : software-d59018
        Primary Dns Suffix  . . . . . . . :
        Node Type . . . . . . . . . . . . : Unknown
        IP Routing Enabled. . . . . . . . : No
        WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter Local Area Connection:

        Connection-specific DNS Suffix  . :
        Description . . . . . . . . . . . : AMD PCNET Family PCI Ethernet Adapter
        Physical Address. . . . . . . . . : 08-00-27-EA-94-15
        Dhcp Enabled. . . . . . . . . . . : Yes
        Autoconfiguration Enabled . . . . : Yes
        IP Address. . . . . . . . . . . . : 10.0.2.15
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 10.0.2.2
        DHCP Server . . . . . . . . . . . : 10.0.2.2
        DNS Servers . . . . . . . . . . . : 10.0.2.3
        Lease Obtained. . . . . . . . . . : Saturday, March 01, 2008 3:34:07 PM
        Lease Expires . . . . . . . . . . : Sunday, March 02, 2008 3:34:07 PM

As you can see, the guest is in the 10.0.2.xxx subdomain (my Host is in the 192.168.0.xxx).

3. Install a FTP server under WinXP.

For my own purpose, I've used the FileZilla Server because it is free and easily configurable through a GUI interface.

Verify the ftp server is working from the Guest OS:

C:\> ftp localhost
Connected to software-d59018.
220-FileZilla Server version 0.9.24 beta
220-written by Tim Kosse (Tim.Kosse@gmx.de)
220 Please visit http://sourceforge.net/projects/filezilla/
User (software-d59018:(none)): anonymous
331 Password required for anonymous
Password:
230 Logged on
ftp>


4. Setup the Port Forwarding

By default, the FTP server uses the port 21 (make sure there is no firewall blocking the port 21 in WindowsXP; by default it is blocked by Windows's Firewall).

In Solaris, I'm going to map the port 4021 to 21 :


/usr/bin/VBoxManage setextradata <name_of_vm> "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort” 4021
/usr/bin/VBoxManage setextradata <name_of_vm> "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort” 21

/usr/bin/VBoxManage setextradata <name_of_vm> "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol” "TCP"

- Replace name_of_vm with the name of your virtual machine
- Replace ssh with the prefered nam you want, it has to be unique

These commands update the .xml file under ~/.VirtualBox/Machines/<name of vm> therefore the configuration is persistent across reboots.

To remove the settings, run the same commands without the last argument.

5. Restart the Guest for the Port Forwarding to take effect.

You can verify if the VM is listening on port 4021

# pfiles 1872
1872:    /opt/VirtualBox/VirtualBox -comment winxp -startvm a805c093-566d-4a22-
  Current rlimit: 256 file descriptors
[...]
 34: S_IFSOCK mode:0666 dev:310,0 ino:7522 uid:0 gid:0 size:0
 O_RDWR
 SOCK_STREAM
 SO_REUSEADDR,SO_OOBINLINE,SO_SNDBUF(49152),SO_RCVBUF(49152)
 sockname: AF_INET 0.0.0.0&nbsp; port: 4021
[...]

6. Verify ftp is accessible from Solaris.

# ftp 192.168.0.4 4021
Connected to 192.168.0.4.
220-FileZilla Server version 0.9.24 beta
220-written by Tim Kosse (Tim.Kosse@gmx.de)
220 Please visit http://sourceforge.net/projects/filezilla/
Name (192.168.0.4:root): anonymous
331 Password required for anonymous
Password:
230 Logged on
Remote system type is UNIX.
ftp> ls
200 Port command successful
150 Opening data channel for directory list.
desktop.ini
My Music
My Pictures
My Videos
226 Transfer OK
47 bytes received in 0.0063 seconds (7.27 Kbytes/s)
ftp>



The same procedure can apply to communicate through http, ftp, etc... from Solaris to a WindowsXP guest.
Comments:

I hope you are aware that Filezilla server has sometimes troubles & you ftp get a file and it can be corrupt ... (try something ~ 20MB , do a checksum, compare checksums ;) )
Especially with backwards compatibility to old ftps ... I know it probably works 100% of the time with its own client ... so better not rely on it !

Posted by 84.42.170.122 on March 04, 2008 at 10:11 AM CET #

How will this work when HOST=WINXP & GUEST=LINUX?

Posted by Unknown on July 10, 2008 at 07:20 AM CEST #

It doesn't matter what HOST or GUEST it is, the procedure is always the same : use VBoxManage
to enable port forwarding.

Posted by Renaud on July 10, 2008 at 11:49 AM CEST #

Great.....

Thank's for this tutorial :)

HOST=FreeBSD
GUEST=Linux and OpenBSD

Posted by Wirasto S. Karim on June 08, 2009 at 03:40 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed