Sometimes there is a need to have a server (maybe for development) with a static IP address.
-
Download Ubuntu server – in my case the 64-bit 14.04.1 iso.
-
Install it into a Virtualbox VM as per normal. The only thing that I make sure to do is install the OpenSSH server.
-
The installation process reboots. At that stage I will log in through the VM directly to sort out the networking. By default, Virtualbox always seems to give the guest an IP address on eth0 of 10.0.2.15.
-
First confirm that you have internet access and can resolve DNS names by ping'ing a familiar site:
ping 8.8.4.4
This is one of Google's DNS servers. You should get packets. Use CTRL-C to end.
-
Next try a domain name such as:
ping google.co.nz
Again, use CTRL-C to end.
-
If that confirms for you that you have internet connectivity then you can start to look at making the guest VM's IP address static. Open up the networking configuration file:
sudo nano /etc/network/interfaces
-
Change the line says dhcp to static and also add some details for your IP address and network so it looks something like this:
iface eth0 inet static address 192.168.1.139 # this corresponds to the IP you want to assign netmask 255.255.255.0 # defining the subnet gateway 192.168.1.1 # the IP address of the router as gateway -
Now we need to change the DNS resolving. To do this (apparently) it is safest to edit the resolv head file:
sudo nano /etc/resolvconf/resolv.conf.d/head
Even though it says something like 'your changes will get overwritten', this is the place to make the update. Add in a domain name such as this:
nameserver 8.8.4.4 # google DNS
-
Now we need to maintain the settings of VirtualBox for the guest. Go to Devices > Network > Network Settings. In the dialogue, change your network adapter (in my case eth0) from NAT to Bridged Adapter:
We are essentially making the Guest a member of the same network as other machines assigned by DHCP from the router. -
With that all done it is time to reboot so within the Guest VM issue the command:
sudo reboot
-
Time to run a few tests. First, confirm the IP address is okay with:
ifconfig
It should tell you that eth0 is on 192.168.1.139.
-
Next ping google's DNS by issuing:
ping 8.8.4.4
It should reach the server on the outside world.
-
Do the same, but use domain name resolving by issuing:
ping google.co.nz
Hopefully now you have a working connection for your VM with a static IP address.
-
Let's try accessing the Guest from another machine on the network (say, the Host machine in my case) using SSH. Fire up a console and enter:
ssh brendon@192.168.1.139
-
Modify the username and IP address as necessary. You will likely be prompted by SSH as to whether you really want to connect to the machine:
The authenticity of host '192.168.1.139 (192.168.1.139)' can't be established. ECDSA key fingerprint is 7d:c5:4d:70:bd:82:b2:7d:60:06:57:80:57:80:35:93. Are you sure you want to continue connecting (yes/no)?
Type 'yes' to complete the connection.
-
You should now be prompted for the user's password on the Guest machine:
Warning: Permanently added '192.168.1.139' (ECDSA) to the list of known hosts. brendon@192.168.1.139's password:
Enter the password and correctly and you will be logged into the Guest and welcome page should be displayed:
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-32-generic x86_64) * Documentation: https://help.ubuntu.com/ System information as of Mon Feb 16 23:11:49 NZDT 2015 System load: 0.08 Processes: 85 Usage of /home: 0.2% of 3.59GB Users logged in: 0 Memory usage: 3% IP address for eth0: 192.168.1.139 Swap usage: 0% Graph this data and manage this system at: https://landscape.canonical.com/ 7 packages can be updated. 3 updates are security updates. Last login: Mon Feb 16 23:02:56 2015 brendon@dev:~$
Now is a good time to upgrade your installation. I like to use aptitude:
sudo aptitude update
sudo aptitude safe-upgrade
And we are done! (at least for the first part...)