<commit_before>---
layout: post
title: Change vmnic order on vSphere host
DATE: 

---
Changing the vmnic order is an unusual thing to do and you may rightfully wonder why one would want to do that. Heterogeneous enironments are fully supported but most vSphere administrators aim at having homogeneous hosts with the exact same config in their clusters to simplify operations and avoid human errors.

Uplinks lables are no exceptions. vSphere gives them labels at the first boot that you then use to configure the vSwtiches (vmnic0, 1, 2...). However, if you make changes to the physical configuration and reorder the vSwitches you may need to change the labels to make them match the other hosts.

The VMware [KB2091560 ](https://kb.vmware.com/s/article/2091560) gives extensive information about the labelling of the IO devices. Here is a quick summary of how to change the uplinks labels.

* First evacuate the host and put it in maintenance mode. We will need to reboot it.
* Connect to the host via SSH.
* List the uplinks and their labels.

    localcli --plugin-dir /usr/lib/vmware/esxcli/int deviceInternal alias list | grep vmnic

The output contains the list of vmnics with their pci ID on the motherboard. If the NIC runs on a native driver (which is most of the time) there will be a logical ID as well. We need to change the alias on both of them.

    Bus type  Bus address          Alias
    ------------------------------------
    pci       s00000002.00         vmnic4
    pci       s00000002.01         vmnic5
    pci       s00000001.01         vmnic1
    pci       s00000001.00         vmnic0
    logical   pci#s00000002.00#0   vmnic4
    logical   pci#s00000002.01#0   vmnic5
    logical   pci#s00000001.01#0   vmnic1
    logical   pci#s00000001.00#0   vmnic0

Let's say after a hardware change you have a gap between vmnic1 and vmnic4 and you don't want that. We want to replace vmnic4 with vmnic2 and vmnic5 with vmnic3.

* Change the PCI alias. You essentially assign an alias to a Bus address.

    localcli --plugin-dir /usr/lib/vmware/esxcli/int/ deviceInternal alias store --bus-type pci --alias vmnic2 --bus-address s00000002.00
    localcli --plugin-dir /usr/lib/vmware/esxcli/int/ deviceInternal alias store --bus-type pci --alias vmnic3 --bus-address s00000002.01

* Change the logical alias. Same as before with a different parameter.

    localcli --plugin-dir /usr/lib/vmware/esxcli/int/ deviceInternal alias store --bus-type logical --alias vmnic2 --bus-address s00000002.00
    localcli --plugin-dir /usr/lib/vmware/esxcli/int/ deviceInternal alias store --bus-type logical --alias vmnic3 --bus-address s00000002.01

* Reboot the host.<commit_msg>Update from Forestry.io <EMAIL> updated _drafts/change-vmnic-order-on-vsphere-host.md<commit_after>---
layout: post
title: Change vmnic order on vSphere host
DATE: 

---
Changing the vmnic order is an unusual thing to do and you may rightfully wonder why one would want to do that. Heterogeneous enironments are fully supported but most vSphere administrators aim at having homogeneous hosts with the exact same config in their clusters to simplify operations and avoid human errors.

Uplinks lables are no exceptions. vSphere gives them labels at the first boot that you then use to configure the vSwtiches (vmnic0, 1, 2...). However, if you make changes to the physical configuration and reorder the vSwitches you may need to change the labels to make them match the other hosts.

The VMware [KB2091560 ](https://kb.vmware.com/s/article/2091560) gives extensive information about the labelling of the IO devices. Here is a quick summary of how to change the uplinks labels.

* First evacuate the host and put it in maintenance mode. We will need to reboot it.
* Connect to the host via SSH.
* List the uplinks and their labels.

    localcli --plugin-dir /usr/lib/vmware/esxcli/int deviceInternal alias list | grep vmnic

The output contains the list of vmnics with their addresses on the motherboard. If the NIC runs on a native driver (which is most of the time) there will be a logical ID as well. We need to change the aliases of both of them.

    Bus type  Bus address          Alias
    ------------------------------------
    pci       s00000002.00         vmnic4
    pci       s00000002.01         vmnic5
    pci       s00000001.01         vmnic1
    pci       s00000001.00         vmnic0
    logical   pci#s00000002.00#0   vmnic4
    logical   pci#s00000002.01#0   vmnic5
    logical   pci#s00000001.01#0   vmnic1
    logical   pci#s00000001.00#0   vmnic0

Let's say after a hardware change you have a gap between vmnic1 and vmnic4 and you don't want that. We want to replace vmnic4 with vmnic2 and vmnic5 with vmnic3.

* Change the PCI alias. You essentially assign an alias to a Bus address.

    localcli --plugin-dir /usr/lib/vmware/esxcli/int/ deviceInternal alias store --bus-type pci --alias vmnic2 --bus-address s00000002.00
    localcli --plugin-dir /usr/lib/vmware/esxcli/int/ deviceInternal alias store --bus-type pci --alias vmnic3 --bus-address s00000002.01

* Change the logical alias. Same as before with a different parameter.

    localcli --plugin-dir /usr/lib/vmware/esxcli/int/ deviceInternal alias store --bus-type logical --alias vmnic2 --bus-address s00000002.00
    localcli --plugin-dir /usr/lib/vmware/esxcli/int/ deviceInternal alias store --bus-type logical --alias vmnic3 --bus-address s00000002.01

* Reboot the host.
{'fraction_non_alphanumeric': 0.07385632923020394, 'fraction_numerical': 0.05842366342090759, 'mean_word_length': 2.9650400582665695, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 24, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3097472', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1531, 'n_words': 713}