Configuring virtual networks in VMware for Linux

Usually, the only method to configuring virtual networks in VMware is to run vmware-config.pl. As a result, you will have to answer lots of questions once again even though most of them are the default value and just need to press Enter. Today I would like to configuring my virtual networks for removing host-only network and nat in production machine. Hopefully it will help optimize the overall utilization a bit. Anyway, I don't want to answer those questions anymore. And I found the secret in /usr/lib/vmware/net-services.sh.

The configuration is stored in /etc/vmware/locations. It also keeps other configuration regarding the host itself. According to net-services.sh, it shows that a host could have virtual networks up to 256 interfaces (0-255). In general, there are only 2 network types: bridged and host-only. However, you could enable NAT in host-only virtual network so I will explain in detail.

Bridged

Usually, you may prefer to use bridged virtual network as long as you have enough IP address. It is very easy and simple to create a bridged network to a physical device by adding a line in below format.

answer VNET_{vn_id}_INTERFACE {interface}

For example, you have 2 interfaces; eth0 and eth1. And you want to enable bridge in both of them as vmnet0 and vmnet1, respectively.

answer VNET_0_INTERFACE eth0
answer VNET_1_INTERFACE eth1

Host-only

In some rare cases, you might want to run a virtual machine in theoritically secure mode so that only the host is able to access to itself and the virtual machine could only access to the host. This is the best match to host-only virtual network. This network type needs 2 lines of configuration to specify its IP address and netmask. Note that this IP address is for the host side. A DHCPD will be configured and started automatically.

answer VNET_{vn_id}_HOSTONLY_HOSTADDR {ip_address}
answer VNET_{vn_id}_HOSTONLY_NETMASK {netmask}

For example, you would like to have vmnet7 setup with IP address 172.16.13.1 and all virtual machines binded to this interface will be automatically assigned IP in netmask 255.255.255.0.

answer VNET_7_HOSTONLY_HOSTADDR 172.16.13.1
answer VNET_7_HOSTONLY_NETMASK 255.255.255.0

NAT

If you would like to let virtual machines behide host-only virtual networks to access the outside network, you may enable NAT by adding another line as follow.

answer VNET_{vn_id}_NAT yes
answer VNET_{vn_id}_HOSTONLY_HOSTADDR {ip_address}
answer VNET_{vn_id}_HOSTONLY_NETMASK {netmask}

For example, you would like to have a NAT virtual network in vmnet8.

answer VNET_8_NAT yes
answer VNET_8_HOSTONLY_HOSTADDR 172.16.17.1
answer VNET_8_HOSTONLY_NETMASK 255.255.255.0

Remove settings

The behavior of locations file is to record all actions in transaction basis. So if you have already configured the virtual networks once and you don't want to remove those lines, you may add lines to remove the settings as follows.

remove_answer {name}

For example, I would like to remov my existing host-only, bridged and NAT interfaces in vmnet1, vmnet2 and vmnet8, respectively.

remove_answer VNET_1_HOSTONLY_HOSTADDR
remove_answer VNET_1_HOSTONLY_NETMASK
remove_answer VNET_2_INTERFACE
remove_answer VNET_8_NAT
remove_answer VNET_8_HOSTONLY_HOSTADDR
remove_answer VNET_8_HOSTONLY_NETMASK

Configuration Steps

  1. First of all, please back up the current configuration.

    cp /etc/vmware/locations /etc/vmware/locations.bak
    
  2. Stop all virtual networks

    /usr/lib/vmware/net-services.sh stop
    
  3. Modify /etc/vmware/locations as you need. Remember that you should not remove the virtual network in use.

  4. Start virtual networks again

    /usr/lib/vmware/net-services.sh start
    

All done.

Tags: , , , ,

Post new comment