Skip to main content

Linux GRE Configuration

GRE is a tunneling protocol that encapsulates various network layer protocols inside point-to-point connections. It is used to create virtual private networks (VPNs) and to transport packets over IP networks.

  • Encapsulation: GRE encapsulates packets within an outer IP packet, allowing the transport of protocols that might not be natively supported by the underlying network.
  • Simplicity: GRE is straightforward and lightweight, making it easy to implement.
  • Use Case: Commonly used for creating VPNs, connecting geographically dispersed networks, and enabling compatibility between different network protocols.

Required Linux Modules

root@dent-1:~# lsmod
Module Size Used by
ip_gre 32768 0
gre 16384 1 ip_gre

Basic GRE configuration

Topology

topology1

Configuration

  • config enp0s4 link on both devices with the required ip addresses.
  • create tun1 GRE link on both sides.
  • add route to the remote destination and set tun1 as nexthop device.
dent-1(config-links-iproute2)# link enp0s4
dent-1(config-[name='enp0s4'])# ip 1.1.1.2/24
dent-1(config-[name='enp0s4'])# admin-status up
dent-1(config-[name='enp0s4'])# exit
dent-1(config)# links-iproute2
dent-1(config-links-iproute2)# gre tun1
dent-1(config-gre[name='tun1'])# admin up
dent-1(config-gre[name='tun1'])# tunnel-info local 1.1.1.2
dent-1(config-gre[name='tun1'])# tunnel-info remote 1.1.1.4
dent-1(config-gre[name='tun1'])# tunnel-info pmtudisc on
dent-1(config-gre[name='tun1'])# exit
dent-1(config-links-iproute2)# exit
dent-1(config)# routes-iproute2
dent-1(config-routes-iproute2)# route 192.168.1.0/24
dent-1(config-[prefix='192.168.1.0/24'][table='main']# nexthop tun1
dent-1(config-nexthop[dev='tun1'])# commit

Verify

  • If we ping from PC1 to PC2 we can see that the traffic is encapsulated with GRE tunnel.

cap