SSH to VirtualBox 3 FreeBsd Guests

This post is based on “Howto: SSH into VirtualBox 3 Linux Guests” by Stuart Colville, which I have updated to work for FreeBSD Guests: In older versions of VirtualBox one had to use a bridge interface to make this work. However, in newer versions; a virtual interface can be added to the Host by default, which make it way easier to access the guest machine through the host.

Usually, you have a primary network interface which uses NAT adapter, that one is needed for connecting to the Internet. What we are going to do is to add an additional interface to the guest machine. All you have to do is to access the settings of the guest when it is off.  Select Network->Adapter 2, then check the “Enable Network Adapter” as shown below. Change “attached to” to “Host-only Adapter” this will have the name vboxnet0 by default.

[][1]

Now if you do ifconfing on your host machine (On Windows hosts use ipconfig), there will be a new interface called *vboxnet0 *(same as the virtual adapter name you just added). You will notice the IP address is something similar to this:

inet addr:192.168.56.1  Bcast:192.168.56.255  Mask:255.255.255.0

Which means his interface can access all the IP addresses in the following range: 192.168.56.1-192.168.56.254. This is needed to setup the guest interface properly.

Now, boot the FreeBsd guest. If you do *ifconfig on your guest machine, *You will notice that a second interface has been added to your machine (The name is *em1 *if you already had one interface). You have to configure the new interface; so you can access it by your host machine. We will set a static IP address for this interface using the IP range above.

Next add the following lines to “/etc/rc.conf” in your guest machine:

ifconfig_em1="inet 192.168.56.10 netmask 255.255.255.0"

Save this and run the following command to restart the network interfaces:

/etc/rc.d/netif restart 

If you have not enabled SSH on your FreeBsd guest yet, edit /etc/rc.conf and add the following:

sshd_enable="YES" 

and then run:

/etc/rc.d/sshd start 

That’s it, now you should be able to ssh to your guest machine by:

ssh saman@192.168.56.10 

.

[1]: http://www.samanbarghi.com/wp-content/uploads/2011/02/VirtualBox-FreeBsd.png

comments powered by Disqus