You have a list of VirtualBox networking modes in its Documentation.
The one you need on both systems is Internal networking. You have to give it a name, you can create several networks in this mode. VirtualBox will connect all guests in the same internal network, so names must match on both virtual machines. The default should work right out-of-the-box.
The server needs an Internal networking with the same name and another one which connects to the world, in your case NAT.
Now the guest server should be able to connect to the internet through the NAT interface.
Give IPs to the machines
In order to the client and the server reach each other, their interfaces must be configured in the same network. You can do it manually (static addresses) or configuring a DHCP server in the server machine.
These are the steps to do it manually:
root@server:~# ifconfig eth0 192.168.1.1 netmask 255.255.255.0
root@client:~# ifconfig eth0 192.168.1.5 netmask 255.255.255.0
You can set any IP you want, but they must be in the same network. Here,
eth0 in the server machine refers to the Internal interface, if you set interface 1 as Internal and 2 as NAT, the above commands will work fine.
Now you should be able to
ping each other, but packets from the client machine won't be able to travel through the server machine yet, only to the server.
Note: These changes will be lost at next reboot, to make the changes permanent you have to edit and configure
/etc/network/interfaces. If you are configuring the client with GUI from the desktop, skip the CLI configuration.
You need to configure forwarding. You could simply do
root@server:~# echo 1 > /proc/sys/net/ipv4/ip_forward
but this would only work until you reboot the machine. You need to edit
/etc/sysctl.conf and uncomment
so it looks like:
# Uncomment the next line to enable packet forwarding for IPv4
This will configure the server machine to forward packets (at next reboot).
This will configure the server to do IP masquerading.
root@server:~# modprobe iptable_nat
root@server:~# iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
root@server:~# iptables -A FORWARD -i eth0 -j ACCEPT
Take care about
eth1, here the 2nd line must be
-o NAT_interface and the 3rd line
Configure the client to go through the server
This setting should have been already set, either in the GUI assistant or by editing
/etc/network/interfaces/. Just in case it is not applied, add the default route through the server machine:
root@client:~# route add default gw 192.168.1.1
Now you should be able to communicate from the client machine, but if you configured the IP addresses manually, you still need to provide the DNS servers so you can resolve names.
/etc/resolv.conf and add the servers you like:
If you configured DHCP in the server machine, you should have already told the DHCP server which DNS servers to use (if not, do it now).
Again, if you configured the client with a GUI assistant, just make sure the DNS are valid and skip this section.