Technical Tip: How to block unauthorized connections to IPsec VPN
| Description | This article describes how to block unauthorized connections to IPsec VPN.
In some cases, there are unauthorized IPsec VPN connection attempts. By default, they are all blocked by the firewall, but it might be an eyesore to see multiple phase1 negotiation errors on the VPN events, as some of the errors might be negotiation errors for a legitimate VPN connection.
In this example the unauthorized remote IP is 192.168.88.152:
![]() |
| Scope | FortiGate. |
| Solution |
config firewall local-in-policy
If there is only a list of specific IPs to connect to the IPsec VPN, which in this case is an IPsec site-to-site VPN with a static remote gateway, it is possible to allow only the remote gateway IP and deny all IKE packets with the use of a local-in policy.
config firewall local-in-policy
The output after creating the local policy to allow only authorized remote gateways. The unauthorized IP is no longer able to negotiate and is no longer present on the VPN event logs.
Note: This is not applicable for dial-up IPsec VPN peers, as the user's IP might change and be blocked by the local-in policy. Starting from v7.6.0, it is possible to create the same policy from the GUI as well: GUI support for local-in policies After v7.6.1+, local-in policies cannot be configured with individual SD-WAN member interfaces but must be configured with the SD-WAN zone. For more information, see Troubleshooting Tip: Local-in, Central-SNAT, DoS policies etc are missing after upgrade to FortiOS v7.4.6 or v7.6.1.
Allowing specific IPs to have access while blocking all the other IPs using only one rule: To allow certain IPs to have access to the IKE while blocking all others. use the option 'srcaddr-negate enable', and use default action 'deny'. In this way the IKE traffic will be allowed to the addresses mentioned in 'Allowed_IPs' and will be blocked for all other IPs
config firewall local-in-policy
Another way to allow specific IP traffic while blocking all others is to use 'Exclude Member' option in address group. Create an Address group with members as all and enable 'Exclude Member' and specify the IPs that needs to be allowed.
Specify this address group in the local-in policy with default action as deny as shown below.
config firewall local-in-policy set action deny
To automatically block unauthorized IP addresses, it can be automated with the use of automation stitch. However, this method has a limitation: if a legitimate user enters an incorrect password, that user's IP address will also be added to the blocklist and need to be removed manually. Technical Tip: Blocking a failed IPsec VPN login using the automation stitch
Related articles: Technical Tip: Creating a Local-In policy (IPv4 and IPv6) on GUI |






