Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Example: Configuring a Policy-Based VPN

This example shows how to configure a policy-based IPsec VPN to allow data to be securely transferred between two sites.

Requirements

This example uses the following hardware:

  • Any SRX Series Firewall

    • Updated and revalidated using vSRX Virtual Firewall on Junos OS Release 20.4R1.
Note:

Are you interested in getting hands-on experience with the topics and operations covered in this guide? Visit the IPsec Policy-Based demonstration in Juniper Networks Virtual Labs and reserve your free sandbox today! You’ll find the IPsec VPN Policy-Based sandbox in the Security category.

Before you begin, read IPsec Overview.

Overview

In this example, you configure a policy-based VPN on SRX1 and SRX2. Host1 and Host2 use the VPN to send traffic securely over the Internet between both hosts.

Figure 1 shows an example of a policy-based VPN topology.

Figure 1: Policy-Based VPN TopologyPolicy-Based VPN Topology

IKE IPsec tunnel negotiation occurs in two phases. In Phase 1, participants establish a secure channel in which to negotiate the IPsec security association (SA). In Phase 2, participants negotiate the IPsec SA for authenticating traffic that will flow through the tunnel. Just as there are two phases to tunnel negotiation, there are two phases to tunnel configuration.

In this example, you configure interfaces, an IPv4 default route, and security zones. Then you configure IKE Phase 1, IPsec Phase 2, security policy, and TCP-MSS parameters. See Table 1 through Table 5.

Table 1: Interface, Static Route, and Security Zone Information for SRX1

Feature

Name

Configuration Parameters

Interfaces

ge-0/0/0.0

10.100.11.1/24

 

ge-0/0/1.0

172.16.13.1/24

Security zones

trust

  • The ge-0/0/0.0 interface is bound to this zone.

 

untrust

  • The ge-0/0/1.0 interface is bound to this zone.

Static routes

0.0.0.0/0

  • The next hop is 172.16.13.2.

Table 2: IKE Phase 1 Configuration Parameters

Feature

Name

Configuration Parameters

Proposal

standard

  • Authentication method: pre-shared-keys

Policy

IKE-POL

  • Mode: main

  • Proposal reference: standard

  • IKE Phase 1 policy authentication method: pre-shared-key ascii-text

Gateway

IKE-GW

  • IKE policy reference: IKE-POL

  • External interface: ge-0/0/1

  • Gateway address: 172.16.23.1

Table 3: IPsec Phase 2 Configuration Parameters

Feature

Name

Configuration Parameters

Proposal

standard

  • Using default configuration

Policy

IPSEC-POL

  • Proposal reference: standard

VPN

VPN-to-Host2

  • IKE gateway reference: IKE-GW

  • IPsec policy reference: IPSEC-POL

  • establish-tunnels immediately
Table 4: Security Policy Configuration Parameters

Purpose

Name

Configuration Parameters

This security policy permits traffic from the trust zone to the untrust zone.

VPN-OUT

  • Match criteria:

    • source-address Host1-Net

    • destination-address Host2-Net

    • application any

  • Permit action: tunnel ipsec-vpn VPN-to-Host2

This security policy permits traffic from the untrust zone to the trust zone.

VPN-IN

  • Match criteria:

    • source-address Host2-Net

    • destination-address Host1-Net

    • application any

  • Permit action: tunnel ipsec-vpn VPN-to-Host2

This security policy permits all traffic from the trust zone to the untrust zone.

You must put the VPN-OUT policy before the default-permit security policy. Junos OS performs a security policy lookup starting at the top of the list. If the default-permit policy comes before the VPN-OUT policy, all traffic from the trust zone matches the default-permit policy and is permitted. Thus, no traffic will ever match the VPN-OUT policy.

default-permit

  • Match criteria:

    • source-address any

    • source-destination any

    • application any

  • Action: permit

Table 5: TCP-MSS Configuration Parameters

Purpose

Configuration Parameters

TCP-MSS is negotiated as part of the TCP three-way handshake and limits the maximum size of a TCP segment to better fit the maximum transmission unit (MTU) limits on a network. This is especially important for VPN traffic, as the IPsec encapsulation overhead, along with the IP and frame overhead, can cause the resulting Encapsulating Security Payload (ESP) packet to exceed the MTU of the physical interface, thus causing fragmentation. Fragmentation results in increased use of bandwidth and device resources.

We recommend a value of 1350 as the starting point for most Ethernet-based networks with an MTU of 1500 or greater. You might need to experiment with different TCP-MSS values to obtain optimal performance. For example, you might need to change the value if any device in the path has a lower MTU, or if there is any additional overhead such as PPP or Frame Relay.

MSS value: 1350

Configuration

Configuring Basic Network and Security Zone Information

CLI Quick Configuration

To quickly configure this example for SRX1, copy the following commands, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, copy and paste the commands into the CLI at the [edit] hierarchy level, and then enter commit from configuration mode.

Step-by-Step Procedure

The following example requires you to navigate various levels in the configuration hierarchy. For instructions on how to do this, see the CLI User Guide.

To configure interface, static route, and security zone information:

  1. Configure the interfaces.

  2. Configure the static routes.

  3. Assign the Internet facing interface to the untrust security zone.

  4. Specify the allowed system services for the untrust security zone.

  5. Assign the Host1 facing interface to the trust security zone.

  6. Specify the allowed system services for the trust security zone.

Results

From configuration mode, confirm your configuration by entering the show interfaces, show routing-options, and show security zones commands. If the output does not display the intended configuration, repeat the configuration instructions in this example to correct it.

Configuring IKE

CLI Quick Configuration

To quickly configure this example for SRX1, copy the following commands, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, copy and paste the commands into the CLI at the [edit] hierarchy level, and then enter commit from configuration mode.

Step-by-Step Procedure

The following example requires you to navigate various levels in the configuration hierarchy. For instructions on how to do that, see the CLI User Guide.

To configure IKE:

  1. Create the IKE proposal.

  2. Define the IKE proposal authentication method.

  3. Create the IKE policy.

  4. Set the IKE policy mode.

  5. Specify a reference to the IKE proposal.

  6. Define the IKE policy authentication method.

  7. Create the IKE gateway and define its external interface.

  8. Define the IKE gateway address.

  9. Define the IKE policy reference.

Results

From configuration mode, confirm your configuration by entering the show security ike command. If the output does not display the intended configuration, repeat the configuration instructions in this example to correct it.

Configuring IPsec

CLI Quick Configuration

To quickly configure this example for SRX1, copy the following commands, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, copy and paste the commands into the CLI at the [edit] hierarchy level, and then enter commit from configuration mode.

Step-by-Step Procedure

The following example requires you to navigate various levels in the configuration hierarchy. For instructions on how to do that, see the CLI User Guide.

To configure IPsec:

  1. Create the IPsec proposal.

  2. Create the IPsec policy.

  3. Specify the IPsec proposal reference.

  4. Specify the IKE gateway.

  5. Specify the IPsec policy.

  6. Configure the tunnel to establish immediately.

Results

From configuration mode, confirm your configuration by entering the show security ipsec command. If the output does not display the intended configuration, repeat the configuration instructions in this example to correct it.

Configuring Security Policies

CLI Quick Configuration

To quickly configure this example for SRX1, copy the following commands, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, copy and paste the commands into the CLI at the [edit] hierarchy level, and then enter commit from configuration mode.

Step-by-Step Procedure

The following example requires you to navigate various levels in the configuration hierarchy. For instructions on how to do that, see the CLI User Guide.

To configure security policies:

  1. Create address book entries for the networks that will be used in the security policies.

  2. Create the security policy to match on traffic from Host1 in the trust zone to Host2 in the untrust zone.

  3. Create the security policy to permit all other traffic to the Internet from the trust zone to the untrust zone.

  4. Create a security policy to permit traffic from Host2 in the untrust zone to Host1 in the trust zone.

Results

From configuration mode, confirm your configuration by entering the show security policies command. If the output does not display the intended configuration, repeat the configuration instructions in this example to correct it.

Configuring TCP-MSS

CLI Quick Configuration

To quickly configure this example for SRX1, copy the following commands, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, copy and paste the commands into the CLI at the [edit] hierarchy level, and then enter commit from configuration mode.

Step-by-Step Procedure

To configure TCP-MSS information:

  1. Configure the TCP-MSS information.

Results

From configuration mode, confirm your configuration by entering the show security flow command. If the output does not display the intended configuration, repeat the configuration instructions in this example to correct it.

If you are done configuring the device, enter commit from configuration mode.

Configuring SRX2

CLI Quick Configuration

For reference, the configuration for SRX2 is provided.

To quickly configure this section of the example, copy the following commands, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, copy and paste the commands into the CLI at the [edit] hierarchy level, and then enter commit from configuration mode.

Verification

To confirm that the configuration is working properly, perform these tasks:

Verifying the IKE Status

Purpose

Verify the IKE status.

Action

From operational mode, enter the show security ike security-associations command. After obtaining an index number from the command, use the show security ike security-associations index index_number detail command.

Meaning

The show security ike security-associations command lists all active IKE Phase 1 security associations (SAs). If no SAs are listed, there was a problem with Phase 1 establishment. Check the IKE policy parameters and external interface settings in your configuration.

If SAs are listed, review the following information:

  • Index—This value is unique for each IKE SA, which you can use in the show security ike security-associations index detail command to get more information about the SA.

  • Remote Address—Verify that the remote IP address is correct.

  • State

    • UP—The Phase 1 SA has been established.

    • DOWN—There was a problem establishing the Phase 1 SA.

  • Mode—Verify that the correct mode is being used.

Verify that the following are correct in your configuration:

  • External interfaces (the interface must be the one that receives IKE packets)

  • IKE policy parameters

  • Preshared key information

  • Phase 1 proposal parameters (must match on both peers)

The show security ike security-associations index 1859361 detail command lists additional information about the security association with an index number of 1859361:

  • Authentication and encryption algorithms used

  • Phase 1 lifetime

  • Traffic statistics (can be used to verify that traffic is flowing properly in both directions)

  • Initiator and responder role information

    Troubleshooting is best performed on the peer using the responder role.

  • Number of IPsec SAs created

  • Number of Phase 2 negotiations in progress

Verifying the IPsec Phase 2 Status

Purpose

Verify the IPsec Phase 2 status.

Action

From operational mode, enter the show security ipsec security-associations command. After obtaining an index number from the command, use the show security ipsec security-associations index index_number detail command.

Meaning

The output from the show security ipsec security-associations command lists the following information:

  • The ID number is 2. Use this value with the show security ipsec security-associations index command to get more information about this particular SA.

  • There is one IPsec SA pair using port 500, which indicates that no NAT-traversal is implemented. (NAT-traversal uses port 4500 or another random high-number port.)

  • The SPIs, lifetime (in seconds), and usage limits (or lifesize in KB) are shown for both directions. The 921/ unlim value indicates that the Phase 2 lifetime expires in 921 seconds, and that no lifesize has been specified, which indicates that it is unlimited. Phase 2 lifetime can differ from Phase 1 lifetime, as Phase 2 is not dependent on Phase 1 after the VPN is up.

  • VPN monitoring is not enabled for this SA, as indicated by a hyphen in the Mon column. If VPN monitoring is enabled, U (up) or D (down) is listed.

  • The virtual system (vsys) is the root system, and it always lists 0.

The output from the show security ipsec security-associations index 2 detail command lists the following information:

  • The local identity and remote identity make up the proxy ID for the SA.

    A proxy ID mismatch is one of the most common reasons for a Phase 2 failure. For policy-based VPNs, the proxy ID is derived from the security policy. The local address and remote address are derived from the address book entries, and the service is derived from the application configured for the policy. If Phase 2 fails because of a proxy ID mismatch, you can use the policy to confirm which address book entries are configured. Verify that the addresses match the information being sent. Check the service to ensure that the ports match the information being sent.

Test Traffic Flow Across the VPN

Purpose

Verify the traffic flow across the VPN.

Action

Use the ping command from the Host1 device to test traffic flow to Host2.

Meaning

If the ping command fails from Host1, there might be a problem with the routing, security policies, end host, or encryption and decryption of ESP packets.

Reviewing Statistics and Errors for an IPsec Security Association

Purpose

Review ESP and authentication header counters and errors for an IPsec security association.

Action

From operational mode, enter the show security ipsec statistics index index_number command, using the index number of the VPN for which you want to see statistics.

You can also use the show security ipsec statistics command to review statistics and errors for all SAs.

To clear all IPsec statistics, use the clear security ipsec statistics command.

Meaning

If you see packet loss issues across a VPN, you can run the show security ipsec statistics command several times to confirm that the encrypted and decrypted packet counters are incrementing. You should also check if the other error counters are incrementing.