Assign IP to VM

By | August 16, 2014
Assigning IP to VM:

We saw how to set up a VM in tutorial -> Create CentOS VM

Currently We don’t have an IP for our VM. It looks like below before we assign an IP

To assign IP to VM, Click on vm instance Ex: “host1” -> Settings

Edit -> Virtual Network Editor

Restart the VM
Enable Ethernet by clicking on “System eth0”

We now have an IP associated with our VM:

You can now reach VM from your host OS (or) any computer in the network:

We have dynamic IP for our VM now.

Now lets see how to assign static IP to our VM

## Configure eth0


# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED=no
ONBOOT=yes
HWADDR=A4:BA:DB:37:F1:04
TYPE=Ethernet
BOOTPROTO=static
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
IPADDR=192.168.1.40
NETMASK=255.255.255.0

Start the “network” service at run-level 5

 $sudo chkconfig --level 5 network on 

## Configure Default Gateway


# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=host1.goldhost.com
GATEWAY=192.168.1.1

## Configure DNS Server


# vi /etc/resolv.conf
search goldhost.com
nameserver 8.8.8.8 

## Restart Network Interface


# /etc/init.d/network restart

Comment below if you find this blog useful.

Reference: https://gist.github.com/fernandoaleman/2172388

Leave a Reply

Your email address will not be published. Required fields are marked *