VMware Cloud Community
austinb324
Enthusiast
Enthusiast
Jump to solution

vMotion TCP/IP Netstack - gateway

Can anyone help me figure out how to set this value from powercli or esxcli?

gateway.jpg

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this.
Update the variables in the first 4 lines to correspond with your environment

$esxName = 'MyEsx'

$stackName = 'vmotion'

$ipGateway = '192.168.1.254'

$ipDevice = 'vmk1'

$esx = Get-VMHost -Name $esxName

$netSys = Get-View -Id $esx.ExtensionData.ConfigManager.NetworkSystem

$stack = $esx.ExtensionData.Config.Network.NetStackInstance | where{$_.Key -eq $stackName}

$config = New-Object VMware.Vim.HostNetworkConfig

$spec = New-Object VMware.Vim.HostNetworkConfigNetStackSpec

$spec.Operation = [VMware.Vim.ConfigSpecOperation]::edit

$spec.NetStackInstance = $stack

$spec.NetStackInstance.RouteTableConfig = New-Object VMware.Vim.HostIpRouteTableConfig

$route = New-Object VMware.vim.HostIpRouteConfig

$route.defaultGateway = $ipGateway

$route.gatewayDevice = $ipDevice

$spec.NetStackInstance.ipRouteConfig = $route

$config.NetStackSpec += $spec

$netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

13 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this.
Update the variables in the first 4 lines to correspond with your environment

$esxName = 'MyEsx'

$stackName = 'vmotion'

$ipGateway = '192.168.1.254'

$ipDevice = 'vmk1'

$esx = Get-VMHost -Name $esxName

$netSys = Get-View -Id $esx.ExtensionData.ConfigManager.NetworkSystem

$stack = $esx.ExtensionData.Config.Network.NetStackInstance | where{$_.Key -eq $stackName}

$config = New-Object VMware.Vim.HostNetworkConfig

$spec = New-Object VMware.Vim.HostNetworkConfigNetStackSpec

$spec.Operation = [VMware.Vim.ConfigSpecOperation]::edit

$spec.NetStackInstance = $stack

$spec.NetStackInstance.RouteTableConfig = New-Object VMware.Vim.HostIpRouteTableConfig

$route = New-Object VMware.vim.HostIpRouteConfig

$route.defaultGateway = $ipGateway

$route.gatewayDevice = $ipDevice

$spec.NetStackInstance.ipRouteConfig = $route

$config.NetStackSpec += $spec

$netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

nicholas1982
Hot Shot
Hot Shot
Jump to solution

Hey Luc,

can an we use this methof to update other tcp stack settings like dns and search domains?

Nicholas
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, on the HostNetStackInstance object, you can specify under the DnsConfig property, a HostDnsConfig object, you can specify several DNS settings


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
nicholas1982
Hot Shot
Hot Shot
Jump to solution

Thanks Luc,

I‘ve almost completed my new host build script I just want to fine tune it a little. Currently to use the motion tcp stack for vmotion portgroups I’m using esxcli to enable the vmotion stack and create vmotion portgroups using the vmotion stack, then migrating the portgroups to DVS because my understanding is the esxcli method doesn’t work directly against DVS, however this was discussed a couple of weeks back and anothe option was to use the api. Can you can this api method works on DVS becaue if so I would prefer to set it directly on the DVS and potentially the possibility of writing a function / module for this?

Nicholas
Reply
0 Kudos
nicholas1982
Hot Shot
Hot Shot
Jump to solution

Hi Luc,

So tested this out and it failed unfortunately. I pre-created the portgroup on the default TCP/IP stack on VMK1 then ran this....

S C:\Users\user>> $esxName = 'esx.host.com'

$stackName = 'vmotion'

$ipGateway = '10.42.228.254'

$ipDevice = 'vmk1'

$esx = Get-VMHost -Name $esxName

$netSys = Get-View -Id $esx.ExtensionData.ConfigManager.NetworkSystem

$stack = $esx.ExtensionData.Config.Network.NetStackInstance | where{$_.Key -eq $stackName}

$config = New-Object VMware.Vim.HostNetworkConfig

$spec = New-Object VMware.Vim.HostNetworkConfigNetStackSpec

$spec.Operation = [VMware.Vim.ConfigSpecOperation]::edit

$spec.NetStackInstance = $stack

$spec.NetStackInstance.RouteTableConfig = New-Object VMware.Vim.HostIpRouteTableConfig

$route = New-Object VMware.vim.HostIpRouteConfig

$route.defaultGateway = $ipGateway

$route.gatewayDevice = $ipDevice

$spec.NetStackInstance.ipRouteConfig = $route

$config.NetStackSpec += $spec

$netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify)

Exception calling "UpdateNetworkConfig" with "2" argument(s): "An error occurred during host configuration. Operation failed, diagnostics report: Unable to Get Instance List: Sysinfo error: FailureSee VMkernel log for details."

At line:20 char:1

+ $netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode] ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : VimException

Nicholas
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Setting DNS only seems to work for the defaultTcpipStack, not for vmotion, nor for Provisioning.

For the defaultTcpipStack it works like this

$esxName = 'esx1.local.homelab'

$stackName = 'defaultTcpipStack'

$dnsServers = '192.168.1.200','192.168.1.201'

$domainName = 'local.homelab'

$hostName = 'esx1'

$esx = Get-VMHost -Name $esxName

$netSys = Get-View -Id $esx.ExtensionData.ConfigManager.NetworkSystem

$stack = $esx.ExtensionData.Config.Network.NetStackInstance | where{$_.Key -eq $stackName}

$config = New-Object VMware.Vim.HostNetworkConfig

$spec = New-Object VMware.Vim.HostNetworkConfigNetStackSpec

$spec.Operation = [VMware.Vim.ConfigSpecOperation]::edit

$spec.NetStackInstance = $stack

$spec.NetStackInstance.RouteTableConfig = New-Object VMware.Vim.HostIpRouteTableConfig

$dns = New-Object VMware.Vim.HostDnsConfig

$dns.Address = $dnsServers

$dns.Dhcp = $false

$dns.HostName = $hostName

$dns.DomainName = $domainName

$dns.SearchDomain = $domainName

$spec.NetStackInstance.DnsConfig = $dns

$config.NetStackSpec += $spec

$netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

nicholas1982
Hot Shot
Hot Shot
Jump to solution

Thanks Luc,

I managed to get what i needed working

Nicholas
Reply
0 Kudos
robbielozier
Enthusiast
Enthusiast
Jump to solution

How were you able to create the vmotion stack and then migrate the portgroups to DVS?

Reply
0 Kudos
sushilkm
Enthusiast
Enthusiast
Jump to solution

@lucd

I was wondering how can i customise this $esxName variable to include multiple esxi hosts. I have approx 120+ esxi which needs to have vmotion gateways 😞 😞 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

One way is to place all the names in an array, and then do a ForEach loop over that array.

Something like this

$esxNames = 'esx1.local.homelab','esx2.local.homelab','esx3.local.homelab'

$stackName = 'defaultTcpipStack'

$dnsServers = '192.168.1.200','192.168.1.201'

$domainName = 'local.homelab'

$hostName = 'esx1'

foreach($esxName in $esxNames){

   $esx = Get-VMHost -Name $esxName

   $netSys = Get-View -Id $esx.ExtensionData.ConfigManager.NetworkSystem

   $stack = $esx.ExtensionData.Config.Network.NetStackInstance | where{$_.Key -eq $stackName}

   $config = New-Object VMware.Vim.HostNetworkConfig

   $spec = New-Object VMware.Vim.HostNetworkConfigNetStackSpec

   $spec.Operation = [VMware.Vim.ConfigSpecOperation]::edit

   $spec.NetStackInstance = $stack

   $spec.NetStackInstance.RouteTableConfig = New-Object VMware.Vim.HostIpRouteTableConfig

   $dns = New-Object VMware.Vim.HostDnsConfig

   $dns.Address = $dnsServers

   $dns.Dhcp = $false

   $dns.HostName = $hostName

   $dns.DomainName = $domainName

   $dns.SearchDomain = $domainName

   $spec.NetStackInstance.DnsConfig = $dns

   $config.NetStackSpec += $spec

   $netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify)

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
sushilkm
Enthusiast
Enthusiast
Jump to solution

you are a Magician @Lucd . 

Reply
0 Kudos
mroova
Contributor
Contributor
Jump to solution

Hello,

One remark: This loop will set the same hostName for all ESXi servers (!)

Regards, 

Wojtek

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You are correct, thanks for noticing,
That line should have said

$dns.HostName = $esxName


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos