Introduction
A plain IPsec site-to-site VPN on Cisco IOS works well for unicast traffic, but it cannot carry multicast, which means routing protocols such as OSPF or EIGRP cannot form adjacencies across it. GRE (Generic Routing Encapsulation) solves that problem by creating a virtual point-to-point link that carries any traffic, including multicast, while IPsec adds the encryption and integrity that GRE lacks on its own. In this lab we build a GRE tunnel between two branch routers, protect it with an IPsec profile (IKEv1, AES-256, SHA-256, DH group 14), and run OSPF over the tunnel so that each site learns the other's LAN dynamically.
Lab Topology
Two routers, R1 (HQ) and R2 (Branch), are connected to the Internet through their GigabitEthernet0/0 interfaces. Each router has a LAN on GigabitEthernet0/1. The GRE tunnel uses its own small /30 subnet.
- R1 WAN (Gi0/0): 203.0.113.1/30, ISP next hop 203.0.113.2
- R1 LAN (Gi0/1): 192.168.10.1/24
- R2 WAN (Gi0/0): 198.51.100.1/30, ISP next hop 198.51.100.2
- R2 LAN (Gi0/1): 192.168.20.1/24
- Tunnel0: R1 172.16.0.1/30, R2 172.16.0.2/30
The traffic path is: LAN host → Tunnel0 (GRE encapsulation) → IPsec ESP in transport mode → Internet → remote router → remote LAN.
Configuration Steps
- Configure interfaces and the default route to the ISP. The public addresses must be reachable from each other before anything else will work.
! R1 interface GigabitEthernet0/0 description WAN-to-ISP ip address 203.0.113.1 255.255.255.252 no shutdown interface GigabitEthernet0/1 description HQ-LAN ip address 192.168.10.1 255.255.255.0 no shutdown ip route 0.0.0.0 0.0.0.0 203.0.113.2 ! R2 interface GigabitEthernet0/0 description WAN-to-ISP ip address 198.51.100.1 255.255.255.252 no shutdown interface GigabitEthernet0/1 description BRANCH-LAN ip address 192.168.20.1 255.255.255.0 no shutdown ip route 0.0.0.0 0.0.0.0 198.51.100.2
Test withping 198.51.100.1 source GigabitEthernet0/0from R1 before continuing. - Create the IKE Phase 1 (ISAKMP) policy and pre-shared key. Both sides must match on encryption, hash, authentication and DH group.
! R1 crypto isakmp policy 10 encryption aes 256 hash sha256 authentication pre-share group 14 lifetime 86400 crypto isakmp key Lab-GRE-Key-2026 address 198.51.100.1 ! R2 crypto isakmp policy 10 encryption aes 256 hash sha256 authentication pre-share group 14 lifetime 86400 crypto isakmp key Lab-GRE-Key-2026 address 203.0.113.1
- Create the Phase 2 transform set and the IPsec profile. Because GRE already adds a new IP header with the tunnel endpoints, transport mode is enough and saves 20 bytes per packet compared to tunnel mode. Apply the same configuration on both routers.
crypto ipsec transform-set TS-GRE esp-aes 256 esp-sha256-hmac mode transport ! crypto ipsec profile GRE-PROTECT set transform-set TS-GRE
- Build the GRE tunnel and attach the IPsec profile. The
tunnel protectioncommand replaces the old crypto map and ACL method: everything that leaves through Tunnel0 is encrypted automatically. Lowering the IP MTU and adjusting TCP MSS avoids fragmentation caused by the GRE and ESP overhead.! R1 interface Tunnel0 description GRE-over-IPsec-to-R2 ip address 172.16.0.1 255.255.255.252 ip mtu 1400 ip tcp adjust-mss 1360 tunnel source GigabitEthernet0/0 tunnel destination 198.51.100.1 tunnel protection ipsec profile GRE-PROTECT ! R2 interface Tunnel0 description GRE-over-IPsec-to-R1 ip address 172.16.0.2 255.255.255.252 ip mtu 1400 ip tcp adjust-mss 1360 tunnel source GigabitEthernet0/0 tunnel destination 203.0.113.1 tunnel protection ipsec profile GRE-PROTECT
The default tunnel mode isgre ip, so it does not need to be typed. - Run OSPF over the tunnel. Advertise only the tunnel subnet and the LAN. Do not advertise the WAN (public) subnets into OSPF, otherwise the router may try to reach the tunnel destination through the tunnel itself (recursive routing) and the tunnel will flap.
! R1 router ospf 1 router-id 1.1.1.1 passive-interface GigabitEthernet0/1 network 172.16.0.0 0.0.0.3 area 0 network 192.168.10.0 0.0.0.255 area 0 ! R2 router ospf 1 router-id 2.2.2.2 passive-interface GigabitEthernet0/1 network 172.16.0.0 0.0.0.3 area 0 network 192.168.20.0 0.0.0.255 area 0
A GRE tunnel interface uses the OSPF point-to-point network type by default, so no DR/BDR election takes place. - Allow the VPN through any WAN ACL. If an inbound ACL is already applied on Gi0/0 (R1 shown), add these entries to it before its final deny so IKE and ESP from the peer are allowed:
ip access-list extended WAN-IN permit udp host 198.51.100.1 host 203.0.113.1 eq isakmp permit esp host 198.51.100.1 host 203.0.113.1 permit udp host 198.51.100.1 host 203.0.113.1 eq non500-isakmp
(The UDP 4500 line is only needed if NAT traversal is in use.)
Verification
1. Phase 1 status – the SA should be in QM_IDLE state, which means Phase 1 is up and ready for quick mode:
R1# show crypto isakmp sa IPv4 Crypto ISAKMP SA dst src state conn-id status 198.51.100.1 203.0.113.1 QM_IDLE 1001 ACTIVE
2. Phase 2 status – look for an active inbound and outbound ESP SA in transport mode, and encrypt/decrypt counters that increase while traffic flows:
R1# show crypto ipsec sa
interface: Tunnel0
Crypto map tag: Tunnel0-head-0, local addr 203.0.113.1
local ident (addr/mask/prot/port): (203.0.113.1/255.255.255.255/47/0)
remote ident (addr/mask/prot/port): (198.51.100.1/255.255.255.255/47/0)
#pkts encaps: 152, #pkts encrypt: 152, #pkts digest: 152
#pkts decaps: 149, #pkts decrypt: 149, #pkts verify: 149
...
in use settings ={Transport, }
Protocol 47 in the proxy identities confirms that only GRE traffic between the two public addresses is being protected. show crypto session gives a short summary and should show Session status: UP-ACTIVE.
3. Tunnel interface – Tunnel0 must be up/up:
R1# show ip interface brief | include Tunnel Tunnel0 172.16.0.1 YES manual up up
4. OSPF adjacency and routes – the neighbor should be FULL/ - (the dash means no DR on a point-to-point link), and the remote LAN should be learned through Tunnel0:
R1# show ip ospf neighbor Neighbor ID Pri State Dead Time Address Interface 2.2.2.2 0 FULL/ - 00:00:35 172.16.0.2 Tunnel0 R1# show ip route ospf O 192.168.20.0/24 [110/1001] via 172.16.0.2, 00:04:12, Tunnel0
5. End-to-end test – ping between the LAN interfaces and recheck the encaps counters:
R1# ping 192.168.20.1 source 192.168.10.1 !!!!! Success rate is 100 percent (5/5)
Troubleshooting Tips
- No ISAKMP SA at all: confirm the public IPs can ping each other and that UDP 500 and ESP are not blocked by an ISP or WAN ACL.
- Phase 1 stuck in MM_NO_STATE or MM_KEY_EXCH: usually a policy mismatch or wrong pre-shared key. Compare
show crypto isakmp policyon both sides and usedebug crypto isakmpcarefully. - Phase 1 up but no Phase 2: check that the transform set (and mode transport) matches on both routers and that both tunnels point at the correct source and destination.
- %TUN-5-RECURDOWN "temporarily disabled due to recursive routing" and a flapping tunnel: the tunnel destination is being learned through the tunnel. Remove the WAN subnet from OSPF and keep a static route or default route to the peer via the ISP.
- Ping works but large transfers stall: this is an MTU problem. Make sure
ip mtu 1400andip tcp adjust-mss 1360are set on both tunnel interfaces. - OSPF stuck in INIT or EXSTART: check for mismatched hello/dead timers, area numbers, or IP MTU between the two tunnel interfaces.
With GRE over IPsec in place, adding a new LAN at either site is just one more network statement in OSPF, and the encrypted tunnel carries it without touching the crypto configuration.
0 Comments