Hi folks !
After a recent fresh installation, I had to configure the host networking and confirm that the physical switchs of our ESXi hosts were connected to were properly configured. I could have done that by many ways (ESXi UI and Sphere client) but I though it could be nice to use some CLI commands.
As a reminder, if you have a vCenter I suggest that you do this kind of configuration via powercli or thanks to command lines in the vMA appliance (take a look here if you are not aware of this pretty cool appliance. Will try to write a post on this topic soon). This, to update the vCenter database on a real time basis. Configuration tasks should be done on the ESX only if it runs in standalone mode (without a vCenter instance).
Stop talking and let’s get started 🙂
What we’ll have to do to configure our ESX host ?
- List all NICS and check their status
- Create a vSwitch for your test (optional)
- Add an uplink to this vSwitch
- Create the required number of Portgroup for this vSwitch
- Assign a VLAN ID for each Portgroup
Before going further, if you don’t know the esxcfg-vswitch tool just keep in mind that it only returns output on failed commands
Create a vSwitch for your test
esxcfg-vswitch –add VLAN-TESTING
Output of this command is null. Just check the result by running esxcfg-vswitch -l
esxcfg-vswitch –link=vmnic2 VLAN-TESTING
If you receive an error like the one below, you must understand that the physical nic is already assigned to a vSwitch and you have to get it back
VirtualSwitch: Unable to Add Uplink vmnic2. Sysinfo error on operation returned status : Busy. Please see the VMkernel log for detailed error informationFailed to add uplink vmnic2 to vswitch VLAN-TESTING, Error: Sysinfo error on operation returned status : Busy. Please see the VMkernel log for detailed error information
List all the switch to retrieve to one you will have to remove the uplink from with esxcfg-vswitch –list
To unassign the nic from the vSwitch0 for example, just type esxcfg-vswitch –unlink=vmnic2 vSwitch0
Once again, output of this command is null. Just check the result by running esxcfg-vswitch -l
Create a PortGroup on the new vSwitch
This, for each VLAN you have to add to your ESX networking layer.
Before running a loop to perform a bulk command I prefer to test it. I do suggest to do the same 😉
My first test consists in checking that my command does exactly what I want : esxcfg-vswitch –add-pg=VLAN-51 VLAN-TESTING
My second test is about confirming the loop I will use : for i in `seq 52 73`;do echo “esxcfg-vswitch –add-pg=VLAN-$i VLAN-TESTING”;done
Everything looks good, i can send my bulk command: for i in `seq 52 73`;do esxcfg-vswitch –add-pg=VLAN-$i VLAN-TESTING;done
As usual, no output. Check the result by listing your vSwitchs…
Specify a VLAN for each Portgroup
Of course, before executing the command, run some tests as we did previously.
for i in `seq 52 73`;do esxcfg-vswitch –vlan=$i –pg=VLAN-$i VLAN-TESTING;done
The command to create all the VLANs from the 52 to 73 (if you ran the test command, you should have created the #51 😉 )
Once added, you can check the configuration of your new vSwitch using the now famous esxcfg-vswitch –list
In the GUI, you should see something like that :
Please, give us your feedback about this page. Any comment (about content, format of the post, whatever you want) will be welcome and will help to improve the quality of this post and the ones to come.
Thanks for reading 🙂