VMware NSX Edge SNAT vs DNAT – PowerShell Config

VMware NSX Edge SNAT vs DNAT – PowerShell Config

VMware NSX Edge SNAT vs DNAT

VMware NSX Edge SNAT vs DNAT – In this blog we would be looking at the differences between SNAT and DNAT and also look at ways to automate their configuration using PowerShell and NSX API’s.

Lets look at the two types of NAT, which are SNAT (Source NAT)  and DNAT (Destination NAT)

SNAT

SNAT or Source NAT allows us to change the source IP address of a network packet to another IP Address. although it does not allow us to change the destination IP address.

Using SNAT allows us to get improved security as we can use Private IP addresses, it helps in masking or hiding the IP of the device which is the requestor.

Ok so lets create an SNAT address using GUI and also look at ways to create it using API call.

Head over to the NSX edge, click on NAT and select add SNAT rule.

VMware NSX Edge SNAT vs DNAT

 

and enter in the required parameters and click on ok.

VMware NSX Edge SNAT vs DNAT

DNAT

DNAT or Destination NAT is used to translate the destination ip address of an network packet to another ip address, DNAT does not allows to change the source ip address, so lets take a scenario when a user accesses an internal application. Using DNAT we can hide the internal IP address of the application and substitute another IP for it and hence is more secure.

Creating a DNAT is similar to the way we created a SNAT, head over to the location identified on the above location and select add DNAT rule.

VMware NSX Edge SNAT vs DNAT

Now lets look at ways to create this using PowerShell and NSX APIs, unfortunately i was unable to find the cmdlet for this in PowerNSX hence i resorted to the old fashioned way of invoking the APIs using Invoke-WebRequest cmdlet.

Now if we look at the NSX API guide, we see the below body and PUT method to create SNAT / DNAT.

VMware NSX Edge SNAT vs DNAT

Now lets create a sample code based on the above syntax and invoke it using PowerShell.

As you can see in the above request, we are creating both a SNAT and DNAT rule.

Now if i refresh my vSphere Web-client i would be able to see the rules created.

Similarly i can also query for these Rules using the QUERY request, another look at the API guide shows that to query the rules i need to execute.

VMware NSX Edge SNAT vs DNAT

Lets implement this code in PowerShell and invoke this API call.

Once we execute the above code, you would be able to see the rules displayed on your screen.

VMware NSX Edge SNAT vs DNAT

I hope this blog was helpful and translates to some real world scenarios to use PowerNSX .

Do check out some of my other Posts on NSX

Please follow and like us:

Share this post

Post Comment