GRE Tunnel: Complete Site-to-Site Configuration Guide
GRE Tunnel: Complete Site-to-Site Configuration Guide
Section titled âGRE Tunnel: Complete Site-to-Site Configuration GuideâTL;DR (Quick Start)
Section titled âTL;DR (Quick Start)âFor the impatient: hereâs the 30-second version.
# Site A (192.168.80.1)/interface gre add name=gre-siteB remote-address=192.168.90.1 local-address=192.168.80.1/ip address add address=172.16.1.1/30 interface=gre-siteB/ip route add dst-address=10.1.202.0/24 gateway=172.16.1.2
# Site B (192.168.90.1)/interface gre add name=gre-siteA remote-address=192.168.80.1 local-address=192.168.90.1/ip address add address=172.16.1.2/30 interface=gre-siteA/ip route add dst-address=10.1.101.0/24 gateway=172.16.1.1Overview
Section titled âOverviewâGRE (Generic Routing Encapsulation) is a tunneling protocol that encapsulates IP and IPv6 packets inside IP packets, creating point-to-point virtual links between routers. Unlike EoIP (Ethernet over IP), GRE operates at Layer 3 and only forwards IP/IPv6 traffic - not full Ethernet frames.
GRE is an industry standard defined in RFC 2784, making it compatible with routers from other vendors including Cisco, Juniper, and others. This interoperability makes GRE the preferred choice when connecting MikroTik routers to non-MikroTik equipment.
Key characteristics:
- Overhead: 24 bytes (4-byte GRE header + 20-byte IP header)
- Protocol: IP Protocol 47
- Encryption: None (use IPsec for security)
- Bridging: Not supported (use EoIP for Layer 2)
GRE Limitations
- NAT traversal: GRE cannot traverse standard NAT (no port numbers). Use IPsec NAT-T or ensure direct IP connectivity.
- ISP blocking: Some ISPs block IP protocol 47. Test with ping using GRE before deployment.
- No encryption: Traffic is transmitted in clear text. Always combine with IPsec for sensitive data.
Understanding GRE Fundamentals
Section titled âUnderstanding GRE FundamentalsâHow GRE Works
Section titled âHow GRE WorksâGRE creates a virtual point-to-point link by encapsulating the original IP packet inside a new IP packet with a GRE header. The outer IP header uses the tunnel endpoint addresses, while the inner packet travels unchanged.
+------------------+------------+------------------+| Outer IP Header | GRE Header | Original Packet || (Tunnel IPs) | (4 bytes) | (Your Data) |+------------------+------------+------------------+Stateless vs Keepalive
Section titled âStateless vs KeepaliveâGRE is inherently stateless - without keepalives, the tunnel interface always shows ârunningâ even if the remote endpoint is unreachable. This can cause black hole routing where traffic enters the tunnel but never reaches its destination.
RouterOS adds keepalive functionality to detect remote endpoint failures:
| Setting | Behavior |
|---|---|
keepalive=10s,10 | Check every 10s, mark down after 10 failures (100s) |
keepalive=5s,3 | Check every 5s, mark down after 3 failures (15s) |
keepalive=0 | Disabled (always shows running) |
GRE vs Other Tunnel Types
Section titled âGRE vs Other Tunnel Typesâ| Feature | GRE | IPIP | EoIP |
|---|---|---|---|
| Layer | 3 (IP) | 3 (IP) | 2 (Ethernet) |
| Overhead | 24 bytes | 20 bytes | 42 bytes |
| Payload | IP/IPv6 | IP only | Full Ethernet |
| Bridgeable | No | No | Yes |
| Standards | RFC 2784 | RFC 2003 | MikroTik proprietary |
| Cisco Compatible | Yes | Yes | No |
| Keepalive | Yes | Yes | Yes |
When to use GRE:
- Site-to-site routing between locations
- Connecting to non-MikroTik routers (Cisco, Juniper, etc.)
- BGP or OSPF peering over tunnels
- When you need standards-compliant tunneling
When to use EoIP instead:
- Extending Layer 2 networks across sites
- Bridging VLANs between locations
- Running non-IP protocols (legacy systems)
Network Architecture Example
Section titled âNetwork Architecture ExampleâThis guide configures a tunnel between two sites:
Site A Internet Site B+-------------------+ +-------------------+| LAN: 10.1.101.0/24| +-----------------+ | LAN: 10.1.202.0/24|| Router: 192.168.80.1|---| ISP/Internet |-------| Router: 192.168.90.1|| | +-----------------+ | || Tunnel: 172.16.1.1|<======= GRE Tunnel =========>| Tunnel: 172.16.1.2|+-------------------+ +-------------------+Tunnel addressing: 172.16.1.0/30 for the point-to-point link between routers.
Routing logic:
- Traffic to 10.1.202.0/24 from Site A goes via GRE tunnel to Site B
- Traffic to 10.1.101.0/24 from Site B goes via GRE tunnel to Site A
Prerequisites
Section titled âPrerequisitesâ- Both routers have public IP addresses (or private IPs with direct routing)
- IP connectivity between tunnel endpoints
- GRE protocol (IP Protocol 47) allowed through all firewalls in the path
- Basic understanding of IP routing and subnetting
Configuration Steps
Section titled âConfiguration StepsâStep 1: Create GRE Interface
Section titled âStep 1: Create GRE InterfaceâCreate the GRE tunnel interface on both routers, specifying the local and remote endpoint addresses.
Site A:
/interface gre add name=gre-siteB \ remote-address=192.168.90.1 \ local-address=192.168.80.1 \ keepalive=10s,10Site B:
/interface gre add name=gre-siteA \ remote-address=192.168.80.1 \ local-address=192.168.90.1 \ keepalive=10s,10Step 2: Assign Tunnel IP Addresses
Section titled âStep 2: Assign Tunnel IP AddressesâAdd IP addresses to the tunnel interfaces for routing:
Site A:
/ip address add address=172.16.1.1/30 interface=gre-siteBSite B:
/ip address add address=172.16.1.2/30 interface=gre-siteAStep 3: Add Static Routes
Section titled âStep 3: Add Static RoutesâConfigure routes to reach the remote LAN networks:
Site A:
/ip route add dst-address=10.1.202.0/24 gateway=172.16.1.2Site B:
/ip route add dst-address=10.1.101.0/24 gateway=172.16.1.1Step 4: Configure Firewall (if needed)
Section titled âStep 4: Configure Firewall (if needed)âAllow GRE protocol through the firewall:
/ip firewall filter add chain=input protocol=gre action=accept \ comment="Allow GRE tunnel" place-before=0Verification
Section titled âVerificationâCheck 1: Interface Status
Section titled âCheck 1: Interface StatusâVerify the GRE interface is running:
/interface gre printExpected Output:
Flags: X - disabled, R - running 0 R name="gre-siteB" mtu=1476 local-address=192.168.80.1 remote-address=192.168.90.1 keepalive=10s,10 dscp=inherit clamp-tcp-mss=yes dont-fragment=no allow-fast-path=yesThe R flag indicates the tunnel is running.
Check 2: Tunnel Connectivity
Section titled âCheck 2: Tunnel ConnectivityâTest basic tunnel connectivity:
/ping 172.16.1.2 count=3Expected Output:
SEQ HOST SIZE TTL TIME STATUS 0 172.16.1.2 56 64 25ms 1 172.16.1.2 56 64 24ms 2 172.16.1.2 56 64 26ms sent=3 received=3 packet-loss=0% min-rtt=24ms avg-rtt=25ms max-rtt=26msCheck 3: Remote LAN Connectivity
Section titled âCheck 3: Remote LAN ConnectivityâVerify traffic flows to the remote LAN:
/ping 10.1.202.1 src-address=10.1.101.1 count=3Check 4: Route Verification
Section titled âCheck 4: Route VerificationâConfirm routes are active:
/ip route print where gateway~"172.16.1"Expected Output:
Flags: D - dynamic, A - active, c - connect, S - static # DST-ADDRESS GATEWAY DISTANCE 0 A S 10.1.202.0/24 172.16.1.2 1Advanced Configuration
Section titled âAdvanced ConfigurationâGRE with IPsec Encryption
Section titled âGRE with IPsec EncryptionâGRE provides no encryption. For secure tunnels, combine with IPsec using the built-in ipsec-secret parameter:
/interface gre add name=gre-secure \ remote-address=192.168.90.1 \ local-address=192.168.80.1 \ ipsec-secret=YourStrongSecretKey \ allow-fast-path=no
/ip address add address=172.16.1.1/30 interface=gre-secureImportant: Set allow-fast-path=no when using IPsec - fast path bypasses IPsec processing.
For manual IPsec configuration (more control over encryption settings):
# Create GRE tunnel/interface gre add name=gre-manual remote-address=192.168.90.1 \ local-address=192.168.80.1 allow-fast-path=no
# Configure IPsec peer/ip ipsec peer add address=192.168.90.1 exchange-mode=ike2
# Configure IPsec policy for GRE traffic/ip ipsec policy add src-address=192.168.80.1/32 \ dst-address=192.168.90.1/32 protocol=gre action=encryptGRE with OSPF
Section titled âGRE with OSPFâUse dynamic routing over the GRE tunnel:
# Create tunnel/interface gre add name=gre-ospf remote-address=192.168.90.1 \ local-address=192.168.80.1/ip address add address=10.0.0.1/30 interface=gre-ospf
# Configure OSPF over tunnel/routing ospf instance add name=default router-id=192.168.80.1/routing ospf area add name=backbone area-id=0.0.0.0 instance=default/routing ospf interface-template add networks=10.0.0.0/30 area=backboneGRE with BGP
Section titled âGRE with BGPâFor BGP peering over GRE:
# Create tunnel/interface gre add name=gre-bgp remote-address=203.0.113.1 \ local-address=198.51.100.1/ip address add address=10.255.255.1/30 interface=gre-bgp
# Configure BGP session over tunnel/routing bgp connection add name=bgp-peer \ remote.address=10.255.255.2 \ local.role=ebgp as=65001GRE6 (GRE over IPv6)
Section titled âGRE6 (GRE over IPv6)âFor IPv6 transport:
/interface gre6 add name=gre6-tunnel \ local-address=2001:db8::1 \ remote-address=2001:db8::2
# Assign IPv4 over IPv6 tunnel/ip address add address=10.255.0.1/30 interface=gre6-tunnel
# Or IPv6-in-IPv6/ipv6 address add address=fd00::1/64 interface=gre6-tunnelCustom Keepalive Settings
Section titled âCustom Keepalive SettingsâFor faster failover detection:
/interface gre set gre-siteB keepalive=5s,3This checks every 5 seconds and marks the tunnel down after 3 failures (15 seconds total).
MTU Optimization
Section titled âMTU OptimizationâGRE adds 24 bytes overhead. For a 1500-byte path MTU:
/interface gre set gre-siteB mtu=1476Enable TCP MSS clamping to prevent fragmentation issues:
/interface gre set gre-siteB clamp-tcp-mss=yesTroubleshooting
Section titled âTroubleshootingâProblem: Tunnel Shows Running But No Traffic
Section titled âProblem: Tunnel Shows Running But No TrafficâSymptoms: GRE interface has R flag but pings through tunnel fail.
Solutions:
- Check keepalive: Without keepalive, tunnel always shows running
/interface gre set gre-tunnel keepalive=10s,10
- Check firewall: Ensure GRE (protocol 47) is allowed
/ip firewall filter print where protocol=gre
- Check routing: Verify routes exist on both sides
/ip route print where gateway~"gre"
Problem: Tunnel Never Comes Up
Section titled âProblem: Tunnel Never Comes UpâSymptoms: Interface shows X (disabled) or no R flag.
Solutions:
- Verify endpoint connectivity:
/ping 192.168.90.1
- Check local-address exists:
/ip address print where address~"192.168.80.1"
- Verify GRE not blocked by ISP: Some ISPs block protocol 47
- Check NAT: GRE cannot traverse typical NAT without IPsec-NAT-T
Problem: Asymmetric Routing / One-Way Traffic
Section titled âProblem: Asymmetric Routing / One-Way TrafficâSymptoms: Ping works one direction only.
Solutions:
- Check routes on both routers: Each side needs return routes
- Verify tunnel addresses: Ensure /30 subnet is correctly configured
- Check for NAT issues: Verify source addresses arenât being NATed
Problem: MTU/Fragmentation Issues
Section titled âProblem: MTU/Fragmentation IssuesâSymptoms: Small packets work, large transfers fail or stall.
Solutions:
- Lower MTU:
/interface gre set gre-tunnel mtu=1400
- Enable MSS clamping:
/interface gre set gre-tunnel clamp-tcp-mss=yes
- Test path MTU:
/ping 172.16.1.2 size=1400 do-not-fragment
Problem: IPsec Not Working with GRE
Section titled âProblem: IPsec Not Working with GREâSymptoms: GRE tunnel works without IPsec but fails with ipsec-secret.
Solutions:
- Disable fast path:
/interface gre set gre-tunnel allow-fast-path=no
- Check IPsec policies:
/ip ipsec policy print/ip ipsec installed-sa print
- Allow IKE/ESP through firewall:
/ip firewall filter add chain=input protocol=udp dst-port=500,4500 action=accept/ip firewall filter add chain=input protocol=ipsec-esp action=accept
Problem: Keepalive Issues in ROS7
Section titled âProblem: Keepalive Issues in ROS7âSymptoms: Tunnel state column empty (not âRâ) after upgrade.
Solutions:
- Temporarily disable keepalive:
/interface gre set gre-tunnel keepalive=0
- Update RouterOS: Keepalive issues were fixed in later releases
- Check both endpoints: Both must run compatible versions
Useful Debug Commands
Section titled âUseful Debug Commandsâ# View GRE interface details/interface gre print detail
# Monitor interface in real-time/interface gre monitor gre-tunnel
# Check interface counters/interface print stats where name~"gre"
# View routing table entries via tunnel/ip route print where gateway~"gre"
# Test with specific source/ping 10.1.202.1 src-address=10.1.101.1
# Packet capture on tunnel/tool sniffer quick interface=gre-tunnelSecurity Considerations
Section titled âSecurity ConsiderationsâNo Built-in Encryption
Section titled âNo Built-in EncryptionâGRE transmits data in clear text. For sensitive traffic:
- Use
ipsec-secretfor automatic IPsec - Configure manual IPsec policies for more control
- Consider WireGuard or IPsec-only tunnels for security-critical applications
Firewall Recommendations
Section titled âFirewall Recommendationsâ# Accept GRE only from known peers/ip firewall filter add chain=input protocol=gre \ src-address=192.168.90.1 action=accept comment="GRE from Site B"
# Drop GRE from unknown sources/ip firewall filter add chain=input protocol=gre action=drop
# Restrict what can traverse the tunnel/ip firewall filter add chain=forward in-interface=gre-siteB \ dst-port=22,80,443 protocol=tcp action=accept/ip firewall filter add chain=forward in-interface=gre-siteB action=dropAccess Control
Section titled âAccess ControlâLimit which networks can use the tunnel:
/ip firewall filter add chain=forward src-address=10.1.101.0/24 \ out-interface=gre-siteB action=accept/ip firewall filter add chain=forward out-interface=gre-siteB action=dropGRE Properties Reference
Section titled âGRE Properties Referenceâ| Property | Type | Default | Description |
|---|---|---|---|
name | string | - | Interface name |
remote-address | IP | - | Remote tunnel endpoint (required) |
local-address | IP | 0.0.0.0 | Local source address (auto if unset) |
disabled | yes/no | no | Enable/disable interface |
mtu | integer | 1476 | Layer 3 MTU |
keepalive | time,retries | 10s,10 | Format: interval,retry-count |
dscp | inherit/0-63 | inherit | DSCP value for outer packets |
clamp-tcp-mss | yes/no | yes | Adjust TCP MSS automatically |
dont-fragment | inherit/no | no | DF bit handling |
allow-fast-path | yes/no | yes | Hardware acceleration (disable for IPsec) |
ipsec-secret | string | - | Pre-shared key (auto-creates IPsec) |
comment | string | - | Description |
Related Topics
Section titled âRelated TopicsâPrerequisites
Section titled âPrerequisitesâ- IP Address Configuration - Interface addressing
- Static Routes - Route traffic over tunnels
- Firewall Basics - Allow GRE protocol
Alternative Tunnel Technologies
Section titled âAlternative Tunnel Technologiesâ- IPsec IKEv2 - Encrypted site-to-site VPN
- WireGuard - Modern encrypted tunnels
- EoIP Tunnel - Layer 2 tunneling for bridging
Related Topics
Section titled âRelated Topicsâ- OSPF Configuration - Dynamic routing over GRE
- BGP Peering - BGP sessions over tunnels
- NAT Masquerade - NAT for tunnel traffic
References
Section titled âReferencesâ- MikroTik GRE Documentation
- RFC 2784 - Generic Routing Encapsulation (GRE)
- RFC 1701 - Generic Routing Encapsulation (original)
- MikroTik Forum: VPN Discussions