Setting Up Networking For An Ubuntu 16.10 Server in VirtualBox

At https://dronze.com we use use virtualbox to do local development is great. I use it so I can emulate configurations that I would normally have to do in aws. This is a simple guide to setting up a server on your laptop that be sshed into and can access the internet.

Setting up the Vbox Instance

I downloaded the iso from the Ubuntu 16.10 download site and mounted it as an optical drive for the install.

Setup The Network Adapters

Set the VirtualBox Preferences for Networking

Setting Up Networking On Your Instance

You will now be able to ssh into your instance. Use the ip address that has been allocated for the Host-Only adapter:

clay@ubuntu-vbox:~$ ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.99.100 netmask 255.255.255.0 broadcast 192.168.99.255
inet6 fe80::a00:27ff:fe98:648e prefixlen 64 scopeid 0x20<link>
ether 08:00:27:98:64:8e txqueuelen 1000 (Ethernet)
RX packets 153 bytes 17965 (17.9 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 104 bytes 13118 (13.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 332 bytes 24748 (24.7 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 332 bytes 24748 (24.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

In our case it is 192.168.99.100 so we ssh into the instance with the user and password we used when we installed ubuntu 16.10

$ ssh clay@192.168.99.100
clay@192.168.99.100's password:
Welcome to Ubuntu 16.10 (GNU/Linux 4.8.0-22-generic x86_64)
* Documentation:  https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
99 packages can be updated.
45 updates are security updates.
Last login: Wed Feb 15 17:19:53 2017 from 192.168.99.1
clay@ubuntu-vbox:~$

Now we want to list the available adapters, in our case it is enp0s3 & enp0s8

clay@ubuntu-vbox:~$ ls /sys/class/net
enp0s3 enp0s8 lo

You will now use this to edit the interfaces file and bind your host only to the NAT.

clay@ubuntu-vbox:~$ sudo vi /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback
# Host-only interface
auto enp0s3
iface enp0s3 inet static
192.168.99.1
address 192.168.99.100
netmask 255.255.255.0
network 192.168.99.0
broadcast 192.168.99.255
# NAT interface
auto enp0s8
iface enp0s8 inet dhcp
clay@ubuntu-vbox:~$ sudo reboot now

Reboot the instance and ssh back in. Now your adapter should be visible to ifconfig:

clay@ubuntu-vbox:~$ ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.99.100 netmask 255.255.255.0 broadcast 192.168.99.255
inet6 fe80::a00:27ff:fe98:648e prefixlen 64 scopeid 0x20<link>
ether 08:00:27:98:64:8e txqueuelen 1000 (Ethernet)
RX packets 153 bytes 17965 (17.9 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 104 bytes 13118 (13.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 10.0.3.15 netmask 255.255.255.0 broadcast 10.0.3.255
inet6 fe80::a00:27ff:fe87:7e00 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:87:7e:00 txqueuelen 1000 (Ethernet)
RX packets 19 bytes 2686 (2.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 35 bytes 3392 (3.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 332 bytes 24748 (24.7 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 332 bytes 24748 (24.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

And you should be able to reach the internet:

clay@ubuntu-vbox:~$ ping yahoo.com
PING yahoo.com (98.139.183.24) 56(84) bytes of data.
64 bytes from ir2.fp.vip.bf1.yahoo.com (98.139.183.24): icmp_seq=1 ttl=63 time=59.0 ms
64 bytes from ir2.fp.vip.bf1.yahoo.com (98.139.183.24): icmp_seq=2 ttl=63 time=58.6 ms

Hope this helps…