Quantcast
Viewing all articles
Browse latest Browse all 190

Notes on Virtualbox 4.3.30 and OS X 10.8.5 for CentOS 7

Virtualbox 4.3.30 on OS X 10.8.5 with CentOS 7 guest VMs work ok on my notebook for web development, but setup was a little fussy.

I use VMs for:

  1. general web development and testing, to stay off the production environment
  2. destructive performance testing (intrusive changes to source code and configurations that require VM rollback to undo, most of which will never be commmitted.) This is great for work on profiling, i18n, caching, mod_rewrite rules, etc.
  3. accelerating automation testing, since a VM can boot in 10 seconds on my Mac with SSD, and VM creation is scriptable. This is a huge win.
  4. working offline (no-Wifi areas.)

Terminology

  • “Host” is your Mac notebook. It runs Virtualbox under Mac OS X.
  • “Guest” is the VM running under Virtualbox. A guest can be any operating system, but in this case we’re using CentOS 7.x.

Getting Started

  • check Internet for known software issues first
  • update to the latest version of Virtualbox

Choose Network Topology

I wanted to run my web site in a VM, viewable from the Mac browser and have the VM be able to run ‘yum update’, so needed host => guest and guest => Internet routing. There’s 2 networking choices that match those requirements:

  1. Bridged – easiest and works best if a Mac network adapter is always connected, like in the office, or at home if your Wifi access point is always on
  2. NAT – always works, but you have to NAT from host => guest (ie. 127.0.0.1:8000 => 10.0.0.5:80). You can use Mac’s ipfw or ipf firewalls to then NAT from 80 to 8000, making it seamless:

    sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to any 80 in

Bridged

  • under “Machine … Settings”, choose “Bridged Adapter”
  • guest IP address will come from Virtualbox DHCP server, usually the guest IP address is 192.168.56.101
  • on the host, you just use the guest’s real IP address from above
  • if you bridge to the Airport interface (en0), and the host Wifi is off, you lose your guest lease (ie. no routing inside or outside guest VM)
  • binds to a host’s physical interface (conceptually speaking)
  • no NAT needed or available in Virtualbox settings
  • the Virtualbox DHCP address is 192.168.x.100

NAT

  • under “Machine … Settings”, just choose NAT, not “NAT Network”
  • guest IP address will come from Virtualbox DHCP server, usually 10.0.0.5 or 10.0.2.15
  • host IP address will be 127.0.0.1 (NATTed to guest address above)
  • click on “Port Forwarding” button and use host ports above 1024 (usually 2222 for ssh and 8000 for HTTP)

Troubleshooting

  • the Virtualbox manual is a reference, not a tutorial. After reading this blog post, the manual is useful to fill in details.
  • disable CentOS 7 firewall with ‘service firewalld stop’
  • view CentOS 7 interfaces with ‘ip a’
  • if one networking topology doesn’t work for you, try another. No need to reboot the VM.
  • if you spend more than an hour without success, try VMware Fusion. It covers my use case automatically.

Exercises

  • do ‘tail -f /var/log/messages’, disable “Cable Connected”, click “OK”, and watch as DHCP lease is lost. Then click on “Cable Connected”, click “OK” to restore
  • if using Bridged on en0, do ‘tail -f /var/log/messages’, do “Turn Wi-fi Off” on Mac, and watch as DHCP lease is lost. Then turn Wifi back on.

Network Security

  • use strong passwords if you value what’s inside the VM
  • enable guest firewall with ‘service firewalld start’
  • TCP wrappers is an easy and effective filtering method
    /etc/hosts.allow:

    sshd: 10.0.0.0/255.0.0.0 192.168.0.0/255.255.0.0
    http: 10.0.0.0/255.0.0.0 192.168.0.0/255.255.0.0

    /etc/hosts.deny:

    ALL: ALL

Simulating Production

You can update /etc/hosts to have your browser access your web site in a VM:

/etc/hosts:

# NAT
127.0.0.1 www.mysite.com
or
# Bridged
10.0.0.5 www.mysite.com

But I find that Firefox gets less confused with permanent redirects, etc. by prefixing the hostname:

/etc/hosts:

# Virtualbox NAT Topology (don't forget to use ports 2222 and 8000 from host => guest!)
#127.0.0.1 www.test-mysite.com
or
# Virtualbox Bridged Topology
#10.0.0.5 www.test-mysite.com
#10.0.2.15 www.test-mysite.com

Backups

Take advantage of Virtualbox’s clone and snapshot features.

forums.virtualbox.org: What does “Cable connected” checkbox change?
Port Forwarding in Mac OSX Mavericks
Port Forwarding in Mac OS Yosemite


Viewing all articles
Browse latest Browse all 190

Trending Articles