Created on 06-23-2024 11:40 PM Edited on 11-06-2024 11:05 PM By Jean-Philippe_P
Description | This article describes possible solutions to prevent NAT port or socket exhaustion. | |||||||||
Scope | FortiGate. | |||||||||
Solution |
NAT port exhaustion occurs when the FortiGate does not have enough source ports available to create a session or to NAT traffic to a specific destination since the source ports might already be used by other connections.
If one more connection is needed for the same destination IP on the same destination port then NAT port exhaustion will occur.
It can also be seen in the clash counter in the CLI:
FGT # diag sys session stat misc info: session_count=20 setup_rate=0 exp_count=0 reflect_count=0 clash=999
Note: When source ports are lower than 1024 and traffic passes through a firewall policy with NAT enabled, session clashes and port exhaustion occur early and frequently. Because for NAT'ing privileged ports FortiGate uses the range only 512-1023.
There are two scenarios where NAT exhaustion may happen:
Scenario 1: (Less likely to occur): NAT exhaustion for local traffic - traffic originating from the FortiGate (For example: SD-WAN SLA, Web ratings):
Scenario 2: NAT exhaustion for forward traffic – User traffic going to the internet:
This scenario is more likely to occur if there is a shared resource over the Internet that many users utilize, such as a well-known DNS server. In this DNS example, users will be establishing sessions to the same destination IP(s), the same protocol (UDP, IP Proto 17), and the same destination port (53). The FortiGate must have unique session entries to identify each session when performing NAT, and so the unique elements of the session that remain are the NAT Source IP of the session (either the FortiGate interface IP or an IP Pool address) and the NAT Source Port (which is allocated by the FortiGate).
The ideal solution is to increase the total number of NAT source ports that can be allocated to user sessions. This can be accomplished by creating and applying an IP Pool in the Firewall Policies that have more than one external Public IP configured (the available ports scales linearly with the number of external IPs available in the IP Pool).
Refer to the following article for more information on configuring IP Pools: Technical Tip: How to configure SNAT with IP pool
If this is not an option, then it may be possible to 'optimize' the usage of the limited NAT source ports that are available by removing as many expired/inactive sessions as possible. This is not generally relevant for TCP sessions (since TCP can signal when a session is completed/closed), but it is relevant for DNS and ICMP traffic (since neither protocol can signal the end of a session, they simply stop sending traffic).
This can be accomplished by reducing the UDP/ICMP session lifetimes so that inactive sessions are expired by the FortiGate more quickly. For example, UDP sessions have a default session expiration of 180 seconds, but for DNS sessions (which typically complete in a few seconds) this could be reduced substantially to 30 seconds or potentially even shorter. Refer to this KB article for information on adjusting Session TTLs (Time to Live) on the FortiGate: Technical Tip: Session timeout settings.
|
The Fortinet Security Fabric brings together the concepts of convergence and consolidation to provide comprehensive cybersecurity protection for all users, devices, and applications and across all network edges.
Copyright 2024 Fortinet, Inc. All Rights Reserved.