Event burst of esx.audit.net.firewall.config.changed started

I have a pretty new version of PowerCLI (5.5 Rel 1) and vCenter is 5.5 as is ESXi.

I also verified Automation.Core is installed:

PowerCLI C:\Windows\system32> Get-PSSnapin VMware.VimAutomation.Core

Name        : VMware.VimAutomation.Core

PSVersion   : 2.0

Description : This Windows PowerShell snap-in contains Windows PowerShell cmdle

              ts for managing vSphere.

but after connecting to vCenter, I get error trying to run:

PowerCLI C:\Windows\system32> $Results = ForEach ($DRSRule in $DRSRules)

>>      {

>>     "" | Select-Object-Property @{N="Cluster";E={(Get-View- Id $DRSRule.Clust

er.Id).Name}},

>>     @{N="Name";E={$DRSRule.Name}},

>>     @{N="Enabled";E={$DRSRule.Enabled}},

>>     @{N="DRS Type";E={$DRSRule.KeepTogether}},

>>     @{N="VMs";E={$VMIds=$DRSRule.VMIds -split ","

>>       $VMs = ForEach ($VMId in $VMIds)

>>         {

>>         (Get-View -Id $VMId).Name

>>         }

>>       $VMs -join ","}}

>>      }

>>

The term 'Select-Object-Property' is not recognized as the name of a cmdlet, fu

nction, script file, or operable program. Check the spelling of the name, or if

a path was included, verify that the path is correct and try again.

At line:3 char:32

+     "" | Select-Object-Property <<<<  @{N="Cluster";E={(Get-View- Id $DRSRule

.Cluster.Id).Name}},

    + CategoryInfo          : ObjectNotFound: (Select-Object-Property:String)

   [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

PowerCLI C:\Windows\system32> Add-PSSnapin VMware.VimAutomation.Core

Is 'Select-Object-Property not installed?  If not, where do I get it, please?

cheers

KC

note, I got this code from Dean here: PowerCLI: Retrieving DRS rules; Deans Blog

All ESXi hosts have an inbuilt firewall sitting between the management interface and the rest of the network. Enabled by default, the ESXi firewall is configured to drop all ingress and egress traffic but for a specific set of services, a subset of which is given in Figure 1 below.

In this article we explore how the firewall may be managed using the vSphere client, ESXCLI commands and PowerCLI. For illustration purposes, I’ll be using a standalone ESXi host but the same techniques apply to vCenter Server managed hosts.

Event burst of esx.audit.net.firewall.config.changed started

Figure 1 – A subset of the services running on ESXi and their corresponding ports

Managing the Firewall using the vSphere client

I’ll be using the C# vSphere Client since the web client is available only when vCenter Server has been installed, which is not the case here. Having said that, VMware Labs have released a fling you can use to manage an ESXi host via an embedded HTML/Javascript extension, though I still have to find out if you can edit firewall settings.

Update: As it were, I installed the fling and even though I admittedly haven’t really dug that deep, I do confirm that it allows you to update firewall rules. This will turn out to be a useful tool to anyone missing the vSphere Web Client.

Event burst of esx.audit.net.firewall.config.changed started

Managing ESXi through the “ESXi Embedded Host Client” fling

Regardless, I’ll stick to the C# vSphere client for now. To review the firewall settings on an ESXi host, log in with the vSphere Client, select the “Configuration” tab and highlight “Security Profile” under “Software”. You’ll see that the “Security Profile” pane is split into 3 areas, the two topmost ones “Services” and “Firewall” being the ones we’re interested in (Figure 2).

Event burst of esx.audit.net.firewall.config.changed started

Figure 2 – Security profile configuration screen for an ESXi host

Clicking on “Properties” under “Services” brings up a dialog box showing which services are enabled and those that aren’t. Clicking on the Options button gives you access to the startup policy for the selected service as you can see in Figure 3.

Event burst of esx.audit.net.firewall.config.changed started

Figure 3 – Start-up policy for a selected service

Similarly, clicking on “Properties” under the “Firewall” section gives you access to a specific service’s settings. A ticked on check-box next to a service tells you that the service is accepting remote access calls. Clicking on the “Firewall” button allows you to limit  remote access to the service in question.

For instance, let’s suppose you want to limit SSH access to the sysadmin team. Their workstations reside on the 192.168.10.0/24 network. To enact this rule, you just need to add the 192.168.10.0/24 network to the “Allowed IP Addresses” list as shown in the next Figure. Any call originating from outside this range will be dropped.

Event burst of esx.audit.net.firewall.config.changed started

Figure 4 – Restricting remote access to a service

Managing the Firewall using ESXCLI

The esxcli network firewall family of commands can be similarly used to manage the ESX firewall. To use them, you’ll need to SSH to the ESXi host using software such as putty.

The command set has a root namespace called ruleset with two child nodes these being allowedip and rule. A service has a ruleset attached to it which can either be disabled or enabled.  A ruleset can contain one or more rules.

Event burst of esx.audit.net.firewall.config.changed started

Figure 5 – Namespaces for the esxcli network firewall command

Here are a few examples to get you started with the command line syntax;

  • List all currently enabled (disabled) rulesets.
esxcli network firewall ruleset list | grep true
esxcli network firewall ruleset list | grep false

Event burst of esx.audit.net.firewall.config.changed started

List all currently enabled (disabled) rulesets

  • List rules associated with a particular service’s ruleset
esxcli network firewall ruleset rule list -r "sshServer"

Event burst of esx.audit.net.firewall.config.changed started

List rules associated with a particular service’s ruleset

Note: Use the –r parameter to target a specific service by its name which you can learn using the esxcli network firewall ruleset list command.

  • Enable a ruleset for a service and restrict remote access

In this example I’ll enable the SNMP server and specify that only ip address 192.168.11.201 has remote access to it

esxcli network firewall ruleset set -r "snmp" -a false -e true
esxcli network firewall ruleset allowedip add -r "snmp" -i "192.168.11.201"
  • List all the rulesets for which the allowedip list has been enabled
esxcli network firewall ruleset allowedip list | grep -v "All"

Event burst of esx.audit.net.firewall.config.changed started

List those rulesets for which allowedip has been enabled

  • Display the firewall status
esxcli network firewall get

Event burst of esx.audit.net.firewall.config.changed started

Display the firewall status

  • Disable the firewall
esxcli network firewall set -e false

Event burst of esx.audit.net.firewall.config.changed started

Disable the firewall

Here, you will find a complete list of all the available firewall commands.

Unfortunately there is no easy way – not that I know of – to add custom rulesets other than creating and importing them using VIB packaging. There’s a good article here on how to go about it. It definitely works as I have used it in the past to enable custom rulesets but it’s not for the impatient and takes some time to get used to. VMware refer to it in this KB article which also provides a link to this Word document explaining the entire procedure in full detail.

Note that the VIB method must be used to create custom rulesets that persist after reboots. Alternatively, there are 2 XML files you can play with as described here. Once again, these changes will not persist at least not on ESXi 5.5 and earlier versions – with ESXi 6 I’m not entirely sure since I got mixed results when testing. There’s a not so clean hack you can try where the /etc/rc.local.d/local.sh script is modified such that it copies the amended firewall XML files, which are stored on a datastore on the ESXi host’s local storage, every time it is rebooted. Regardless, my opinion is to stick with the VIB method, despite being cumbersome and all.

Managing the Firewall using PowerCLI

With PowerShell, there are a couple of options you can use to manage the ESXi firewall. You can either expose the same ESXCLI functionality through the Get-EsxCli cmdlet or use the following cmdlets;

  • Get-VMHostFirewallException
  • Set-VMHostFirewallException
  • Get-VMHostFirewallDefaultPolicy
  • Set-VMHostFirewallDefaultPolicy

However, if you’re already familiar with the ESXCLI syntax, you would naturally want to use get-EsxCLi since it’s pretty much the same thing save for a few syntactical differences. Here’s how to do it;

First of all, you need to retrieve the esxcli.network.firewall namespace and save it as an object. We do this as follows;

$esxcli = (get-esxcli –

vmhost

 192.168.11.117).network.firewall

Event burst of esx.audit.net.firewall.config.changed started

Retrieving esxcli.network.firewall in PowerShell

I’m going to replicate the examples I listed under the “Managing the Firewall using ESXCLI” section so you can compare and contrast.

  • List all currently enabled (disabled) rulesets
$ESXfw.ruleset.list() | Where {$_.Enabled -eq "false"}

Event burst of esx.audit.net.firewall.config.changed started

List all currently enabled (disabled) rulesets

  • List rules associated with a particular service’s ruleset
$ESXfw.ruleset.rule.list("sshServer")

Event burst of esx.audit.net.firewall.config.changed started

List rules associated with a particular service’s ruleset

  • Enable a ruleset for a service and restrict remote access
$ESXfw.ruleset.set($false, $true, "snmp")
$ESXfw.ruleset.allowedip.add("192.168.11.201","snmp")

Event burst of esx.audit.net.firewall.config.changed started

Enabling a ruleset for a service while restricting remote access

  • List all the rulesets for which the allowedip list has been enabled
$esxcli.ruleset.allowedip.list() | where {$_.AllowedIPAddresses -ne "All"}

Event burst of esx.audit.net.firewall.config.changed started

List those rulesets for which allowedip has been enabled

  • Display the firewall status
$esxcli.get()

Event burst of esx.audit.net.firewall.config.changed started

Display the firewall status

  • Disable the firewall (and set it to DROP packets)
$esxcli.set("false","false")

Event burst of esx.audit.net.firewall.config.changed started

Disable the firewall

Note the two Boolean values passed to the cmdlet. The first specifies the action the firewall takes with true=PASS and false=DROP. The 2nd parameter simply enables or disables the firewall.

Conclusion

As we’ve seen, there are a number of methods you can use to manage your ESXi host’s firewall settings. It would be great if with future releases, VMware would add an easy way to include custom rulesets as the current method is somewhat awkward and quite frankly a pain to deal with.

I hope you enjoyed reading this post and better still learned something from it.

[the_ad id=”4738″][the_ad id=”4796″]

How do I check ESXi firewall status?

You can list the current status of the firewall by running:.
esxcli network firewall get..
esxcli network firewall set –enabled false. ... .
esxcli network firewall rulesset list..
esxcli network firewall ruleset –enabled true –ruleset-id rulesetName..
esxcli network firewall ruleset –enabled false –ruleset-id rulesetName..

How do I disable firewall on ESXi host?

To enable or disable ESXi firewall rules on a host, use the Set-VMHostFirewallException cmdlet. You can use the Get-VMHostFirewallException cmdlet to specify the Secure Shell (SSH) client service and then pipe that to Set-VMHostFirewallException to enable that exception.

Is there a firewall on ESXi?

All ESXi hosts have an inbuilt firewall sitting between the management interface and the rest of the network. Enabled by default, the ESXi firewall is configured to drop all ingress and egress traffic but for a specific set of services, a subset of which is given in Figure 1 below.

How do I disable Esxcli?

From the vSphere Client select the ESXi Host and go to Configuration >> Security Profile. Under Services select Edit then select the ESXi Shell service and click options. Change the service to "Start and stop manually" and stop the service and click OK.