Knowledge BaseSystem NetworkHow to set up a Static IP for a Virtual Machine (CentOS)

How to set up a Static IP for a Virtual Machine (CentOS)

The following lists steps to set up a Static IP for a Metric Insights Virtual Machine (CentOS). Note, you will have to get the IP from the customer's network administrator.


We've deployed the Metric Insights OVA in our virtual player, but company policy dictates that we not use a Bridged connection. We must use NAT instead and our network administrator has provided us with an IP for the VM. How do we set this up?


To set up a Static IP, please follow the steps below in the VM. Ensure you have the static IP, gateway, and netmask to properly configure the VM:


1.) From the command line, make a backup of the network card file ifcg-eth0 or ifcg-enp0s3 in /etc/sysconfig/network-scripts/ then proceed with making changes to either file (the file repesent depends on the CentOS release):

# cp /etc/sysconfig/network-scripts/ifcfg-eth0  /etc/sysconfig/network-scripts/ifcfg-eth0.bak

# vim /etc/sysconfig/network-scripts/ifcfg-eth0


2.) Make the following changes to ifcg-eth0 in the vim editor: 

NAME="System eth0"

Only the parameters BOOTPROTO, IPADDR, NETMASK, and GATEWAY have to be adjusted (or added if missing). You do not have to edit the other lines.


3.) Next, edit /etc/sysconfig/network:

# vim /etc/sysconfig/network

Add the following entries:


4.) After configuring the IP, we now need to configure DNS. This can be done in /etc/resolv.conf:

# vim /etc/resolv.conf

Add or edit the following nameserver entries:


You can add two or more nameserver entries. The VM will try the second one in case the first nameserver is unreachable.


5.) Add the IP and hostname in /etc/hosts:

# vim /etc/hosts   localhost localhost.localdomain localhost4 localhost4.localdomain4  

Note, the new hostname will only be applied after a system reboot.  6.) To apply the network changes, enter the following command:

# services network restart

7.) After the network service restart you can confirm the static IP has been applied to the VM by running:

# ifconfig

You should see an output like this: ifconfig 
eth0      Link encap:Ethernet  HWaddr 20:89:84:c8:12:8a  
          inet addr:  Bcast:  Mask:
          inet6 addr: 2001:db8::c0ca:1eaf/64 Scope:Link
          RX packets:200197 errors:0 dropped:67 overruns:0 frame:0
          TX packets:69689 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:64103748 (64.1 MB)  TX bytes:14106191 (14.1 MB)

lo        Link encap:Local Loopback  
          inet addr:  Mask:
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:10365 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10365 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:875114 (875.1 KB)  TX bytes:875114 (875.1 KB)

You should be able to reach the Metric Insights UI now by entering the IP in your web browser. Also, you can check for Internet access from the VM by pinging an external website like Note, if the network administrator has restricted internet access from the NAT network, you will be unable to ping the internet.