Six Million Ways To…
  • About
CLI , vSphere

ESXi : Configuring network via CLI

by Axel September 28, 2017 No Comments

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 ?

  1. List all NICS and check their status
  2. Create a vSwitch for your test (optional)
  3. Add an uplink to this vSwitch
  4. Create the required number of Portgroup for this vSwitch
  5. 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

 

List all NICS

esxcfg-nics โ€“l

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

Add an uplink to the switch

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 :

Done !

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 ๐Ÿ™‚

vSphere

  • Previous Nutanix : Create a three nodes cluster5 years ago
  • Next vCenter : Remove orphaned VMs5 years ago

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Menu

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Recent Posts

  • vRA : API : Submit a request
  • vRO: Setting constants for workflows
  • VM : Quickly delete one or more VM
  • vRO: Using vRA REST API to get all vCAC VMs
  • vRO : Workflow to Get Restarted VMs by HA

Archives

  • October 2019
  • March 2019
  • March 2018
  • September 2017

Categories

  • CLI (2)
  • ESXi (1)
  • Orchestrator (4)
  • Scripts (3)
    • Powercli (3)
  • vRA (2)
  • vSphere (1)

Tags

API (1) CLI (1) HA (1) Nutanix (1) PowerCLI (1) Reminder (1) REST (1) REST API (1) vCenter (3) VRA (2) VRO (3) vSphere (4)
2023 Six Million Ways To…. Donna Theme powered by WordPress