An IP network can carry another network inside encapsulated packets. A GRE tunnel gives two Linux hosts a point-to-point link over their existing IPv4 connection, with separate addresses for traffic inside the tunnel.

The outer addresses must already be assigned and reachable between the hosts. Each peer uses the other's outer address as its remote endpoint; the inner addresses share an unused subnet and become reachable through the GRE interfaces.

GRE supplies neither encryption nor authentication, so it suits trusted transport or traffic protected separately. ip tunnel changes the running kernel configuration only; the tunnel and its inner address disappear after a reboot.

Steps to add a GRE tunnel with ip tunnel:

  1. Identify each host's existing outer IPv4 address.
    $ ip -brief -4 address show

    Both hosts need iproute2, ping, kernel GRE support, and administrative access through sudo. Host A uses outer address 192.0.2.10 and Host B uses 192.0.2.20. These are documentation addresses to replace with your assigned addresses. The local address must belong to an existing interface on that host.

  2. Check that each host can reach the other's outer IPv4 address.
    $ ping -c 3 192.0.2.20

    On Host B, the destination is 192.0.2.10. Replies confirm the underlying IP path. Firewalls and intervening devices must also permit GRE, IP protocol 47, between the two outer endpoints. GRE does not use a TCP or UDP port. The traffic checks also require ICMP echo replies.

  3. Create gre1 on each host with reversed outer endpoints.

    GRE exposes traffic to the underlying network without encryption or peer authentication. An existing interface named gre1 must be left intact; choose another unused name if necessary. If the new tunnel causes unwanted routing, sudo ip tunnel del gre1 removes that tunnel and its assigned addresses on the affected host.

    $ sudo ip tunnel add gre1 mode gre local 192.0.2.10 remote 192.0.2.20

    On Host B, the endpoint arguments are local 192.0.2.20 remote 192.0.2.10; the name and mode gre stay the same.

  4. Assign one inner address from an unused subnet to each GRE interface.

    The inner subnet must not overlap an existing local or routed network. Assigning it adds a connected route that can divert traffic intended for that network.

    $ sudo ip address add 10.0.0.1/30 dev gre1

    On Host B, the address is 10.0.0.2/30. Both inner addresses belong to 10.0.0.0/30. They are separate from the outer addresses used to carry GRE packets.
    Tool: IP Overlap Checker

  5. Bring the GRE interface up on both hosts.
    $ sudo ip link set dev gre1 up
  6. Inspect the GRE interface's endpoints and inner address on each host.
    $ ip address show dev gre1
    12: gre1@NONE: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1476 qdisc noqueue state UNKNOWN group default qlen 1000
        link/gre 192.0.2.10 peer 192.0.2.20
        inet 10.0.0.1/30 scope global gre1
           valid_lft forever preferred_lft forever
        inet6 fe80::5efe:c000:20a/64 scope link 
           valid_lft forever preferred_lft forever

    Host A should show the UP flag, outer pair 192.0.2.10 and 192.0.2.20, and inner address 10.0.0.1/30. Host B should show the reversed outer pair and 10.0.0.2/30. Tunnel interfaces commonly show state UNKNOWN; the UP flag alone does not prove that the peer responds.

  7. Verify that Host A receives replies through gre1 from Host B's inner address.
    $ ping -c 3 -I gre1 10.0.0.2
    PING 10.0.0.2 (10.0.0.2) from 10.0.0.1 gre1: 56(84) bytes of data.
    64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=0.113 ms
    64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.161 ms
    64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=0.224 ms
    
    --- 10.0.0.2 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2066ms
    rtt min/avg/max/mdev = 0.113/0.166/0.224/0.045 ms

    3 received and 0% packet loss show a working round trip through the tunnel. -I gre1 binds the test to the new interface. A timeout requires checking both peers' addresses, interface state, and GRE and ICMP filtering. Additional networks behind the peers need separate routing and forwarding configuration.
    Related: How to add a static route with ip route

Share this guide