Centos on Mac with Virtual Box
If you want to learn how to administer a Linux server or have a need to test your application on a specific Linux distribution, a good point of start is to virtualize it locally using VirtualBox. This post explains how get CentOS up and running on OS X. Our goal here is to install minimal Linux server and access it for administration via ssh from your Host operating system. We will also enable the Guest system to act like a web server.
If you don't have VirtualBox already go to download page and install it.
To get an image of CentOS go here and choose the version you want (I went for
6.5) by clicking on
x86_64 then pick one of the mirror servers for downloading the desired image (my choice was
Nameof you choice, Linux for
Type, Red Hat 64 bit for
Create a virtual hard drive now
Processor: set 2 cores.
Storage Treeframe. In
Attributessection browse to your iso by clicking the cd icon.
start(the green arrow) - this will start the installation process in graphical mode.
basic storage devicesbutton.
replace existing linuxin one of the following screens.
After rebooting log in in the terminal with the
root user and the password you created during installation.
If you run
ifconfig in the Guest console, the only network interface listed is
lo (loopback device). The first action to take in this case will be setting up another two interfaces: one for accessing the Internet, second for connecting the Guest Linux from your Host OS via ssh.
eth0 (access to the network) edit
/etc/sysconfig/network-scripts/ifcfg-eth0 and change
yes. Restart the network service by running:
service network restart. You can check your internet connection with
ping centos.org (all must be done as root, not via sudo).
Shut down your Guest VM.
Preferences, pick the
Network and Host-only Network tab. Click plus on the right hand (Add host-only network) to create
Then go to your Guest VM settings, tab
Adapter 2. Click
Enable Network Adapter and choose
Now boot up your Guest VM, navigate to
/etc/sysconfig/network-scripts/ and create a new file
ifcfg-eth1 with the following content:
DEVICE=eth1 BOOTPROTO=static IPADDR=192.168.56.101 NETMASK=255.255.255.0
The last thing will be opening port 22. Go to the Guest VM settings -
Network - Adapter 1 -
port forwarding -
add and set Host and Guest ports to 22.
Now you should be able to connect to your Guest VM from your Host OS terminal:
ssh email@example.com with the root password.
From now on you can administrate the CentOS server without switching to the VirtualBox instance console.
First you have to open port 80 on your Guest machine. To to this edit the file
/etc/sysconfig/iptables and add the following line:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT.
Restart the network service:
service network restart.
To test the server you can use python's SimpleHTTPServer: create a new folder for storing your http content, for example
/var/www and place there a new
index.html file with a content of your choice.
python -m SimpleHTTPServer 80. This command will start a http server listening on port 80.
If you navigate a browser to
http://192.168.56.101 you should be able to see the content of your index.html file.
To take the burden of remembering the IP number off your memory, let's create an easy to remember host name, both for ssh and http access.
/etc/hosts file (on your Host) and attribute the IP an easy to remember name, for example:
Now you can access your Guest VM by
ssh firstname.lastname@example.org and check the web server using the
If you've come so far, it means that you have succesfully installed your Linux distribution. Now you are ready to dig for more information about how to install the technology stack of your choice.