Hi all, In this post we will review the procedure of setting up the FreeBSD environment on VirtualBox along with setting up Internet on the guest OS(this was pretty tricky!).BTW, my host OS is Ubuntu 14.04
So, I am assuming you have already installed VirtualBox as per your host OS and has downloaded the FreeBSD amd64 iso image(If not you can do it from here and extract it appropriately to get a .iso file.
Installing FreeBSD on VirtualBox
Installing FreeBSD on virtual box is pretty straight forward, just insert use the downloaded iso to boot up the VM with default hardware settings for 64 bit FreeBSD OS. Following will be the bootup window:
Just press enter and follow the default procedure. Don’t attempt to configure network adapter at this stage we’ll do it later after complete installation.
Note: Please don’t forget to remove the installation disc from virtual machine settings after complete installation. Otherwise, every time during bootup it will recall the install procedure.
Setting up Internet
We will be setting up host-only adapter. Here are the common disadvantages of different type of network adapter types available:
Requires port forwarding if you want to connect to the VM from the host.
The VM can not access the internet unless the host is a router.
Exposes the vm to the network; not portable.
Adding a VirtualBox Host-only adapter
In VirtualBox > Preferences > Network, set up a host-only network.
Click on the screwdriver icon to edit the adapter settings. Add a new adapter if vboxnet0 isn’t available
Disable DHCP server. Click on Ok and reboot the machine.
Also, on machine settings under network tab, select the settings as shown:
On host OS(Ubuntu)
sudo su iptables -A FORWARD -o wlan0 -i vboxnet0 -s 192.168.56.0/24 -m conntrack --ctstate NEW -j ACCEPT iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT iptables -t nat -F POSTROUTING iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
After these, you can verify the configuration by netstat and iptables as
uka_in@Madaari:~$ sudo iptables -L | grep 192.168.56.0 ACCEPT all -- 192.168.56.0/24 anywhere ctstate NEW uka_in@Madaari:~$
uka_in@Madaari:~$ netstat -r Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface default www.mblaze.home 0.0.0.0 UG 0 0 0 wlan0 172.17.0.0 * 255.255.0.0 U 0 0 0 docker0 192.168.1.0 * 255.255.255.0 U 0 0 0 wlan0 192.168.56.0 * 255.255.255.0 U 0 0 0 vboxnet0 uka_in@Madaari:~$
On Guest OS(FreeBSD)
First, check the interfaces available to FreeBSD by ifconfig:
so, my interface name is em0.
Then, we need to edit rc.conf file by ee /etc/rc.conf and add the below line to rc.conf
ifconfig_em0="inet 192.168.56.101 netmask 255.255.255.0"
So, finally here’s how my rc.conf looks like:
Then reload the configurations by running /etc/rc.d/netif restart
Now final thing needed to be done is adding a default gateway which can be added like :
route add default 192.168.56.1
That’s it. It should now work! try ping 188.8.131.52.
Configuration can be verified by netstat as:
Notice the gateway mentioned. If the gateway is not correctly setup errors like “no available route” will appear. Try pinging 192.168.56.1, if it worked and you still have no internet access you probably did some misconfig during packet forwarding in ubuntu.
The above procedure works for me, however, I had several issues while trying out other tutorials on the internet. I guess, the best thing that helps me debug out the problem was, Wireshark! It’s really awesome. Don’t hesitate to debug out problems and comment here with a complete log in case of failure. Thanks.
Several common errors/issues:
Initially, with raw installation switching to root will give this error. One possible solution for this is to boot FreeBSD in single-user mode and then enter the following commands:
mount -u -w / pw usermod your_user_name -G wheel
and now, switching to root should work!
SSH From Host(Ubuntu) to Guest OS(FreeBSD in VirtualBox)
For this, you should first have sshd_enable option enabled in your /etc/rc.conf file.
Then you need to add a port forwarding rule to VirtualBox network option like:
Now simply try ssh from your host machine like: ssh -p 2222 email@example.com . If it shows ssh_exchange_identification: read: Connection reset by peer error try reloading rc.conf settings or restart the guest os.