Configure Static IP Address on Linux VM in VMware Player

If you run VMware Player, you would have 3 networking options for virtual machines running there: Bridged, NAT, Host-Only. In the latest 5.0.1, I also found a new one: LAN Segment. This blog has a nice explanation on these three settings if you want to get more details.

In most of cases, I use NAT for networking because the virtual machine can have Internet access which allows me to install additional software as needed. By default, VMware Player uses DHCP to dynamically assign IP address while using NAT. So you cannot guarantee to get same IP address after each rebooting.

You can set static IP address for a VM running on VMware Player with a little trick. On a Debian Linux machine like Ubuntu, you can edit a configuration file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ sudo vim /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5)
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
  address 192.168.47.200
  netmask 255.255.255.0
  broadcast 192.168.47.255
  gateway 192.168.47.2
dns-nameservers 192.168.47.2

After saving the file, you would like to restart the network so that the change take effect:

1
$ sudo service networking restart

In my case, the VMnet8 which is the network adapter for the NAT network has an IP address of 192.168.47.1. When I first modified the interfaces file, I used it as the gateway IP address and failed to ping outside the network.

To figure it out why, I reversed back to the DHCP configuration (change the ifacce line to “iface eth0 dhcp” and delete the lines afterwards). In the DHCP mode, typing command “route –n” will show working gateway IP address: 192.168.47.2.

By default, the gateway IP is configured to use X.X.X.2. This can be changed with Virtual Network Editor which is not included in VMware Player. I will show you how to hack it in next post.

Update: for Fodera Linux like RedHat, CentOS, you can configure static IPs as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## define eth0 interface
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
 
DEVICE=eth0
NM_CONTROLLED=no
ONBOOT=yes
HWADDR=00:50:56:37:F1:04
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.1.8
NETMASK=255.255.255.0
 
## set Default Gateway
# vi /etc/sysconfig/network
 
NETWORKING=yes
HOSTNAME=web.example.com
GATEWAY=192.168.1.1
 
# Restart Network Interface
# service network restart
# chkconfig network on
# service NetworkManager stop
# chkconfig NetworkManager off
 
## Configure DNS Server
#
# vi /etc/resolv.conf
nameserver 192.168.1.1
nameserver 8.8.8.8    # Google's DNS server

If you run into issue with cloned virtual machine changes eth0 to eth1, you can

1
2
# rm -f /etc/udev/rules.d/70-persistent-net.rules
# reboot

Update: for SUSE Linux which is used by vCenter virtual appliance, the static IP address can be changed as follows:

1
2
3
4
5
6
7
8
9
vCSA:~ # vim /etc/sysconfig/network/ifcfg-eth0
DEVICE=eth0
BOOTPROTO='static'
STARTMODE='auto'
TYPE=Ethernet
USERCONTROL='no'
IPADDR='192.168.1.8'
NETMASK='255.255.255.0'
BROADCAST='192.168.0.255'
This entry was posted in Virtualization and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

6 Comments

  1. Posted March 12, 2013 at 12:35 am | Permalink

    Configure Static IP Address on Linux VM in VMware Player (DoubleCloud) http://t.co/r1IcxPEyyX

  2. Posted March 12, 2013 at 12:50 am | Permalink

    Configure Static IP Address on Linux VM in VMware Player (DoubleCloud) http://t.co/QuU2rFQMxN

  3. Posted March 12, 2013 at 2:35 am | Permalink

    VMware – big fan “@sjin2008: [DoubleCloud] Configure Static IP Address on Linux VM in VMware Player http://t.co/BBlX6Shpp9” #VMware

  4. tako
    Posted October 7, 2014 at 9:14 am | Permalink

    this helped me a lot, thx

  5. Saha
    Posted November 18, 2014 at 9:21 am | Permalink

    Hello,
    I create an webservice (JAVA) and application side (PHP) to manage our pool of VM’s and automate some actions. Particullary, I create a form to deploy a virtual machine and its network configuration (with XML autogeneration – CustomizationSpec).
    Since Ubuntu 14.04, I noticed that the attributes dns-nameservers and dns-search are not fill depsite they are correctly added to the XML.

    I am aware about Ubuntu 14 changes its politic about networking but I wonder why these attributes are no longer deployed, some one get en axplication ? Ty in advance.

  6. Posted November 18, 2014 at 11:01 pm | Permalink

    Hi Saha,
    Thanks for the update. Sorry to know it doesn’t work any more. Have you checked if VMware has a newer version of its VMware Tools?
    Steve

2 Trackbacks

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • NEED HELP?


    My consulting helps clients with virtualization and cloud computing, including VMware infrastructure automation and orchestration, vSphere management APIs, and deep product integration with hypervisors. Current training offerings include vSphere APIs training, vCenter Orchestrator training, and etc. Should you, or someone you know, need these consulting services or training, please feel free to contact me: steve __AT__ doublecloud.org.

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.