Friday, 6 May 2011

ESX Command Line Networking Configuration


So you’ve built your VMware ESX server and your dead impressed with yourself that you got this far.  You leave the datacentre head back to the office safe in the knowledge that the install went well.  However once safely back at your desk, oh no! You find that you shiny new ESX install is uncontactable from the network.


We’ve all been there.  So here is my guide to configuring ESX networking from the server console post install.  No VI client or GUI tools required.  Just good solid command-line stuff.  Specifically we will be looking at:

  • Changing IP Address, Subnet Mask, Default Gateway, Hostname and DNS Server Settings
  • Linking and Unlinking Physical Network Cards to Virtual Switches and Network Card Teaming
  • VLAN Tagging
  • NIC Teaming Policy and Load Balancing

Why?  Because there doesn’t appear to be any single place (that I can find at least) where all of the this is detailed.  So hold onto you hats, here we go.

UPDATE: For ESXi Command Line Networking Configuration see THIS POST

Changing IP Address, Subnet Mask, Default Gateway, DNS Server Settings and Hostname
Happens to us all.  Perhaps you just ‘fat fingered’ the IP?  Use

[root@server root]# ifconfig |more
[root@server root]# cat /etc/sysconfig/network
to confirm that IP config is indeed wrong

IP Address / Subnet Mask
Run this command to set the IP address:
[root@server root]# esxcfg-vswif -i [a.b.c.d] -n [w.x.y.z] vswif0
Where [a.b.c.d] is the IP address and [w.x.y.z] is the subnet mask and vswif0 is the Service Console adapter that is the interface to which you are applying the IP address change.

Open the /etc/hosts file with nano and modify it so that it reflects the correct IP address and hostname.

Default Gateway
To change the default gateway address and the hostname, edit the /etc/sysconfig/network file and change the GATEWAY and HOSTNAME parameters to the proper values.  For the changes to take place, reboot the host or restart the network service with the command:
[root@server root]# service network restart

DNS Server Settings
To change the DNS server settings, update the nameserver IPs and search domain in the /etc/resolv.conf file.

Further reading on Changing IP Address, Subnet Mask, Default Gateway, DNS Server Settings: http://kb.vmware.com/kb/4309499

Hostname
Change the hostname and domain name (if applicable) of the host in the following files:
  • /etc/hosts
  • /etc/sysconfig/network
Execute this command where [hostname] is the new hostname for the ESX host:
[root@server root]# esxcfg-advcfg -s [hostname] /Misc/HostName
Reboot the ESX host
Further reading on Changing ESX Hostname: http://kb.vmware.com/kb/1010821


Linking and Unlinking Physical Network Cards to Virtual Switches and Network Card Teaming
This is possibly my most used ESX console command.  Often used when there has been a cabling mix up or the software installation has detected the physical network adaptors in a different order than anticipated prior to the install.  Sure I could just swap cables around, but if physical changes are not possible (i.e.cabling is as documented or moving cables is not allowed) then these commands will help.

First lets look at how the vSwitch is configured post install.  Screenshot from a VI Client:
If you were to view the same information at the service console command line we would use the following command to list the virtual switches configured:
[root@server root]# esxcfg-vswitch -l

To connect a physical adaptor to a virtual switch, you need to Link it, using the following command:
[root@server root]# esxcfg-vswitch -L vmnic1 vSwitch0
Where vmnic1 is the physical network card being connected to the virtual switch vSwitch0.

To disconnect a physical adaptor to a virtual switch, you need to Unlink it, using the following command:
[root@server root]# esxcfg-vswitch -U vmnic1 vSwitch0
Where vmnic1 is the physical network card being disconnected from the virtual switch vSwitch0.

Basic network card teaming is achieved by having two or more physical adaptors connected to the same virtual switch.  From the VI Client:
 Which in turn looks like this from the console:

Further reading on Linking and Unlinking Physical Network Cards to Virtual Switches: http://kb.vmware.com/kb/1000258


VLAN Tagging
 Use the following command to assign a VLAN to a console port / port group
 [root@server root]# esxcfg-vswitch -v [VLAN] -p “Service Console” vSwitch0
Where [VLANID] is the VLAN number, "Service Console" is the console port / port group name and vSwitch0 is the virtual switch the console port / port group is connected to.  A zero [VLANID] here specifies no VLAN.

Further reading on VLAN Tagging: http://kb.vmware.com/kb/1000258


NIC Teaming Policy and Load Balancing
First lets look at how the vSwitch load balancing configured post install.  Screenshot from a VI Client:

Which in turn looks like this from the console:

 To specify the NIC teaming load balancing policy on a vSwitch, run the command:
[root@server root]# vimsh -n -e "hostsvc/net/vswitch_setpolicy --nicteaming-policy [policy] vSwitch0"
Where [policy] is one of these NIC teaming policies:

  • loadbalance_srcid (Route based on the originating virtual switch port ID)
  • loadbalance_srcmac (Route based on source MAC hash)
  • loadbalance_ip (Route based on IP hash)
  • failover_explicit (Use explicit failover order)

For example, to set the NIC teaming policy to route based on IP hash, run the command:
[root@server root]# vimsh -n -e "hostsvc/net/vswitch_setpolicy --nicteaming-policy loadbalance_ip vSwitch0"
To confirm the setting, run the command:
[root@server root]# vimsh -n -e "hostsvc/net/vswitch_info vSwitch0" | grep policy
Further reading on NIC Teaming Policy and Load Balancing: http://kb.vmware.com/kb/1019864


Overview
In this post we looked at how to configure the following, all from the ESX console, no VI client required!

  • Changing IP Address, Subnet Mask, Default Gateway, Hostname and DNS Server Settings
  • Linking and Unlinking Physical Network Cards to Virtual Switches and Network Card Teaming
  • VLAN Tagging
  • NIC Teaming Policy and Load Balancing

Next time.... ESXi.

- Chris

Newer Posts Older Posts Home