Home > Virtualization > Configure Static IP Address on Linux VM in VMware Player

Configure Static IP Address on Linux VM in VMware Player

March 12th, 2013 Leave a comment Go to comments

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.

Time to learn how to "Google" and manage your VMware and clouds in a fast and secure

HTML5 App

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'
  1. March 12th, 2013 at 00:35 | #1

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

  2. March 12th, 2013 at 00:50 | #2

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

  3. March 12th, 2013 at 02:35 | #3

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

  4. tako
    October 7th, 2014 at 09:14 | #4

    this helped me a lot, thx

  5. Saha
    November 18th, 2014 at 09:21 | #5

    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. November 18th, 2014 at 23:01 | #6

    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

  7. December 11th, 2014 at 12:12 | #7

    This worked great for me Steve! Saved my butt when working on my VM daily. Thanks!

  8. December 11th, 2014 at 13:52 | #8

    Great to know Rob, glad it helped.

    Steve

  9. xiaofeng
    July 10th, 2015 at 07:54 | #9

    Dear Steve
    I come across your article while trying to setup my VM NAT using static IP. I am using VMPlayer 7.1.0. and downloaded vmnetcfg.exe from https://ninety9names.wordpress.com/2013/12/18/download-vmnetcfg-exe-vmnetcfglib-dll-for-vmware-player-6-x-7-x/.

    My VM OS is Scientific Linux 6. From vmnetcfg.exe I set
    VM IP 192.168.230.100
    Subnet Mask 255.255.2555.0
    Default gateway 192.168.230.2

    For NAT setting, I have Map incoming port
    Host port 600;
    TCP
    VM IP 192.168.230.100; port 600

    On my Linux side, I modified
    /etc/sysconfig/network-scripts/ifcfg-eth0
    {
    DEVICE=eth0
    NM_CONTROLLED=no
    ONBOOT=yes
    TYPE=Ethernet
    BOOTPROTO=static
    IPADDR=192.168.230.100
    NETMASK=255.255.255.0
    }

    /etc/sysconfig/network
    {
    {
    NETWORKING=yes
    HOSTNAME=whisky
    GATEWAY=192.168.230.2
    }

    And “Service network restart “ passed OK. But “service NetworkManager stop” failed.
    So, I run “rm -f /etc/udev/rules.d/70-persistent-net.rules” and “reboot”

    However, after reboot, I am still not able to get into internet
    “nslookup http://www.google.co.uk” or firefox web search failed.

    Have I missed anything from your article and do you have any suggestion?

    Thanks for your time.

    Best regards

    Xiaofeng

  10. July 10th, 2015 at 10:36 | #10

    Hi Xiaofeng,

    Not familiar with both vmnetcfg.exe and Scientific Linux. I would try to check first the linkage from your vm to your host.

    Steve

  11. Sathya Jammi
    July 24th, 2015 at 13:18 | #11

    I have a couple VMs running Ubuntu, the IP addresses in my interfaces keep getting deleted every couple minutes or so.

    I have statically defined the IP addresses of these interfaces in the /etc/network/interfaces.

    If I do a “ifup eth1”, the IP addresses show up fine, but dissappear again after a couple of minutes, I am really looking for a solution for this.. any advice would help.

    root@reventon:~# route -n
    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    0.0.0.0 10.3.80.1 0.0.0.0 UG 0 0 0 eth0
    10.3.80.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
    169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
    root@reventon:~# route -n
    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    0.0.0.0 10.3.80.1 0.0.0.0 UG 0 0 0 eth0
    10.3.80.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
    169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
    root@reventon:~# ifconfig eth1
    eth1 Link encap:Ethernet HWaddr 00:0c:29:4f:c7:81
    inet6 addr: fe80::20c:29ff:fe4f:c781/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:990 errors:0 dropped:80 overruns:0 frame:0
    TX packets:1429 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:220333 (220.3 KB) TX bytes:241382 (241.3 KB)

    root@reventon:~# cat /etc/network/interfaces
    # interfaces(5) file used by ifup(8) and ifdown(8)
    auto lo
    iface lo inet loopback
    auto eth0
    iface eth0 inet static
    address 10.3.80.13
    netmask 255.255.255.0
    gateway 10.3.80.1
    broadcast 10.3.80.255
    dns-nameservers 10.43.2.10

    auto eth1
    iface eth1 inet static
    address 4.3.10.1
    netmask 255.255.0.0
    gateway 4.3.0.254
    broadcast 4.3.255.255

    auto eth2
    iface eth2 inet static
    address 5.3.10.1
    netmask 255.255.0.0
    gateway 5.3.0.254
    broadcast 5.3.255.255


    root@reventon:~# ifup eth1
    RTNETLINK answers: File exists
    Failed to bring up eth1.
    root@reventon:~# ifconfig eth1
    eth1 Link encap:Ethernet HWaddr 00:0c:29:4f:c7:81
    inet addr:4.3.10.1 Bcast:4.3.255.255 Mask:255.255.0.0
    inet6 addr: fe80::20c:29ff:fe4f:c781/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:1002 errors:0 dropped:80 overruns:0 frame:0
    TX packets:1443 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:222595 (222.5 KB) TX bytes:244157 (244.1 KB)


    After 2 minutes this would dissapear…
    root@reventon:~# ifconfig eth1
    eth1 Link encap:Ethernet HWaddr 00:0c:29:4f:c7:81
    inet6 addr: fe80::20c:29ff:fe4f:c781/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:990 errors:0 dropped:80 overruns:0 frame:0
    TX packets:1429 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:220333 (220.3 KB) TX bytes:241382 (241.3 KB)

  12. July 24th, 2015 at 19:16 | #12

    Sathya,

    I think you can have only one default gateway. In your case, you have 3. You may want to fix that.

    Good luck!

    Steve

  13. Prithvi
    October 5th, 2015 at 16:21 | #13

    Steve,

    Host is Ubuntu and guest is also Ubuntu on the same version 14.04.

    I am trying to setup remote access from my host to guest through Terminal. Setting the static IP using your procedure works, I can also ping it from the host. But trying ssh doesn’t work. When I rollback to DHCP, it works again. Any help would be appreciated.

    Prithvi

  14. October 5th, 2015 at 17:24 | #14

    That is interesting. So when you use static IP for the VM, you cannot SSH to the VM from the host. But when you use DHCP, you can SSH to it from the host? Both cases you can ping the VM from the host. The only difference is the way how the IP is acquired? static or DHCP IP

  15. Akim
    November 10th, 2015 at 07:10 | #15

    Thank you very much. Like the other commentators you helped to resolve the all issue with editing the host file when installing an oracle database software. I also did a restart of the whole network using the cmd: /etc/rc.d/init.d/network restart

  16. George
    June 13th, 2016 at 03:27 | #16

    Hello, couple months ago I installed VMware and ubuntu in it, I tried to set a static ip on ubuntu because of I wanted to have a game server for me and my friends, anyway, I think I messed up everything in ubuntu and then I completely removed VMware even reinstalled windows but I keep getting this error, every once in a while, like in every 3-4 hours I get network error on windows 10 then on the right corner I right click and click troubleshoot problem and it is fixed, but the date and time in my pc is never accurate. I am tired of this could anyone please help me or have any clue what it might be? Thanks huge!

  17. June 13th, 2016 at 20:16 | #17

    Hi George, Sorry to hear that. I haven’t seen similar problem. Hope the readers can help out.

    -Steve

  18. September 1st, 2016 at 13:22 | #18

    THANKS… I needed to set up a CentOS 7 box to run a particular server for my own use locally on my Windows 10 Pro machine and every time my machine went to sleep, I would lose the connection and have to change my IP address in PuTTY / WinSCP and in my favorites in Firefox… This helped immensely. Thanks bunches.

  19. September 2nd, 2016 at 12:01 | #19

    You are very welcome Harold! -Steve

  1. March 12th, 2013 at 09:05 | #1
  2. March 31st, 2014 at 01:44 | #2
  3. February 4th, 2016 at 23:18 | #3
  4. May 25th, 2017 at 18:50 | #4
  5. June 7th, 2017 at 02:25 | #5
  6. August 30th, 2017 at 14:40 | #6