Lab 3 - Nat PDF
Lab 3 - Nat PDF
Lab 3 - Nat PDF
© FORTINET
Lab 3: Network Address Translation (NAT)
NAT is used to perform source NAT (SNAT) and destination NAT (DNAT) for the traffic passing through
FortiGate. There are two ways to configure source NAT and destination NAT:
You will configure and test SNAT using the central SNAT policy and DNAT using the DNAT policy and VIPs.
Objectives
l Configure destination NAT settings using a VIP.
l Configure the source NAT settings using overload IP pools.
l Configure a central NAT policy for the source NAT.
l Configure DNAT and VIPs for the destination NAT.
Time to Complete
Estimated: 50 minutes
Prerequisites
Before starting the procedures in this lab, you must restore a configuration file on each FortiGate.
Make sure to restore the correct configuration in each FortiGate using the following
steps. Failure to restore the correct configuration on each FortiGate will prevent you
from doing the lab exercise.
© FORTINET
VIP addresses are typically used to translate external or public IP addresses to internal or private IP addresses.
In this exercise, you will configure a VIP address for the Local-Windows VM. Then, you will create an egress-to-
ingress firewall policy and apply a VIP address. This will allow Internet connections to the Local-Windows VM.
You will also verify the destination NAT (DNAT) and source NAT (SNAT) behavior using CLI commands.
Create a VIP
On FortiGate, a VIP is a destination NAT (DNAT), which you can select only in a firewall policy’s destination
address field.
In this procedure, you will configure the VIP to map the Local-Windows VM (10.0.1.10) to 10.200.1.200,
which is a part of the port1 subnet. You can refer to the lab Network Topology on page 10 diagram.
To create a VIP
1. On the Local-Windows VM, open a browser and log in to the Local-FortiGate GUI at 10.0.1.254 with the user
name admin and password password.
2. Click Policy & Objects > Virtual IPs.
3. Click Create New, and then select Virtual IP.
4. Configure the following settings:
Field Value
Name VIP-INTERNAL-HOST
Interface port1
© FORTINET
5. Click OK.
You will configure a new firewall policy using the VIP that you just created as the destination address.
Field Value
Name Web-Server-Access
Source all
Destination VIP-INTERNAL-HOST
Schedule always
Tip: In right pane, type the name in the search box, and then click
Services to add.
Action ACCEPT
© FORTINET
4. In the Firewall / Network Options section, turn off the NAT switch.
5. In the Logging Options section, turn on the Log Allowed Traffic switch, and then select All Sessions.
6. Click OK.
© FORTINET
Now that you've configured a firewall policy with the VIP address as the destination, you can test your VIP by
accessing it from the Remote-Windows VM, which is behind the Remote-FortiGate internal network. Traffic is
routed from the Remote-FortiGate to the Local-FortiGate by a Linux machine, which acts as a router between
these two FortiGate devices. For more information, see Network Topology on page 10.
You will also test how the source address is translated by the VIP when traffic is leaving from the Local-Windows
VM.
2. On the Local-Windows VM, open PuTTY and connect over SSH to the LOCAL-FORTIGATE saved session.
3. At the login prompt, enter the user name admin and password password.
4. Enter the following command to check the destination NAT entries in the session table:
get system session list
Sample output:
Local-FortiGate# get system session list
PROTO EXPIRE SOURCE SOURCE-NAT DESTINATION DESTINATION-NAT
tcp 3594 10.200.3.1:49478 - 10.200.1.200:80 10.0.1.10:80
You will notice that the destination address 10.200.1.200 is translated to 10.0.1.10, which is the
mapping you configured in the VIP.
© FORTINET
Test the Source NAT
As a result of the VIP (which is a static NAT), all translated outgoing connections from the Local-Windows VM (IP
address 10.0.1.10) will use the VIP address to source NAT for the ingress-to-egress firewall policy and not the
egress interface IP address.
To test SNAT
1. Continuing on Local-Windows, return to the Local-FortiGate PuTTY session and run the following command to
clear any existing sessions:
The CLI command diagnose sys session clear will clear all sessions
including SSH session you created using PuTTY. This is expected behavior.
The firewall is stateful, so any existing sessions will not use this new firewall policy
until they time out or are cleared for ingress-to-egress traffic.
This clears the session to the Local-FortiGate from the Local-Windows VM.
Sample output:
© FORTINET
The outgoing connections from the Local-Windows VM are now being translated with
the VIP address 10.200.1.200, instead of the firewall egress interface IP address
(10.200.1.1).
This is a behavior of the SNAT VIP. That is, when you enable SNAT on a policy, a VIP static NAT takes
priority over the destination interface IP address.
IP pools are used to translate the source address to an address from that pool, rather than the egress interface
address.
Currently, the Local-FortiGate translates the source IP address of all traffic generated from the Local-Windows
VM to 10.200.1.200 because of the SNAT translation in the VIP.
In this exercise, you will create an IP pool, apply it to the ingress-to-egress firewall policy, and verify the SNAT
address using CLI commands.
Create an IP Pool
In this procedure, you will create an IP pool from the range of public IP addresses available on the egress port
(port1).
To create an IP pool
1. On the Local-Windows VM, open a browser and log in to the Local-FortiGate GUI at 10.0.1.254 with the user
name admin and password password.
2. Click Policy & Objects > IP Pools.
3. Click Create New and configure the following settings:
Field Value
Name INTERNAL-HOST-EXT-IP
Type Overload
4. Click OK.
Now, you will apply the IP pool to change the behavior from static NAT to dynamic NAT on the ingress-to-egress
firewall policy.
© FORTINET
To edit the firewall policy
1. Continuing on the Local-FortiGate GUI, click Policy & Objects > IPv4 Policy.
2. Right-click the ID column for the Full_Access firewall policy and click Edit.
3. In the Firewall / Network Options section, configure the following settings:
Field Value
NAT <enable>
4. Click the + that appeared when you clicked Use Dynamic IP Pool, and from the right pane, click INTERNAL-
HOST-EXT-IP.
Your configuration will look similar to the following example:
5. Click OK.
Now that your configuration is ready, you can test dynamic NAT with IP pools by browsing to a few external sites
on the Internet. If successful, you will see that the Local-Windows VM IP address (10.0.1.10) is translated to
the IP pool address of 10.200.1.100.
© FORTINET
To test dynamic NAT with IP pools
1. Continuing on the Local-Windows VM, open PuTTY and connect over SSH to the LOCAL-FORTIGATE saved
session.
2. At the login prompt, enter the user name admin and password password.
3. Run the following command to clear any existing sessions:
The CLI command diagnose sys session clear will clear all sessions
including the SSH session you created using PuTTY. This is expected behavior.
The firewall is stateful, so any existing sessions will not use this updated firewall policy
until they time out or are cleared for ingress-to-egress traffic.
Sample output:
© FORTINET
Notice that the source NAT address is now 10.200.1.100, as configured in the IP pool, and the IP pool
has overridden the static NAT VIP.
8. Close PuTTY.
9. Close all browser tabs except the Local-FortiGate GUI.
A central SNAT policy is applied to multiple firewall policies, based on a configured central rule.
In this exercise, you will configure a central SNAT policy and test it.
Prerequisites
Before beginning this lab, you must restore a configuration for central NATfile to Local-FortiGate.
Make sure to restore the correct configuration for Local-FortiGate using the following
steps. Failure to restore the correct configuration on Local-FortiGate will prevent you
from doing the lab exercise.
© FORTINET
When enabling central NAT, you must remove VIP and IP pool references from the
existing firewall policies first.
For example, you will see the following error if you try to enable central NAT without
removing VIP and IP pool references from the existing firewall policies.
To prevent this error from occurring during this exercise, the VIP and IP pool
references must be removed from the firewall policies.
1. The IP pool has been removed from the Full_Access firewall policy (policy ID 1),
and the VIP address has been removed from the Web-Server-Access firewall
policy (policy ID 2), because central NAT can be enabled only if none of the firewall
policies have IP pool and VIP addresses associated with them.
2. The VIP object you added in a previous exercise to test the firewall policy source
NAThas been removed.
In this procedure, you will configure a central SNAT policy using the IP pool you created in the previous exercise.
Field Value
NAT <enable>
© FORTINET
Field Value
Protocol ANY
3. Keep the default values for the remaining settings and click OK to save the changes.
If no central SNAT or matching central SNAT rule exists, FortiGate drops the
traffic.
© FORTINET
Review the Firewall Policy
There is no option for enabling NAT and/or using IP pools. In central SNAT, NAT on
the SNAT policy controls whether the NAT is used or not.
4. Click Cancel.
Now that your configuration is ready, you can test the behavior of the central SNAT policy.
© FORTINET
3. Run the following command to clear the existing sessions:
The CLI command diagnose sys session clear will clear all sessions
including the SSH session you created using PuTTY. This is expected behavior.
Sample output:
Notice that the source NAT address is now 10.200.1.100, which matches the IP Pool configured in central
SNAT policy.
9. Close PuTTY.
10. Close all browser tabs except the Local-FortiGate GUI.
Now you will create a second IP Pool, which you will use later when creating a second central SNAT policy.
© FORTINET
Take the Expert Challenge!
On the Local-FortiGate GUI, create a second IP Pool named SNAT-Pool with IP range 10.200.1.50 -
10.200.1.50 and the type as Overload.
If you require assistance, or to verify your work, use the step-by-step instructions that follow.
After you complete the challenge, see Create a Second SNAT Policy on page 70
Field Value
Name SNAT-Pool
Type Overload
3. Click OK.
Now you will create a more granular SNAT policy by selecting a specific destination address and protocol to
match specific traffic.
If you require assistance, or to verify your work, use the step-by-step instructions that follow.
After you complete the challenge, see Reorder Central SNAT Policies on page 71
© FORTINET
Field Value
NAT <enable>
Protocol TCP
3. Click OK.
Now you will reorder the central NAT policies to put the more granular rule at the top.
Similar to firewall policies, a central SNAT policy is processed from top to bottom and, if a match is found, the
source address and source port translate based on that central SNAT policy.
© FORTINET
To reorder central SNAT policies
1. Continuing on the Local-FortiGate GUI, click Policy & Objects > Central SNAT.
2. Drag the newly created central SNAT policy above the previously created central SNAT policy.
Now that your configuration is ready, you will test the central SNAT configuration.
ping -t 10.200.3.1
8. Open PuTTY and connect over SSH to the LOCAL-FORTIGATE saved session.
9. At the login prompt, enter the user name admin and password password.
10. Run the following command:
Notice that the TCP sessions to destination 10.200.3.1 are translated to 10.200.1.50, because that
address matches the central SNAT policy.
Sample output:
© FORTINET
ICMP sessions to destination 10.200.3.1 are translated to 10.200.1.100, which matches the central
SNAT policy at the bottom.
Sample output:
11. Open several browser tabs and connect to a few websites. For example:
l www.fortinet.com
l www.yahoo.com
l www.bbc.com
12. Return to LOCAL-FORTIGATE PuTTY session.
13. Run the following command:
Also, other TCP sessions to different destinations are translated to 10.200.1.100, based on the
matching central SNAT policy at the bottom.
A Central SNAT policy is processed from top to bottom, similar to firewall policies.
In firewall policy NAT, Virtual IPs is selected in the firewall policy as the destination address. In central NAT, as
soon as DNAT & Virtual IPs is configured, FortiGate automatically creates a rule in the kernel to allow DNAT to
occur, and no additional configuration is required.
In this exercise, you will configure and test the behavior of central DNAT.
Field Value
Name Central-DNAT
Interface port1
5. Click OK.
© FORTINET
Verify the Firewall Policy Settings
Now, you will verify the firewall policy settings for the egress-to-ingress firewall policy.
You can't select VIPs previously created in a firewall policy as a destination address.
As soon as a VIP object is created, FortiGate automatically creates a rule in the kernel
for DNAT to occur.
5. Scroll to the bottom of the page and ensure the Enable this policy switch is turned on.
6. Click OK.
In this procedure, you will test DNAT and VIPs by accessing the Local-Windows VM.
http://10.200.1.150
Sample output:
Local-FortiGate # get system session list
PROTO EXPIRE SOURCE SOURCE-NAT DESTINATION DESTINATION-NAT
© FORTINET
tcp 3599 10.200.3.1:49183 10.200.1.100 10.200.1.150:80 10.0.1.10:80
6. Open additional web browser tabs and try to access few websites. For example:
l www.fortinet.com
l www.yahoo.com
l www.bbc.com
7. Return to the Local-FortiGate PuTTY session and verify the SNAT IP address those sessions are using:
Sample output:
Notice that the session originating from source IP, 10.0.1.10, is translated to 10.200.1.150 (VIP) as
opposed to the central SNAT policy pool IP of 10.200.1.100. This is expected behavior in central NAT.
If both the SNAT and DNAT are defined, the egress traffic will source NAT to the
DNAT/VIP address, as opposed to the configured source SNAT policy.
8. Close PuTTY.
9. Close all browser tabs except the Local-FortiGate GUI.