Step-by-Step IPSec over GRE Tunnel Setup on Cisco Routers

IPSec over GRE is one of the most important topics in network security. It combines the encryption and authentication capabilities of IPSec with the routing flexibility of GRE tunneling. This approach allows organizations to securely transmit data across untrusted networks such as the Internet while still supporting multiple protocols and multicast traffic through GRE. In this guide, we focus on implementing IPSec over GRE on Cisco IOS routers to understand the core configuration. Although many Cisco security courses cover this topic, it often does not receive the attention it deserves. In practice, IPSec over GRE is widely deployed in many organizations to secure sensitive data as it travels over insecure networks. We will break down the concept and configuration process so that you can confidently apply it in real-world environments.

Importance of IPSec over GRE in Network Security

Organizations face constant threats when transmitting data across public networks. Unencrypted traffic is vulnerable to interception, manipulation, and unauthorized access. IPSec provides encryption, authentication, and integrity, ensuring that data is protected while in transit. GRE, on the other hand, allows the encapsulation of various network layer protocols into a single tunnel. By combining these technologies, you can transport multiple types of traffic, including routing protocols, between two sites while encrypting only the necessary payload. This method offers a balance between security and efficiency, as it avoids encrypting unnecessary control traffic while securing sensitive data flows. IPSec over GRE is particularly useful in site-to-site VPN deployments where routing flexibility is needed without the additional overhead of encrypting all tunnel traffic.

Understanding the Example Topology

To understand IPSec over GRE configuration, consider a simple topology with two branch routers connected via the Internet. Router R1 at Branch-01 has two interfaces: one with IP address 100.0.0.1/24 connected to the internet and another with IP address 192.168.1.1/24 connected to the local network. Router R2 at Branch-02 also has two interfaces: one with IP address 200.0.0.1/24 connected to the internet and another with IP address 172.1.1.1/24 connected to its local network. A GRE tunnel is created between the two routers, with R1’s tunnel interface 10 using IP address 10.0.0.1/24 and tunnel destination 200.0.0.1, and R2’s tunnel interface 12 using IP address 10.0.0.2/24 and tunnel destination 100.0.0.1. Once the GRE tunnel is established, an IPSec site-to-site VPN is configured between the two tunnel interfaces using a pre-shared key. The goal is to secure the data passing through the GRE tunnel while allowing routing updates and other control traffic to remain in clear text.

IPSec over GRE and Site-to-Site VPNs

A site-to-site VPN allows secure communication between two fixed locations over the public internet. IPSec is commonly used to build these VPNs because of its strong encryption and authentication features. By integrating GRE into this setup, you gain the ability to carry multiple protocols, not just IP, and to support multicast and broadcast traffic. GRE over IPSec encrypts all GRE-encapsulated traffic, including routing protocol updates. IPSec over GRE, however, encrypts only the interesting traffic defined by access control lists, leaving other tunnel traffic unencrypted. This approach is efficient when routing updates do not require encryption,, but application traffic does. In many organizations, IPSec over GRE is the preferred choice because it provides a good balance between security and network performance.

How IPSec over GRE Works

The IPSec over GRE process begins by establishing a GRE tunnel between two routers. This tunnel creates a virtual point-to-point link that can carry multiple types of traffic. Routing protocols such as OSPF or EIGRP can run over this tunnel without encryption. Once the GRE tunnel is up, IPSec policies are applied to secure only the specified traffic flowing between the two tunnel endpoints. This is achieved using access control lists to identify the interesting traffic that needs encryption. IPSec then uses these lists to apply its encryption and authentication algorithms to the selected traffic. This method reduces processing overhead by not encrypting unnecessary control messages, while still providing end-to-end protection for sensitive data.

ISAKMP and IPSec Phases

Building an IPSec connection involves the use of ISAKMP, also known as Internet Key Exchange (IKE). ISAKMP negotiation is divided into two phases. In Phase 1, the two peers establish a secure, authenticated channel for further negotiations. This channel protects the messages exchanged during Phase 2. Phase 2 creates the IPSec tunnel that encrypts the data traffic. The parameters for encryption, authentication, and key exchange are agreed upon during these phases. ISAKMP ensures that both sides have matching security policies, and once the tunnels are established, IPSec encrypts the traffic using the agreed-upon algorithms.

Why Use IPSec over GRE Instead of GRE over IPSec

The decision between IPSec over GRE and GRE over IPSec depends on your security and routing requirements. GRE over IPSec encrypts all GRE-encapsulated packets, including routing updates and control messages. This approach is more secure but also more resource-intensive, as every packet passing through the tunnel is encrypted. IPSec over GRE, on the other hand, encrypts only the defined interesting traffic, leaving routing updates unencrypted. This reduces CPU load on the routers and improves performance, making it ideal for situations where securing control traffic is not a priority. Additionally, IPSec over GRE eliminates the need to encrypt the GRE header, further reducing processing requirements.

Practical Uses of IPSec over GRE

IPSec over GRE is widely used in enterprise networks to connect branch offices to a central site. It is also deployed between data centers for secure application data exchange. Service providers may use it to offer secure connectivity to customers while supporting dynamic routing protocols. In testing and lab environments, IPSec over GRE is valuable for simulating secure WAN connections while experimenting with routing protocols. This flexibility makes it a core skill for network engineers working in environments where security and routing capabilities must work together seamlessly.

Preparing the Environment for IPSec over GRE Configuration

Before configuring IPSec over GRE, it is essential to prepare the routers and network environment. Both routers must have interfaces configured with the correct IP addresses for their public and internal connections. They should also have routing set up to reach each other’s public IP addresses. In most production deployments, static public IP addresses are used for each site. This ensures that the tunnel destinations remain consistent. If your routers are connected through the internet, make sure that any firewalls or access control devices between them permit GRE and IPSec traffic. GRE uses IP protocol 47, and IPSec typically uses UDP port 500 for IKE Phase 1 negotiations and UDP port 4500 for NAT traversal. ESP (Encapsulating Security Payload) uses IP protocol number 50. Properly preparing the environment prevents connectivity problems later during tunnel establishment.

Assigning IP Addresses to Interfaces

In this example, Router R1 represents Branch-01 and Router R2 represents Branch-02. On Router R1, the interface facing the internet is assigned IP address 100.0.0.1/24, and the LAN-facing interface is assigned IP address 192.168.1.1/24. On Router R2, the interface facing the internet is assigned IP address 200.0.0.1/24, and the LAN-facing interface is assigned IP address 172.1.1.1/24. These addresses ensure proper separation between the private and public networks at each site. In practice, these public IP addresses may be replaced with the actual assigned addresses from the ISP. Both routers must be able to ping each other’s public IP addresses before GRE or IPSec configuration begins.

Configuring the GRE Tunnel Interfaces

On Router R1, a tunnel interface numbered 10 is created. This interface is assigned IP address 10.0.0.1/24, with the tunnel source set to the internet-facing interface and the tunnel destination set to Router R2’s public IP address 200.0.0.1. On Router R2, a tunnel interface numbered 12 is created. This interface is assigned IP address 10.0.0.2/24, with the tunnel source set to its internet-facing interface and the tunnel destination set to Router R1’s public IP address 100.0.0.1. The GRE tunnel forms a point-to-point link between the two routers, allowing them to exchange routing information and application traffic. After configuration, the tunnel interfaces should be in the up/up state, and each router should be able to ping the other’s tunnel IP address.

Understanding the Role of Access Control Lists in IPSec

Access control lists (ACLs) play a key role in defining the traffic that IPSec will encrypt. In IPSec over GRE, ACLs are used to identify the interesting traffic between the two tunnel IP addresses. Only this traffic is passed through the IPSec encryption process. All other traffic on the GRE tunnel, such as routing protocol updates, remains unencrypted. This selective encryption reduces processing overhead and ensures efficient performance. The ACLs must be mirrored on both routers so that both peers agree on what traffic should be encrypted.

Configuring ISAKMP Policies for Phase 1

ISAKMP Phase 1 policies define how the two routers will negotiate and authenticate with each other before building the IPSec tunnel. These policies specify the encryption algorithm, hashing method, authentication type, Diffie-Hellman group, and lifetime. For example, you might use AES-256 for encryption, SHA for hashing, pre-shared key authentication, Diffie-Hellman group 2, and a lifetime of 86400 seconds. On each router, a pre-shared key must be defined for the peer’s public IP address. This key must match on both sides. In our example, the pre-shared key is unnets@123. Once the ISAKMP policies are in place, the routers will be able to establish the secure control channel during Phase 1.

Configuring IPSec Transform Sets for Phase 2

The IPSec transform set defines how the data will be protected in Phase 2. It specifies the combination of encryption and authentication algorithms used for the traffic. A common choice is AES for encryption and SHA for integrity checking. The transform set is referenced by a crypto map, which ties together the ACL, peer address, and IPSec settings. Both routers must have matching transform sets for the tunnel to work. The transform set is where you determine the level of encryption strength applied to your data. Stronger algorithms provide more security but require more processing power.

Building the Crypto Map and Applying It

The crypto map is the key configuration element that links the peer IP, the access list defining interesting traffic, and the transform set. It also specifies whether Perfect Forward Secrecy is used, which enhances security by generating new keying material for each session. The crypto map is applied to the physical interface that faces the Internet. In our example, the crypto map on Router R1 is applied to the interface with IP address 100.0.0.1, and on Router R2 it is applied to the interface with IP address 200.0.0.1. Once applied, the routers will attempt to negotiate the IPSec tunnel when interesting traffic is detected.

Verifying Tunnel Establishment

After configuration, the tunnel should be verified step by step. First, check basic IP connectivity between the routers’ public interfaces. Then, verify the GRE tunnel by pinging the tunnel IP addresses 10.0.0.1 and 10.0.0.2 from each side. If the pings are successful, check the ISAKMP security associations to ensure Phase 1 is complete. This can be done with commands such as show crypto isakmp sa. Finally, verify IPSec security associations with commands such as show crypto ipsec sa to confirm that Phase 2 is established and packets are being encrypted. If the associations are in place and packets are encrypted, the IPSec over GRE tunnel is functioning correctly.

Troubleshooting Common Issues

When IPSec over GRE does not work as expected, the problem can be in several areas. If the GRE tunnel is down, check that the tunnel source and destination IP addresses are correct and reachable. If the GRE tunnel is up but IPSec is not established, verify that the ISAKMP policies and pre-shared keys match on both routers. Ensure that ACLs defining interesting traffic are correct and identical on both sides. Also, check that any firewall between the routers is allowing IKE, ESP, and GRE traffic. Packet captures can help confirm whether the negotiation packets are reaching the other side. Incrementing packet counters in the show crypto ipsec sa output is a sign that encryption and decryption are occurring successfully.

Security Considerations

Although IPSec over GRE is secure for the defined interesting traffic, keep in mind that routing updates and other GRE control traffic are sent in clear text. If you require encryption for routing protocols as well, GRE over IPSec may be a better choice. Additionally, choose strong encryption algorithms and hashing methods to protect against modern cryptographic attacks. Use access lists to tightly control which traffic is sent through the IPSec tunnel, and periodically rotate the pre-shared key to reduce the risk of compromise. Regularly reviewing the IPSec configuration and monitoring logs for unusual activity is also part of good security practice.

Step-by-Step Configuration on Router R1

The configuration process on Router R1 begins with setting the IP addresses for the interfaces. The interface facing the internet must be assigned the public IP address 100.0.0.1/24, and the internal LAN interface must be assigned the private IP address 192.168.1.1/24. This separation allows the router to differentiate between traffic that comes from the local network and traffic that traverses the public internet. Once the IP addresses are configured, the router must have basic routing or static routes in place to reach the other site’s public IP address. After the basic IP setup, the GRE tunnel interface is created with the command to specify a tunnel number, in this case, tunnel 10. The tunnel interface is given IP address 10.0.0.1/24, the tunnel source is set to the internet-facing interface, and the tunnel destination is set to the public IP address of Router R2, which is 200.0.0.1. This configuration creates a logical link between the two routers. When the tunnel is brought up, it will act as a direct link, even though the physical connectivity is through the public internet. At this stage, a basic ping test between the tunnel IP addresses is used to confirm GRE connectivity before applying IPSec.

Step-by-Step Configuration on Router R2

On Router R2, the process mirrors that of Router R1. The internet-facing interface is assigned the public IP address 200.0.0.1/24, and the LAN interface is assigned the private IP address 172.1.1.1/24. Routing is configured so that Router R2 knows how to reach Router R1’s public IP address 100.0.0.1. The GRE tunnel interface on Router R2 is created as tunnel 12 and assigned the IP address 10.0.0.2/24. The tunnel source is the internet-facing interface, and the tunnel destination is Router R1’s public IP address 100.0.0.1. This mirrors the setup on R1, forming a point-to-point GRE tunnel between the two routers. Once configured, a ping from Router R2’s tunnel IP 10.0.0.2 to Router R1’s tunnel IP 10.0.0.1 should succeed, confirming GRE connectivity.

Configuring the Access Control Lists

Access control lists are critical in defining which traffic will be protected by IPSec. On Router R1, an extended ACL is created to match traffic between the two tunnel IP addresses. This ACL should only include the traffic that needs encryption. For example, you might specify that traffic between 10.0.0.1 and 10.0.0.2 is interesting traffic. On Router R2, a mirrored ACL is created with the same matching criteria. The ACLs must match on both routers to avoid mismatches during IPSec negotiation. Incorrect ACLs can result in partial or failed encryption because the two ends will not agree on what traffic needs to be secured.

Configuring ISAKMP for Phase 1 on Router R1

ISAKMP Phase 1 settings define how the two routers will authenticate and establish the initial secure channel. On Router R1, a crypto ISAKMP policy is configured to specify parameters such as the encryption algorithm AES, the hashing method SHA, the authentication type pre-share, the Diffie-Hellman group, and the lifetime. The pre-shared key unnets@123 is then applied for the peer address, which is the public IP address of Router R2. This key must be identical on both routers. If there is any mismatch in the key, the routers will fail to establish Phase 1.

Configuring ISAKMP for Phase 1 on Router R2

On Router R2, the ISAKMP configuration mirrors that of Router R1. The same encryption algorithm AES, hashing method SHA, authentication type pre-share, and Diffie-Hellman group must be used. The pre-shared key unnets@123 is configured for the peer address 100.0.0.1, which is Router R1’s public IP address. Any deviation in these settings from Router R1’s configuration will result in the inability to complete ISAKMP Phase 1. Once both sides have matching ISAKMP policies and pre-shared keys, the Phase 1 negotiation should be successful.

Creating IPSec Transform Sets

A transform set defines the security protocols and algorithms used in IPSec Phase 2. On Router R1, a transform set might be named TS-SET and configured to use ESP with AES for encryption and SHA for integrity. Router R2 must have an identical transform set configuration. The transform set is then referenced later in the crypto map configuration. Matching transform sets on both routers is essential because IPSec Phase 2 will fail if the settings do not align.

Building the Crypto Map on Router R1

The crypto map ties together the peer IP address, the access list defining interesting traffic, and the transform set. On Router R1, the crypto map is given a name and sequence number, with the peer address set to Router R2’s public IP address 200.0.0.1. The access list created earlier is applied to match the interesting traffic, and the transform set is bound to the crypto map. The crypto map is then applied to the physical interface facing the internet, which in this case has IP address 100.0.0.1. Once applied, IPSec negotiation will begin whenever traffic matching the ACL is detected.

Building the Crypto Map on Router R2

On Router R2, the crypto map mirrors the configuration on Router R1. The peer address is set to 100.0.0.1, the access list matches the same interesting traffic as Router R1, and the identical transform set is applied. The crypto map is then applied to the interface with IP address 200.0.0.1, which faces the internet. When this configuration is complete, both routers will be ready to negotiate the IPSec tunnel for the GRE traffic.

Verifying ISAKMP and IPSec Security Associations

Verification is a critical step in confirming that the tunnel is functioning correctly. On both routers, the show crypto isakmp sa command is used to check Phase 1 status. The output should indicate that the state is QM_IDLE, meaning the Phase 1 negotiation is complete. For Phase 2 verification, the show crypto ipsec sa command shows the active security associations and packet counters. These counters should increase as traffic flows through the tunnel, indicating successful encryption and decryption.

Testing Connectivity Across the Tunnel

To test the tunnel, initiate traffic from the LAN of one router to the LAN of the other. For example, ping from a host in the 192.168.1.0/24 network on Branch-01 to a host in the 172.1.1.0/24 network on Branch-02. If the tunnel is working, the ping should succeed, and the packet counters in the IPSec security associations should increase. If the ping fails, check the ACLs, ISAKMP policies, and transform sets to ensure they match on both routers.

Fine-Tuning the Configuration

Once the tunnel is operational, you can fine-tune the configuration for performance and security. Adjust the lifetime values in the ISAKMP policy and IPSec settings to balance security and performance. Enable Perfect Forward Secrecy in the crypto map to enhance security. Monitor CPU usage on the routers to ensure that encryption processes are not overloading the hardware. You can also add redundancy by configuring multiple tunnels between different interfaces or routers to provide failover in case of link failure.

Advanced Verification Techniques

After establishing the IPSec over a GRE tunnel, advanced verification ensures long-term stability and performance. Basic ping tests and packet counter checks confirm initial success, but deeper inspection verifies that the tunnel will remain reliable under varying traffic conditions. Using the show crypto session command provides detailed information on the current state of ISAKMP and IPSec sessions, including lifetimes and negotiation status. The show interfaces tunnel command can confirm the GRE tunnel’s operational status, bandwidth usage, and packet drop counts. Combining these commands provides a comprehensive view of tunnel health.

Monitoring Tunnel Stability Over Time

Long-term monitoring is critical to ensure that the IPSec over GRE tunnel does not experience intermittent drops or renegotiations. Configuring logging for ISAKMP and IPSec events helps track when tunnels are established or torn down. Logs will also reveal if Phase 1 or Phase 2 negotiations fail due to mismatched parameters. Periodic testing of application performance over the tunnel, such as transferring large files or streaming video, ensures the tunnel supports real-world workloads. Network management tools that poll router performance counters can alert administrators to unusual activity, such as sudden increases in dropped packets or CPU usage.

Troubleshooting Tunnel Failures

When the tunnel fails, isolating the problem is essential. If the GRE tunnel interface is down, confirm that both endpoints’ public IP addresses are reachable via ping or traceroute. If the GRE tunnel is up but IPSec is not establishing, check that both routers have identical ISAKMP policies, pre-shared keys, and transform sets. Packet captures at the WAN interface can confirm whether ISAKMP packets are being exchanged. If packets are not arriving, the issue could be firewall restrictions or incorrect routing. If Phase 1 completes but Phase 2 fails, the problem is often in the ACL definitions for interesting traffic. Ensuring both routers have mirrored ACLs typically resolves these issues.

Performance Optimization

The efficiency of IPSec over GRE depends on proper hardware resources and configuration. Routers with hardware-based encryption acceleration can offload processing from the CPU, improving performance. Selecting appropriate encryption algorithms also impacts performance; while AES-256 provides strong security, AES-128 may be faster and sufficient for many deployments. Limiting the interesting traffic defined in the ACLs to only necessary subnets reduces the processing load. Adjusting TCP MSS values on the GRE tunnel interface prevents fragmentation issues caused by the overhead of GRE and IPSec encapsulation.

Security Best Practices

Security is not limited to encryption. Regularly changing the pre-shared key reduces the risk of key compromise. Using stronger Diffie-Hellman groups provides better protection against brute-force attacks during key exchange. Monitoring logs for repeated negotiation failures can indicate potential intrusion attempts. Restricting the tunnel source and destination to specific known IP addresses prevents unauthorized devices from attempting to establish tunnels. Access control lists on the WAN interface can further restrict traffic to only the protocols necessary for GRE and IPSec operation.

Integration with Dynamic Routing Protocols

One of the advantages of GRE is the ability to run dynamic routing protocols such as OSPF or EIGRP over the tunnel. This simplifies route management between the two sites. When running dynamic routing over GRE with IPSec, remember that routing updates are not encrypted in IPSec over GRE. This is acceptable in environments where control traffic does not require confidentiality, but in high-security environments, GRE over IPSec may be preferred. Careful route filtering ensures that only intended networks are advertised through the tunnel, preventing accidental exposure of unnecessary routes.

High Availability and Redundancy

For critical applications, a single IPSec over GRE tunnel may not provide sufficient reliability. Configuring redundant tunnels between multiple routers or interfaces ensures that connectivity is maintained if a link fails. Dynamic routing protocols can automatically reroute traffic through the backup tunnel. Some deployments also use IP SLA tracking to detect tunnel failures and trigger failover scripts. Redundancy planning should include considerations for both GRE and IPSec configurations to ensure seamless failover.

Scaling IPSec over GRE Deployments

In larger networks with many branch offices, managing individual IPSec over GRE tunnels between each site can become complex. Hierarchical designs using hub-and-spoke topologies can reduce configuration complexity. The hub router terminates GRE tunnels from all branch sites and applies IPSec selectively based on traffic requirements. In very large deployments, technologies such as DMVPN may be more appropriate, but IPSec over GRE remains a useful solution for fixed, well-defined site-to-site connections.

Real-World Deployment Considerations

In real-world deployments, factors such as internet latency, bandwidth limitations, and hardware capacity influence IPSec over GRE performance. Testing the tunnel under expected traffic loads before going live is critical. Consideration must also be given to maintenance windows for rekeying and configuration changes, as these actions can temporarily interrupt connectivity. In environments with strict compliance requirements, regular audits of IPSec configurations may be required to verify that encryption standards and key management practices meet policy guidelines.

Conclusion

IPSec over GRE on Cisco IOS routers provides a secure and flexible method for connecting remote sites. By combining GRE’s ability to encapsulate multiple protocols with IPSec’s strong encryption and authentication, this solution meets the needs of many enterprise networks. Proper planning, configuration, verification, and monitoring ensure that the tunnel remains stable and secure over time. While alternative tunneling and encryption methods exist, IPSec over GRE remains a widely used and well-understood option that balances security, performance, and routing flexibility.