Using host network adapters

A vSphere Standard or Distributed Switch can have virtual and physical network adapters. Physical network adapters are used to connect virtual switches to physical switches and have a name starting with vmnic. Virtual network adapters or VMKernel network adapters can be used to set various properties such as management traffic, vMotion, fault tolerance logging, IP address, and subnet mask. Virtual network adapters have a name starting with vmk. You can see virtual and physical network adapters in the screenshot given in the preceding section,  Creating vSphere Standard Switches .

Creating host network adapters

To create a new virtual network adapter or VMkernel port, you can use the New-VMHostNetworkAdapter cmdlet. The cmdlet creates a port group if the -PortGroup parameter is used. The syntax of this cmdlet is as follows:

New-VMHostNetworkAdapter [[-VMHost] <VMHost>] [[-PortGroup] <String>]
    [-PortId <String>] [-VirtualSwitch] <VirtualSwitchBase> [[-IP]
    <String>] [[-SubnetMask] <String>] [[-Mac] <String>] [-Mtu <Int32>]
    [-ConsoleNic] [-VMotionEnabled [<Boolean>]]
    [-FaultToleranceLoggingEnabled [<Boolean>]] [-IPv6ThroughDhcp]
    [-AutomaticIPv6] [-IPv6 <String[]>] [-ManagementTrafficEnabled
    [<Boolean>]] [-VsanTrafficEnabled [<Boolean>]]
    [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

The -VirtualSwitch parameter is required.

In the following example, we will create a new VMkernel port called vmk1 on the vSwitch1 virtual switch that is present on the host 192.168.0.133. A port group named VMKernelPortGroup1 is also created:

PowerCLI C:> $VMHost = Get-VMHost -Name 192.168.0.133
PowerCLI C:> $VirtualSwitch = $VMHost |
>> Get-VirtualSwitch -Name vSwitch1
PowerCLI C:> New-VMHostNetworkAdapter -VMHost $VMhost -PortGroup
    VMKernelPortGroup1 -VirtualSwitch $VirtualSwitch -IP 192.168.0.150
    -SubnetMask 255.255.255.0


    Name Mac               DhcpEnabled IP            SubnetMask    Device
                                                               Name
---- ---               ----------- --            ----------    ------
vmk1 00:50:56:6c:a8:38 False       192.168.0.150 255.255.255.0 vmk1

Retrieving host network adapters

The Get-VMHostNetworkAdapter cmdlet can be used to retrieve the physical and virtual host network adapters. This cmdlet will retrieve the network adapters for vSphere Standard Switches and also for vSphere Distributed Switches. The syntax of the Get-VMHostNetworkAdapter cmdlet is as follows:

Get-VMHostNetworkAdapter [-VMHost <VMHost[]>] [[-VirtualSwitch]
    <VirtualSwitchBase[]>] [-PortGroup <VirtualPortGroupBase[]>] 
    [-Physical] [-VMKernel] [-Console] [[-Name] <String[]>] 
    [-Id <String[]>] [-Server <VIServer[]>] [<CommonParameters>]

In the following example, all of the host network adapters of the host 192.168.0.133 are retrieved. To fit the output of the command on a page of this book, the output of the Get-VMHostNetworkAdapter cmdlet is piped to the Select-Object cmdlet to select only the Name, Mac, DhcpEnabled, IP, and SubnetMask properties, and is then piped to the Format-Table -AutoSize command, to write the output in the table format, and to adjust the column size based on the width of the data:

PowerCLI C:> $VMHost = Get-VMHost -Name 192.168.0.133
PowerCLI C:> $VMHost | Get-VMHostNetworkAdapter | Select-Object
    -Property Name,Mac,DhcpEnabled,IP,SubnetMask | Format-Table -AutoSize

The output of the preceding command is as follows:

Name   Mac               DhcpEnabled IP            SubnetMask
----   ---               ----------- --            ----------
vmnic0 00:0c:29:23:ab:67       False
vmnic1 00:0c:29:23:ab:71       False
vmnic2 00:0c:29:23:ab:7b       False
vmnic3 00:0c:29:23:ab:85       False
vmnic4 00:0c:29:23:ab:8f       False
vmnic5 00:0c:29:23:ab:99       False
vmnic6 00:0c:29:23:ab:a3       False
vmnic7 00:0c:29:23:ab:ad       False
vmk0   00:0c:29:23:ab:67       False 192.168.0.133 255.255.255.0
vmk1   00:50:56:6c:a8:38       False 192.168.0.150 255.255.255.0

Configuring host network adapters

To modify the settings of a host network adapter, you can use the Set-VMHostNetworkAdapter cmdlet. The syntax of this cmdlet is as follows. The first parameter set is for setting the network speed on the physical network adapters to half or full duplex or auto negotiate:

Set-VMHostNetworkAdapter -PhysicalNic <PhysicalNic[]>
    [-Duplex <String>] [-BitRatePerSecMb <Int32>] [-AutoNegotiate]
    [-WhatIf] [-Confirm] [<CommonParameters>]

The second parameter set is for configuring virtual network adapters:

Set-VMHostNetworkAdapter -VirtualNic <HostVirtualNic[]> [-Dhcp]
    [-IP <String>] [-SubnetMask <String>] [-Mac <String>] [-Mtu <Int32>]
    [-VMotionEnabled [<Boolean>]] [-FaultToleranceLoggingEnabled
    [<Boolean>]] [-ManagementTrafficEnabled [<Boolean>]]
    [-VsanTrafficEnabled [<Boolean>]] [-IPv6ThroughDhcp [<Boolean>]]
    [-AutomaticIPv6 [<Boolean>]] [-IPv6 <String[]>] [-IPv6Enabled
    [<Boolean>]] [-WhatIf] [-Confirm] [<CommonParameters>]

The third parameter set is for migrating a virtual network adapter from a Standard Port Group to a Distributed Port Group:

Set-VMHostNetworkAdapter -VirtualNic <HostVirtualNic[]> -PortGroup 
    <DistributedPortGroup> [-WhatIf] [-Confirm] [<CommonParameters>]

The -PhysicalNic, -VirtualNic, and -PortGroup parameters are required.

Configuring network speed and duplex setting

In the first example of the Set-VMHostNetworkAdapter cmdlet, we will set the speed of the physical network adapter vmnic2 of the host 192.168.0.133 to 1,000 MB and full duplex:

PowerCLI C:> Get-VMHostNetworkAdapter -VMHost 192.168.0.133
    -Name vmnic2 |
>> Set-VMHostNetworkAdapter -BitRatePerSecMb 10000 -Duplex
    Full -Confirm:$false


    Name     Mac                DhcpEnabled  IP  SubnetMask  DeviceName
----     ---                -----------  --  ----------  ----------
vmnic2   00:0c:29:23:ab:7b  False                        vmnic2

Configuring the management network

To enable a VMkernel port on an ESXi server for management traffic, you have to use the Set-VMHostNetworkAdapter -ManagementTrafficEnabled parameter. Using $true as the value for this parameter will enable management traffic, and $false will disable it. In the following example, we will enable management traffic for the VMkernel port vmk1 of the host 192.168.0.133:

PowerCLI C:> Get-VMHostNetworkAdapter -VMHost 192.168.0.133
    -Name vmk1 |
>> Set-VMHostNetworkAdapter -ManagementTrafficEnabled:$true
    -Confirm:$false


    Name Mac               DhcpEnabled IP            SubnetMask    Device
---- ---               ----------- --            ----------    ------
vmk1 00:50:56:6c:a8:38 False       192.168.0.150 255.255.255.0 vmk1

Configuring vMotion

In the following example, we will enable vMotion on the VMkernel network adapter vmk2 for the host 192.168.0.133:

PowerCLI C:> Get-VMHostNetworkAdapter -VMHost 192.168.0.133
    -Name vmk1 |
>> Set-VMHostNetworkAdapter -VMotionEnabled:$true
    -Confirm:$false


    Name Mac               DhcpEnabled IP            SubnetMask    Device
---- ---               ----------- --            ----------    ------
vmk1 00:50:56:6c:a8:38 False       192.168.0.150 255.255.255.0 vmk1

To disable vMotion, you have to modify $true in the preceding example to $false.

Removing host network adapters

To remove a host network adapter, you can use the Remove-VMHostNetworkAdapter cmdlet, which has the following syntax:

Remove-VMHostNetworkAdapter [-Nic] <HostVirtualNic[]> [-WhatIf]
    [-Confirm] [<CommonParameters>]

The -Nic parameter is required.

In the following example, we will use the Remove-VMHostNetworkAdapter cmdlet to remove the host network adapter vmk1 from the host 192.168.0.133:

PowerCLI C:> Get-VMHostNetworkAdapter -VMHost 192.168.0.133
    -Name vmk1 |
>> Remove-VMHostNetworkAdapter -Confirm:$false

The preceding command returns no output.

Configuring NIC teaming

NIC Teaming, also known as Load Balancing and Failover (LBFO), allows you to combine multiple network adapters into one virtual NIC for fault tolerance and better performance. You can configure NIC Teaming for an entire virtual switch or per virtual port group. The Get-NicTeamingPolicy and Set-NicTeamingPolicy cmdlets that we will discuss in this section have two parameter sets, one for NIC Teaming at the virtual switch level and one for NIC Teaming at the virtual port group level. The syntax of the Get-NicTeamingPolicy cmdlet is as follows. The first parameter set is for retrieving the NIC Teaming policy of a virtual switch:

Get-NicTeamingPolicy [-VirtualSwitch] <VirtualSwitch[]>
    [-Server <VIServer[]>] [<CommonParameters>]

The second parameter set is for retrieving the NIC Teaming policy of a virtual port group:

Get-NicTeamingPolicy [-VirtualPortGroup] <VirtualPortGroup[]>
    [-Server <VIServer[]>] [<CommonParameters>]

One of the -VirtualSwitch or -VirtualPortGroup parameter is required.

In the following example, we will retrieve the NIC Teaming policy for virtual switch vSwitch1 of host 192.168.0.133:

PowerCLI C:> Get-VMHost -Name 192.168.0.133 |
>> Get-VirtualSwitch -Name vSwitch1 |
>> Get-NicTeamingPolicy


    VirtualSwitch ActiveNic StandbyNic UnusedNic FailbackEnabled NotifySw
                                                             itches
------------- --------- ---------- --------- --------------- --------
vSwitch1      {vmnic2}                       True            True

In the following example, we will retrieve the NIC Teaming policy for the virtual port group Management Network of the host 192.168.0.133:

PowerCLI C:> Get-VMHost -Name 192.168.0.133 |
>> Get-VirtualPortGroup -Name 'Management Network' |
>> Get-NicTeamingPolicy


    VirtualPortGroup   ActiveNic StandbyNic UnusedNic FailbackEnabled
----------------   --------- ---------- --------- ---------------
Management Network {vmnic0}                       True

To configure a NIC Teaming policy by using the Set-NicTeamingPolicy cmdlet, you have to use a Teaming policy, which was retrieved by the Get-NicTeamingPolicy cmdlet, as the input. You can pass this Teaming policy via the pipeline. The syntax of the Set-NicTeamingPolicy cmdlet is as follows. The first parameter set is for configuring the NIC Teaming policy of a virtual switch:

Set-NicTeamingPolicy [-VirtualSwitchPolicy]
    <NicTeamingVirtualSwitchPolicy[]> [-BeaconInterval <Int32>]
    [-LoadBalancingPolicy <LoadBalancingPolicy>]
    [-NetworkFailoverDetectionPolicy <NetworkFailoverDetectionPolicy>]
    [-NotifySwitches [<Boolean>]] [-FailbackEnabled [<Boolean>]]
    [-MakeNicActive <PhysicalNic[]>] [-MakeNicStandby <PhysicalNic[]>]
    [-MakeNicUnused <PhysicalNic[]>] [-WhatIf] [-Confirm]
    [<CommonParameters>]

The second parameter set is for configuring the NIC teaming policy of a virtual port group:

Set-NicTeamingPolicy [-VirtualPortGroupPolicy] 
    <NicTeamingVirtualPortGroupPolicy[]> [-InheritLoadBalancingPolicy
    [<Boolean>]] [-InheritNetworkFailoverDetectionPolicy [<Boolean>]]
    [-InheritNotifySwitches [<Boolean>]] [-InheritFailback [<Boolean>]]
    [-InheritFailoverOrder [<Boolean>]] [-LoadBalancingPolicy
    <LoadBalancingPolicy>] [-NetworkFailoverDetectionPolicy 
    <NetworkFailoverDetectionPolicy>] [-NotifySwitches [<Boolean>]]
    [-FailbackEnabled [<Boolean>]] [-MakeNicActive <PhysicalNic[]>]
    [-MakeNicStandby <PhysicalNic[]>] [-MakeNicUnused <PhysicalNic[]>]
    [-WhatIf] [-Confirm] [<CommonParameters>]

One of the -VirtualSwitchPolicy or -VirtualPortGroupPolicy parameters is required.

In the following example, we will first add the physical network adapter vmnic1 to the virtual switch vSwitch0 on the host 192.168.0.133, using the Add-VirtualSwitchPhysicalNetworkAdapter cmdlet we have already seen in the Adding network adapters to a switch section:

PowerCLI C:> $VMHost = Get-VMHost -Name 192.168.0.133
PowerCLI C:> $NetworkAdapter = Get-VMHostNetworkAdapter
    -VMHost $VMHost -Physical -Name vmnic1
PowerCLI C:> Get-VirtualSwitch -Name vSwitch0 -VMHost $VMHost |
>> Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic
    $NetworkAdapter -Confirm:$false

The preceding command does not return any output.

Next, we will configure NIC Teaming for the virtual port group Management Network and add vmnic1 to the active NICs:

PowerCLI C:> $Policy = $VMHost |
>> Get-VirtualPortGroup -Name 'Management Network' |
>> Get-NicTeamingPolicy
PowerCLI C:> Set-NicTeamingPolicy -VirtualPortGroupPolicy $Policy
    -MakeNicActive vmnic1


    VirtualPortGroup   ActiveNic        StandbyNic UnusedNic FailbackEna
                                                         bled
----------------   ---------        ---------- --------- -----------
Management Network {vmnic0, vmnic1}                      True

In the screenshot of the vSphere Web Client, you can see the teamed Physical Adapters  vmnic0 and vmnic1 after executing the commands from the preceding example:

Configuring NIC teaming

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.29.145