Setting up a GRE tunnel

1 min read
On this page 1. Install the iproute2 and iptables packages on the VPS server.2. Create a GRE tunnel using the ip tunnel command.3. Configure an IP address for the GRE interface.4. Set default routing through the GRE interface.5. Configure iptables rules to allow GRE traffic.

To set up a GRE tunnel on a VPS server, you need to perform the following steps:

  • 1. Install the iproute2 and iptables packages on the VPS server.

sudo apt-get update
sudo apt-get install iproute2 iptables
  • 2. Create a GRE tunnel using the ip tunnel command.

  • # Replace the IP addresses with your own
    sudo ip tunnel add gre-tunnel mode gre remote <SERVER_IP> local <CLIENT_IP>
    sudo ip link set gre-tunnel up
  • 3. Configure an IP address for the GRE interface.

  • # Replace the IP address with your own
    sudo ip addr add <GRE_IP>/24 dev gre-tunnel
  • 4. Set default routing through the GRE interface.

  • sudo ip route add default via <GRE_IP> dev gre-tunnel
  • 5. Configure iptables rules to allow GRE traffic.

  • sudo iptables -A INPUT -p gre -j ACCEPT
    sudo iptables -A OUTPUT -p gre -j ACCEPT

    Now you should have a configured GRE tunnel on the VPS server. You can test its functionality by sending data through the tunnel interface and verifying that it reaches the other end of the tunnel.

    Didn’t find the answer?Contact support — we’ll help you sort it out.
    Open a ticket →