Your basic problem (having a static IP) is unrelated to the VM. Instead of using a bridged network interface (i.e. guest system does its own networking), you could in theory use NAT and port redirection and configure the host system to have a static IP.
Unfortunately, it is not possible to configure a static IPv4 address. In an IPv4 network, every node has its own routing table. Typically, most nodes will send traffic to their local network (starting with 192.168., 10., or 172.16-31.* ) directly to the target PC. Unfortunately, the addresses used in the network can be any of the above, and your preferred address may already be taken.
That leaves us with a global IPv4 address. Routing for those is configured in the core internet, and that routing must be configured by the ISP and local gateway to the internet. This is not feasible, and does not allow dynamic readressing.
The Mobile IP standard that would allow such rerouting has not seen widespread implementation. Mobile IPv4 works by having a system manage your global IPv4 address and rerouting it to your current location.
You can achieve something like this today by using a VPN: Set up a VPN server with a static IP somewhere on the internet, and have your Ubuntu Server VM connect to it. Then, redirect the ports in question from the VPN server to the client.
If a constant name that maps to the current IP address is sufficient, you can use a dyndns service. These give you a domain name you can update with a client utility that runs in your VM. That way, you can point my-ubuntu-vm.dyndns-provider.net to the current local address in use.
Instead of registering a global DNS name, you can also use multicast DNS with avahi. After configuration, your VM will be reachable under a name like my-ubuntu-vm.local. Unfortunately, multicast DNS requires additional software. While many Linux and Mac OS X systems support it out of the box, Windows systems do not. You can install Apple's Bonjour (also offered together with Apple Safari) on these systems.
If dyndns doesn't work for you (you really need an IP, and not a name, or update times are too spotty), and you have almost constant internet connection, I'd recommend moving the VM system to a host that has a global IP address. This has the same downsides as the VPN solution (doesn't work when you're not connected to the internet, and you'll have to pay for the server and global address), but is comparatively easy to set up.
If you only want to access the VM from the host itself, you can simply use NAT and Port Forwarding (Now available in the GUI to, via Devices -> Network Adapters). Redirect the ports (for example, redirect the client's HTTP server from port 80 on the guest to port 2080 on the host), and then use the modified port. Step-By-step:
- Go to the network tab. If the VM is running, select
Devices-> Network Adapters. If it is not, right-click, select Settings (or click the Settings button), and then go to the Network tab.
- Make sure there is only one adapter, and that it is set to NAT. (If you change anything here, you need to reconfigure the VM)
- Open up
Advanced in the networking tab.
- Click
Port Forwarding.
- Add a rule. Set the host port to a high port (like 2080), and the client port to the port you want to redirect (80 for HTTP, 22 for ssh).
- Enter
http://localhost:2080 in your host system's browser to access the client HTTP server.
If you need the services to run on the same ports, you can also add an additional interface (apart from the NAT one) and set it to host-only. That will make a new interface appear on your host system, and you can use the private IPs VirtualBox reserves for this network to communicate with the guest. Step-by-step:
- Shut down the VM.
- Right click the VM in the Manager and select
Settings.
- Go to the
Network tab.
- Configure two interface: One as NAT (to allow your VM to access the internet), the other as Host-only (to allow your host to communicate with the guest).
- Boot the VM, and type
/sbin/ifconfig to find out its address. You want the one starting with 192.168..
- Use that address on the host system.