Chris Hall bio photo

Chris Hall

Principal Technical Consultant

PolarCloudsUK Chris LinkedIn Github
Chris Hall Nutanix Certified Master - Multicloud Infrastructure 6 Chris Hall VMware vExpert 2024 Nutanix Certified Professional - Cloud Integration Chris Hall Nutanix Certified Professional - Multicloud Infrastructure 6 Chris Hall Nutanix Certified Professional - Unified Storage 6 Chris Hall VMware vExpert 2023 Chris Hall VMware vExpert 2022
Ages and ages ago, I posted an article detailing ESX Command Line Networking Configuration, and at the bottom of the post I added the sign off "Next time.... ESXi."  Well, finally here is said ESXi post: How to configure ESXi networking from the command line.

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, again, here we go... Again!

Changing IP Address, Subnet Mask, Default Gateway, Hostname and DNS Settings (All Versions)
Very simple. Use the console configuration tool:

OK, whilst strictly not "command line", why not use the built in configuration tool? It is far simpler!

Word of warning - Whilst not prompted for a reboot when changing the ESXi's Hostname, I would complete a reboot anyway.  I and others have seen spurious issues later on through ESXi configuration when a post rename reboot has not been completed.

Linking and Unlinking Physical Network Cards to Virtual Switches and Network Card Teaming (All Versions)
Again sure you can do this through the console configuration tool for the service console / management vSwitch.  However, what happens if you want to make changes on other vSwitches?

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:
esxcfg-vswitch -l

To connect a physical adaptor to a virtual switch, you need to Link it, using the following command:
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:
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

NIC Teaming Policy and Load Balancing (ESXi 4.1 and Earlier)
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:
vim-cmd /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:
vim-cmd /hostsvc/net/vswitch_setpolicy --nicteaming-policy='loadbalance_ip' vSwitch0
To confirm the setting, run the command:
vim-cmd /hostsvc/net/vswitch_info vSwitch0 | grep policy
When run on console:

NIC Teaming Policy and Load Balancing (ESXi 5.0 and Later)
To specify the NIC teaming load balancing policy on a vSwitch, run the command:
esxcli network vswitch standard policy failover set -l [policy] -v vSwitch0
Where [policy] is one of these NIC teaming policies:
  • portid (Route based on the originating virtual switch port ID)
  • mac (Route based on source MAC hash)
  • iphash (Route based on IP hash)
  • explicit (Use explicit failover order)
For example, to set the NIC teaming policy to route based on originating switch port ID, run the command:
esxcli network vswitch standard policy failover set -l portid -v vSwitch0
To confirm the setting, run the command:
esxcli network vswitch standard policy failover get -v vSwitch0
When run on console:
Further reading on NIC Teaming Policy and Load Balancing: http://kb.vmware.com/kb/1011520

VLAN Tagging (All Versions)
Use the following command to assign a VLAN to a console port / port group
esxcfg-vswitch -v [VLANID] -p "Management Network" vSwitch0
Where [VLANID] is the VLAN number, "Management Network" 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

Overview
In this post we looked at how to configure the following, all from the ESXi 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
  • NIC Teaming Policy and Load Balancing
  • VLAN Tagging

- Chris