Reader small image

You're reading from  Learning PowerCLI - Second Edition

Product typeBook
Published inFeb 2017
Publisher
ISBN-139781786468017
Edition2nd Edition
Right arrow
Author (1)
Robert van den Nieuwendijk
Robert van den Nieuwendijk
author image
Robert van den Nieuwendijk

Robert van den Nieuwendijk is an IT veteran from the Netherlands with over thirty years of experience in Information Technology. He holds a bachelor degree in software engineering. After working a few years as a programmer of air traffic control and vessel traffic management systems, he started his own company Van den Nieuwendijk Informatica in 1988. Since then he has worked as a freelance systems administrator of OpenVMS, Windows Server, Linux, and VMware vSphere systems, for Dutch governmental organizations and cloud providers. During winter he is also a ski and snowboard instructor at an indoor ski school. With his background as a programmer, he always tries to make his job easier by writing programs or scripts to perform repeating tasks. In the past, he used the C programming language, OpenVMS DCL, Visual Basic Script and KiXtart to do this. Now, he uses Microsoft PowerShell and VMware PowerCLI for all of his scripting work. Robert is a frequent contributor and moderator at the VMware VMTN Communities. Since 2012 VMware awarded him the vExpert title for his significant contributions to the community and a willingness to share his expertise with others. He has a blog at http://rvdnieuwendijk.com where he writes mainly about VMware PowerCLI, Microsoft PowerShell, and VMware vSphere. If you want to get in touch with Robert, then you can find him on Twitter. His username is @rvdnieuwendijk. Robert is also the author of Learning PowerCLI, Packt Publishing.
Read more about Robert van den Nieuwendijk

Right arrow

Chapter 6. Managing Virtual Networks with PowerCLI

ESXi servers need network connections for management, vMotion, fault tolerance logging traffic, iSCSI, virtual SAN traffic, and NAS/NFS access. Virtual machines need network connections to communicate with other virtual or physical computers. VMware vSphere provides two types of virtual switch that you can use to configure the networks: vSphere Standard Switches and vSphere Distributed Switches. vSphere Standard Switches are specific for an ESXi server host. vSphere Distributed Switches are created and centrally managed on a vCenter Server and are copied to every host that uses the vSphere Distributed Switch.

The topics that will be covered in this chapter are as follows:

  • Using vSphere Standard Switches

  • Using host network adapters

  • Using standard port groups

  • Using vSphere Distributed Switches

  • Using distributed virtual port groups

  • Configuring host networking

  • Configuring the network of virtual machines

Using vSphere Standard Switches


vSphere Standard Switches are created on a specific host. If you are using vSphere clusters, then normally you will create the same vSphere Standard Switches on all of your hosts in a cluster, and give the switches the same configuration on all of the hosts. You can use PowerCLI to create and configure the switches on all of your hosts.

The following figure shows two hosts, and each host has a vSphere Standard Switch:

Creating vSphere Standard Switches

After deploying a new ESXi server, one vSphere Standard Switch is already created. This switch, called vSwitch0, has two port groups: Management Network and VM Network. Also, it is connected to a physical adapter, vmnic0. You can use this switch to connect the host to a vCenter Server or to connect directly to this host using the vSphere Client.

The following screenshot of vSphere Web Client shows vSphere Standard Switch vSwitch0 just after deploying the host 192.168.0.133:

To create a new standard switch, you...

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...

Using standard port groups


Port groups are collections of ports that have the same properties, such as the same virtual switch, VLAN ID, Teaming policy, policies for filtering, tagging, and traffic shaping. Port groups are identified by a network label name. You should give all port groups in a data center, which are connected to the same network, the same network label. This will make virtual machine configurations portable across hosts. Using the PowerCLI cmdlets, you can only specify a network label name for the port group and a VLAN ID.

Note

A Virtual Local Area Network (VLAN) is a virtual computer network independent of physical location. All of the computers in a VLAN can receive broadcasts from the others and are usually in the same IP subnet.

Creating standard port groups

The New-VirtualPortGroup cmdlet will create a new port group for a vSphere Standard Switch. The syntax of this cmdlet is as follows:

New-VirtualPortGroup [-Name] <String> [-VirtualSwitch]
    <VirtualSwitch...

Using vSphere Distributed Switches


The vSphere Distributed Switches are virtual switches that span multiple hosts. This makes it easier to configure hosts that need similar network configurations. It also ensures that virtual machines will get the same network configuration when they migrate to another host. You need a vSphere Enterprise Plus license and a vCenter Server to be able to use vSphere Distributed Switches.

In PowerCLI, there are separate sets of cmdlets for working with vSphere Standard Switches and vSphere Distributed Switches. In the past, the VMware PowerCLI team tried to integrate both types of switches into one set of cmdlets. This is why, for example, the Get-VirtualSwitch cmdlet has a -Distributed parameter. However, this parameter is now obsolete, and VMware made a new set of cmdlets specific for vSphere Distributed Switches. The PowerCLI VDS snap-in that provides support for managing Distributed Switches and port groups was introduced in PowerCLI 5.1 Release 2. In this...

Using distributed virtual port groups


A description of port groups has already been given in the  Using standard port groups section. In this section, you will learn how to use port groups on Distributed Virtual Switches.

Creating distributed virtual port groups

You can use the New-VDPortgroup cmdlet to create distributed virtual port groups from scratch, from the reference port groups or from an export of a Distributed Virtual Switch. The syntax of the New-VDPortgroup cmdlet is as follows. The first parameter set is the default one:

New-VDPortgroup [-VDSwitch] <VDSwitch> -Name <String>
    [-Notes <String>] [-NumPorts <Int32>] [-VlanId <Int32>]
    [-VlanTrunkRange <VlanRangeList>] [-PortBinding
    <DistributedPortGroupPortBinding>] [-RunAsync]
    [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

The second parameter set can be used to create a port group from a reference port group:

New-VDPortgroup...

Configuring host networking


The Get-VMHostNetwork cmdlet will retrieve information about the network on a specific host. This cmdlet has the following syntax:

Get-VMHostNetwork [-Server <VIServer[]>] [-VMHost] <VMHost[]>
    [<CommonParameters>]

The -VMHost parameter is required.

In the following example, we will retrieve the information about the network on the host 192.168.0.133, and format the output as a list:

PowerCLI C:\> Get-VMHost -Name 192.168.0.133 | Get-VMHostNetwork |
>> Format-List *

The output of the preceding command is as follows:

WARNING: The 'VMKernelGatewayDevice' property of VMHostNetworkInfo
    type is deprecated and will be removed in a future release.
WARNING: The 'VirtualSwitch' property of VMHostNetworkInfo type is
    deprecated. Use 'Get-VirtualSwitch' cmdlet instead.
WARNING: The 'PhysicalNic' property of VMHostNetworkInfo type is
    deprecated. Use 'Get-VMHostNetworkAdapter' cmdlet instead.
WARNING: The 'ConsoleNic...

Configuring the network of virtual machines


To configure the network of a virtual machine guest operating system, you can use the Invoke-VMScript cmdlet, to run scripts in the guest operating system of a virtual machine. You have already seen the Invoke-VMScript cmdlet in Chapter 5, Managing Virtual Machines with PowerCLI .

To configure the network of Microsoft Windows virtual machines with PowerShell V3 or later versions installed, you can use the cmdlets in the netadapter and NetTCPIP modules to modify network adapters and TCP/IP settings. For Microsoft Windows virtual machines with PowerShell V1 or V2 installed, you can use the Windows Management Instrumentation (WMIGet-WMIObject cmdlet with the Win32_NetworkAdapterConfiguration class. In this section, we will focus on using the cmdlets from the NetTCPIP module.

Setting the IP address

The PowerShell cmdlet we will use for setting the IP address, network mask, and default gateway is New-NetIPAddress. This cmdlet has the following syntax...

Summary


In this chapter, we covered virtual networking. We showed you how to work with vSphere Standard Switches and vSphere Distributed Switches using PowerCLI. You learned how to use port groups, how to use host network adapters, and how to configure the management network of a host and the network of a virtual machine.

In the next chapter, you will learn all about managing storage with PowerCLI.

lock icon
The rest of the chapter is locked

Unlock this book and the full library FREE for 7 days

Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
You have been reading a chapter from
Learning PowerCLI - Second Edition
Published in: Feb 2017Publisher: ISBN-13: 9781786468017
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime

Author (1)

author image
Robert van den Nieuwendijk

Robert van den Nieuwendijk is an IT veteran from the Netherlands with over thirty years of experience in Information Technology. He holds a bachelor degree in software engineering. After working a few years as a programmer of air traffic control and vessel traffic management systems, he started his own company Van den Nieuwendijk Informatica in 1988. Since then he has worked as a freelance systems administrator of OpenVMS, Windows Server, Linux, and VMware vSphere systems, for Dutch governmental organizations and cloud providers. During winter he is also a ski and snowboard instructor at an indoor ski school. With his background as a programmer, he always tries to make his job easier by writing programs or scripts to perform repeating tasks. In the past, he used the C programming language, OpenVMS DCL, Visual Basic Script and KiXtart to do this. Now, he uses Microsoft PowerShell and VMware PowerCLI for all of his scripting work. Robert is a frequent contributor and moderator at the VMware VMTN Communities. Since 2012 VMware awarded him the vExpert title for his significant contributions to the community and a willingness to share his expertise with others. He has a blog at&nbsp;http://rvdnieuwendijk.com where he writes mainly about VMware PowerCLI, Microsoft PowerShell, and VMware vSphere. If you want to get in touch with Robert, then you can find him on Twitter. His username is @rvdnieuwendijk. Robert is also the author of Learning PowerCLI, Packt Publishing.
Read more about Robert van den Nieuwendijk