VirtualBox Configure a Static IP on CentOS 7


In my job I have to create several virtual machines every month (each for a new project). We need a static ip to access our web application in browser even if Wi-Fi is not available (mostly while traveling or at the client site).

Our OS, Software and Version

Let's see how to setup Static IP on CentOS with Oracle VM VirtualBox.

Step 1: Before Creating a New Virtual Machine

Before we start, we need to check the 'DHCP Server' is enabled or not for 'VirtualBox Host-Only Ethernet Adapter'. If it is not available, you can create it. Select Network via Tools (Three Line Menu). Now you can see 'VirtualBox Host-Only Ethernet Adapter' Properties. (If it is not available, you can create it.) See (or check) the Adapter and DHCP Server settings as given in the following picture. Make a note of Lower Address Bound and Upper Address Bound values.

Step 2: Create Virtual Machine

Please follow the steps as per the images.

Important: Before first-start, please enable the Network Adapter 2 - Attached to 'Host-only Adapter and Select the Name 'VirualBox Host-Only Ethernet Adapter' (see Image 7)

Step 3: Start Virtual Machine

  • Select start-up disk CentOS-7-x86_64-Minimal-1810.iso -> Start
  • Install CentOS 7
  • What language would you like to use during the installation process? Choose default and click on Continue.
  • Click Installation Destination and Select 'Local Standard Disks' and Done.
  • Now you can see 'Begin Installation' button highlighted in Blue color, click on it.
  • Click on Root Password and set it (click on Done)
  • Once CentOS 7 installation process finished, click on 'Reboot' button.

Step 4: Configure a Static IP on CentOS

  • Login with 'root' user.

  • Edit ifcfg-enp0s3 file as per the following code. (In vi editor, use 'i' for insert, 'esc' key to enter command mode and 'wq' for save and quit)

vi /etc/sysconfig/network-scripts/ifcfg-enp0s3

ONBOOT=yes
USERCTL=no
  • Edit ifcfg-enp0s8 file as per the following code. (Note. IPADDR value should be in between Lower Address Bound and Upper Address Bound values)

vi /etc/sysconfig/network-scripts/ifcfg-enp0s8

BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.56.141
PREFIX=24
  • Restart network
systemctl restart network
  • Test with the ping command, try it in a Windows Command Prompt window (CMD).
Microsoft Windows [Version 10.0.17763.253]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\tutorial>ping 192.168.56.141

Pinging 192.168.56.141 with 32 bytes of data:
Reply from 192.168.56.141: bytes=32 time=1ms TTL=64
Reply from 192.168.56.141: bytes=32 time<1ms TTL=64
Reply from 192.168.56.141: bytes=32 time=1ms TTL=64
Reply from 192.168.56.141: bytes=32 time=1ms TTL=64

Ping statistics for 192.168.56.141:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms

Bonus Tip

  • Disable firewall on CentOS.
systemctl stop firewalld.service && systemctl disable firewalld.service
  • Disable SELINUX vi /etc/sysconfig/selinux
# SELINUX=permissive
SELINUX=disabled
  • Reboot your virtual machine!

Happy Coding!
My Facebook Page - Python Machine Learning