2015-11-01

Static IP address in CentOS in VirtualBox

* Env
Host: Windows 7 with internet access
Hypervisor: VirtualBox v5.x
Guest OS: CentOS v7.x (Following config should work for other Linux distributions with systemd, e.g., Debian v8.x, Ubuntu v15.x, etc.)

* Requirement
Guest OS should be able to access internet with minimal config.
Host OS should be able to acess Guest OS without port forwarding.

* How to
1. Install Guest OS using NAT (not "NAT Network").
media: CentOS-7-x86_64-NetInstall-1503.iso

In CentOS installer,
- turn on the ethernet, getting dynamic IP address 10.2.0.x.
- set the Installaion Source to /centos/7/os/x86_64/, e.g., http://mirror.optus.net/centos/7/os/x86_64/

Cf https://www.centos.org/download/mirrors/
2. In the new virtual machine Setting --> Network, enable Adapter 1 and Adapter 2, choose NAT (not "NAT Network") for Adapter 1, Host-only Adapter for Adapter 2.

3. Reboot CentOS. In CentOS, check the IP address using "ip a" command to find device name and MAC address for Adapter 2, and create network script for the device.

For example, if enp0s8 is the device name for the host only adapter, create /etc/sysconfig/network-scripts/ifcfg-enp0s8 file as follows.

TYPE=Ethernet
DEVICE=enp0s8
HWADDR=08:00:27:FA:F6:6A
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.56.101
NETMASK=255.255.255.0

Cf https://wiki.centos.org/FAQ/CentOS7

In Ubuntu, add next to /etc/network/interfaces.
auto enp0s8
iface enp0s8 inet static
    address   192.168.56.101
    netmask   255.255.255.0
    network   192.168.56.0
    broadcast 192.168.56.255

-----------------------------------

To run docker in CentOS 7.x,
- disable selinux
- run
chkconfig docker on

Cf https://docs.docker.com/installation/centos/