Knowledge BaseMetric InsightsSystemNetworkHow 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.

ISSUE

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?

SOLUTION

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: 

DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=20:89:84:c8:12:8a
TYPE=Ethernet
BOOTPROTO=static
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
IPADDR=192.168.90.1
NETMASK=255.255.255.0
GATEWAY=192.168.90.254

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:

NETWORKING=yes
HOSTNAME=company_name.metricinsights.com
GATEWAY=192.168.90.254


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:

nameserver	8.8.8.8
nameserver	8.8.4.4

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

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
192.168.90.1   company_name.metricinsights.com  

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:

root@company_name.metricinsights.com:~# ifconfig 
eth0      Link encap:Ethernet  HWaddr 20:89:84:c8:12:8a  
          inet addr:192.168.90.1  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: 2001:db8::c0ca:1eaf/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          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:127.0.0.1  Mask:255.0.0.0
          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 google.com. Note, if the network administrator has restricted internet access from the NAT network, you will be unable to ping the internet.