{"id":4724,"date":"2025-05-30T20:50:14","date_gmt":"2025-05-30T17:50:14","guid":{"rendered":"https:\/\/avenacloud.com\/blog\/?p=4724"},"modified":"2025-05-30T20:50:17","modified_gmt":"2025-05-30T17:50:17","slug":"configure-gre-tunnel-on-vps-easy-step-by-step-guide","status":"publish","type":"post","link":"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/","title":{"rendered":"Configure GRE Tunnel on VPS: Easy Step-by-Step Guide"},"content":{"rendered":"<p>In today&#8217;s interconnected world, network security and efficient data routing are more essential than ever. Whether you\u2019re a system administrator, developer, or an IT enthusiast, understanding how to set up a GRE tunnel on your VPS can drastically improve your network&#8217;s flexibility and security. This <strong>Step-by-Step Guide: Configure GRE Tunnel on VPS<\/strong> is designed to help you master the process with ease, clarity, and confidence.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Quick Summary<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#What_Is_a_GRE_Tunnel_and_Why_Configure_It_on_Your_VPS\" >What Is a GRE Tunnel and Why Configure It on Your VPS?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Benefits_of_GRE_Tunnels\" >Benefits of GRE Tunnels<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Step_1_Prerequisites_for_Configuring_GRE_Tunnel_on_VPS\" >Step 1: Prerequisites for Configuring GRE Tunnel on VPS<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Checking_Your_VPS_Environment\" >Checking Your VPS Environment<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Step_2_Understand_GRE_Tunnel_Components_and_Terminology\" >Step 2: Understand GRE Tunnel Components and Terminology<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#How_GRE_Works_on_VPS\" >How GRE Works on VPS<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Step_3_Preparing_Your_VPS_for_GRE_Tunnel_Setup\" >Step 3: Preparing Your VPS for GRE Tunnel Setup<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#1_Load_GRE_Kernel_Module\" >1. Load GRE Kernel Module<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#2_Update_and_Install_Necessary_Packages\" >2. Update and Install Necessary Packages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#3_Verify_IP_Forwarding_is_Enabled\" >3. Verify IP Forwarding is Enabled<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Step_4_Detailed_Step-by-Step_GRE_Tunnel_Configuration\" >Step 4: Detailed Step-by-Step GRE Tunnel Configuration<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#41_Creating_GRE_Tunnel_Interface\" >4.1 Creating GRE Tunnel Interface<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#42_Assign_Tunnel_IP_Addresses\" >4.2 Assign Tunnel IP Addresses<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#43_Activate_the_Tunnel_Interface\" >4.3 Activate the Tunnel Interface<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#44_Confirm_Tunnel_Status\" >4.4 Confirm Tunnel Status<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Step_5_Routing_Traffic_Through_the_GRE_Tunnel\" >Step 5: Routing Traffic Through the GRE Tunnel<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Example_Scenario\" >Example Scenario:<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Step_6_Firewall_Configuration_to_Allow_GRE_Traffic\" >Step 6: Firewall Configuration to Allow GRE Traffic<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Opening_GRE_on_iptables\" >Opening GRE on iptables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Save_iptables_Rules\" >Save iptables Rules<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Opening_GRE_on_firewalld_CentOSRedHat\" >Opening GRE on firewalld (CentOS\/RedHat)<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Step_7_Automate_GRE_Tunnel_Setup_at_Boot\" >Step 7: Automate GRE Tunnel Setup at Boot<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Using_systemd_Service\" >Using systemd Service<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Network_Configuration_Files\" >Network Configuration Files<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Troubleshooting_GRE_Tunnel_on_VPS\" >Troubleshooting GRE Tunnel on VPS<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#1_Tunnel_Does_Not_Come_Up\" >1. Tunnel Does Not Come Up<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#2_No_Ping_or_Traffic_Through_Tunnel\" >2. No Ping or Traffic Through Tunnel<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#3_Performance_Issues\" >3. Performance Issues<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Advanced_GRE_Tunnel_Configuration_Options\" >Advanced GRE Tunnel Configuration Options<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Multipoint_GRE_mGRE\" >Multipoint GRE (mGRE)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Tunneling_Non-IP_Protocols\" >Tunneling Non-IP Protocols<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Combining_GRE_with_IPsec_for_Encryption\" >Combining GRE with IPsec for Encryption<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Security_Considerations_When_Configuring_GRE_Tunnel_on_VPS\" >Security Considerations When Configuring GRE Tunnel on VPS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-34\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Use_Cases_for_GRE_Tunnel_on_VPS\" >Use Cases for GRE Tunnel on VPS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-35\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Performance_Tips_for_GRE_Tunnel_on_VPS\" >Performance Tips for GRE Tunnel on VPS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-36\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Tools_to_Validate_and_Monitor_GRE_Tunnel\" >Tools to Validate and Monitor GRE Tunnel<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-37\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Best_Practices_Summary_for_Configuring_GRE_Tunnel_on_VPS\" >Best Practices Summary for Configuring GRE Tunnel on VPS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-38\" href=\"https:\/\/avenacloud.com\/blog\/configure-gre-tunnel-on-vps-easy-step-by-step-guide\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"What_Is_a_GRE_Tunnel_and_Why_Configure_It_on_Your_VPS\"><\/span>What Is a GRE Tunnel and Why Configure It on Your VPS?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4728 aligncenter\" title=\"Step-by-Step Guide: Configure GRE Tunnel on VPS. What Is a GRE Tunnel and Why Configure It on Your VPS?\" src=\"https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/55fa75b1cd00b483036f7d735d48551b.jpg\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/55fa75b1cd00b483036f7d735d48551b.jpg 1024w, https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/55fa75b1cd00b483036f7d735d48551b-300x225.jpg 300w, https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/55fa75b1cd00b483036f7d735d48551b-768x576.jpg 768w\" alt=\"Step-by-Step Guide: Configure GRE Tunnel on VPS. What Is a GRE Tunnel and Why Configure It on Your VPS?\" width=\"1024\" height=\"768\" \/><\/p>\n<p>Before diving into the technicalities, let&#8217;s understand the basics. GRE (Generic Routing Encapsulation) is a tunneling protocol developed by Cisco, enabling you to encapsulate a wide variety of network layer protocols inside virtual point-to-point links. Essentially, it creates a private tunnel over a public network like the Internet.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Benefits_of_GRE_Tunnels\"><\/span>Benefits of GRE Tunnels<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li><strong>Improved Security:<\/strong> Encrypt and route sensitive data securely through the tunnel.<\/li>\n<li><strong>Network Extension:<\/strong> Connect geographically separated networks as if they were local.<\/li>\n<li><strong>Protocol Encapsulation:<\/strong> Encapsulate non-IP protocols for seamless transport.<\/li>\n<li><strong>Traffic Engineering:<\/strong> Route traffic flexibly across different physical networks.<\/li>\n<\/ul>\n<p>When you configure GRE tunnel on VPS, you unlock these advantages without the need for expensive dedicated hardware.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_1_Prerequisites_for_Configuring_GRE_Tunnel_on_VPS\"><\/span>Step 1: Prerequisites for Configuring GRE Tunnel on VPS<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before starting this <strong>Step-by-Step Guide: Configure GRE Tunnel on VPS<\/strong>, ensure that your environment meets a few key requirements.<\/p>\n<ul>\n<li><strong>VPS with Root Access:<\/strong> You need full administrative rights to execute commands and modify system files.<\/li>\n<li><strong>Linux-based OS:<\/strong> This guide focuses on configuring GRE tunnels on Linux servers (Ubuntu, Debian, CentOS, etc.).<\/li>\n<li><strong>Public IP Addresses:<\/strong> At least two VPS instances, each with public IPs you&#8217;ll use as tunnel endpoints.<\/li>\n<li><strong>Basic Linux Networking Knowledge:<\/strong> Familiarity with commands (ip, ifconfig) and editing configuration files.<\/li>\n<li><strong>Firewall Permissions:<\/strong> Ensure GRE protocol (IP Protocol 47) is allowed through your firewall.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Checking_Your_VPS_Environment\"><\/span>Checking Your VPS Environment<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Run these checks to verify readiness:<\/p>\n<ol>\n<li>Verify the Linux kernel supports GRE:<br \/>\n<code>modprobe ip_gre<\/code><\/li>\n<li>Confirm your VPS has public IPs assigned.<br \/>\n<code>ip addr show<\/code><\/li>\n<li>Check firewall rules allow GRE protocol:<br \/>\n<code>iptables -L<\/code> or consult your control panel.<\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Step_2_Understand_GRE_Tunnel_Components_and_Terminology\"><\/span>Step 2: Understand GRE Tunnel Components and Terminology<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Knowledge of fundamental components helps streamline configuration.<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n<thead>\n<tr>\n<th>Component<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>GRE Tunnel Interface<\/td>\n<td>A virtual interface created on VPS for sending and receiving GRE encapsulated packets.<\/td>\n<\/tr>\n<tr>\n<td>Local Endpoint<\/td>\n<td>The public IP address of the VPS where the tunnel originates.<\/td>\n<\/tr>\n<tr>\n<td>Remote Endpoint<\/td>\n<td>The public IP address of the VPS where the tunnel terminates.<\/td>\n<\/tr>\n<tr>\n<td>Tunneled Network<\/td>\n<td>The private subnet or IP addresses that are routed through the tunnel.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><span class=\"ez-toc-section\" id=\"How_GRE_Works_on_VPS\"><\/span>How GRE Works on VPS<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The VPS sends packets encapsulated in GRE headers to the remote endpoint. These packets traverse the public Internet but appear as secured, point-to-point links from the VPS\u2019s perspective.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_3_Preparing_Your_VPS_for_GRE_Tunnel_Setup\"><\/span>Step 3: Preparing Your VPS for GRE Tunnel Setup<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Follow these instructions carefully to prepare your VPS for a successful GRE tunnel configuration.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Load_GRE_Kernel_Module\"><\/span>1. Load GRE Kernel Module<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4727 aligncenter\" title=\"Step-by-Step Guide: Configure GRE Tunnel on VPS. 1. Load GRE Kernel Module\" src=\"https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/4367b0c9dacbae9aba06e722b2676c39.jpg\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/4367b0c9dacbae9aba06e722b2676c39.jpg 1024w, https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/4367b0c9dacbae9aba06e722b2676c39-300x225.jpg 300w, https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/4367b0c9dacbae9aba06e722b2676c39-768x576.jpg 768w\" alt=\"Step-by-Step Guide: Configure GRE Tunnel on VPS. 1. Load GRE Kernel Module\" width=\"1024\" height=\"768\" \/><\/p>\n<p>Most Linux distributions support GRE out of the box, but confirm by running:<\/p>\n<pre>sudo modprobe ip_gre<\/pre>\n<p>To ensure this loads automatically at boot, add <code>ip_gre<\/code> to your modules file:<\/p>\n<pre>echo \"ip_gre\" | sudo tee -a \/etc\/modules<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"2_Update_and_Install_Necessary_Packages\"><\/span>2. Update and Install Necessary Packages<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Ensure your VPS is up-to-date and has tools like <code>iproute2<\/code> installed:<\/p>\n<pre>sudo apt update &amp;&amp; sudo apt install iproute2 -y  # For Debian\/Ubuntu<\/pre>\n<p><em>For CentOS\/RedHat users:<\/em><\/p>\n<pre>sudo yum update &amp;&amp; sudo yum install iproute -y<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"3_Verify_IP_Forwarding_is_Enabled\"><\/span>3. Verify IP Forwarding is Enabled<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>GRE tunnels forward packets; your VPS must have IP forwarding enabled:<\/p>\n<pre>sudo sysctl -w net.ipv4.ip_forward=1<\/pre>\n<p>To make it persistent across reboots, add or modify this line in <code>\/etc\/sysctl.conf<\/code>:<\/p>\n<pre>net.ipv4.ip_forward=1<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step_4_Detailed_Step-by-Step_GRE_Tunnel_Configuration\"><\/span>Step 4: Detailed Step-by-Step GRE Tunnel Configuration<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now, the core of our <strong>Step-by-Step Guide: Configure GRE Tunnel on VPS<\/strong>: configuring the tunnel itself. Let\u2019s assume you have two VPSs (VPS A and VPS B), each with public IP addresses.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"41_Creating_GRE_Tunnel_Interface\"><\/span>4.1 Creating GRE Tunnel Interface<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>On VPS A, create a tunnel interface named <code>gre1<\/code>:<\/p>\n<pre>sudo ip tunnel add gre1 mode gre local <strong>[VPS A Public IP]<\/strong> remote <strong>[VPS B Public IP]<\/strong> ttl 255<\/pre>\n<p>For VPS B, use the mirror configuration:<\/p>\n<pre>sudo ip tunnel add gre1 mode gre local <strong>[VPS B Public IP]<\/strong> remote <strong>[VPS A Public IP]<\/strong> ttl 255<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"42_Assign_Tunnel_IP_Addresses\"><\/span>4.2 Assign Tunnel IP Addresses<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4729 aligncenter\" title=\"Step-by-Step Guide: Configure GRE Tunnel on VPS. 4.2 Assign Tunnel IP Addresses\" src=\"https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/f74dee5a135924f65334dc9558ccd113.jpg\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" srcset=\"https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/f74dee5a135924f65334dc9558ccd113.jpg 1024w, https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/f74dee5a135924f65334dc9558ccd113-300x225.jpg 300w, https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/f74dee5a135924f65334dc9558ccd113-768x576.jpg 768w\" alt=\"Step-by-Step Guide: Configure GRE Tunnel on VPS. 4.2 Assign Tunnel IP Addresses\" width=\"1024\" height=\"768\" \/><\/p>\n<p>Assign private IPs on the tunnel interfaces. Use an unused subnet, e.g., <code>10.10.10.0\/24<\/code>:<\/p>\n<pre>sudo ip addr add 10.10.10.1\/24 dev gre1  # VPS A<\/pre>\n<pre>sudo ip addr add 10.10.10.2\/24 dev gre1  # VPS B<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"43_Activate_the_Tunnel_Interface\"><\/span>4.3 Activate the Tunnel Interface<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Bring the tunnel interface up on both VPSs:<\/p>\n<pre>sudo ip link set gre1 up<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"44_Confirm_Tunnel_Status\"><\/span>4.4 Confirm Tunnel Status<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Verify the interface and routes:<\/p>\n<pre>ip addr show gre1<\/pre>\n<pre>ip route show table main<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step_5_Routing_Traffic_Through_the_GRE_Tunnel\"><\/span>Step 5: Routing Traffic Through the GRE Tunnel<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Once the tunnel is active, configure routing so traffic between private subnets flows through it.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Example_Scenario\"><\/span>Example Scenario:<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>VPS A serves network 192.168.1.0\/24<\/li>\n<li>VPS B serves network 192.168.2.0\/24<\/li>\n<\/ul>\n<p>To route these subnets over the tunnel, add routes on both VPSs:<\/p>\n<pre>sudo ip route add 192.168.2.0\/24 via 10.10.10.2 dev gre1  # On VPS A<\/pre>\n<pre>sudo ip route add 192.168.1.0\/24 via 10.10.10.1 dev gre1  # On VPS B<\/pre>\n<p>With this in place, systems on both private networks communicate as if they were in the same LAN.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_6_Firewall_Configuration_to_Allow_GRE_Traffic\"><\/span>Step 6: Firewall Configuration to Allow GRE Traffic<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Security is critical. The GRE protocol (number 47) must be allowed in firewalls on both VPSs and any intermediate routers.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Opening_GRE_on_iptables\"><\/span>Opening GRE on iptables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre>sudo iptables -A INPUT -p 47 -j ACCEPT<\/pre>\n<pre>sudo iptables -A OUTPUT -p 47 -j ACCEPT<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Save_iptables_Rules\"><\/span>Save iptables Rules<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To ensure these rules persist on reboot:<\/p>\n<pre>sudo sh -c \"iptables-save &gt; \/etc\/iptables\/rules.v4\"<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Opening_GRE_on_firewalld_CentOSRedHat\"><\/span>Opening GRE on firewalld (CentOS\/RedHat)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre>sudo firewall-cmd --permanent --add-protocol=gre<\/pre>\n<pre>sudo firewall-cmd --reload<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step_7_Automate_GRE_Tunnel_Setup_at_Boot\"><\/span>Step 7: Automate GRE Tunnel Setup at Boot<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Manually configuring the tunnel after every reboot isn\u2019t practical. Automate with system scripts or network configuration files.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_systemd_Service\"><\/span>Using systemd Service<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Create a systemd unit file, e.g., <code>\/etc\/systemd\/system\/gre-tunnel.service<\/code> with the following content:<\/p>\n<pre>[Unit]\nDescription=GRE Tunnel Setup\nAfter=network.target\n\n[Service]\nType=oneshot\nExecStart=\/usr\/local\/bin\/gre-tunnel.sh\nRemainAfterExit=yes\n\n[Install]\nWantedBy=multi-user.target\n<\/pre>\n<p>Then, create the script <code>\/usr\/local\/bin\/gre-tunnel.sh<\/code>:<\/p>\n<pre>#!\/bin\/bash\nip tunnel add gre1 mode gre local [LOCAL_IP] remote [REMOTE_IP] ttl 255\nip addr add 10.10.10.1\/24 dev gre1\nip link set gre1 up\nip route add [REMOTE_PRIVATE_SUBNET] via 10.10.10.2 dev gre1\n<\/pre>\n<p>Make it executable:<\/p>\n<pre>sudo chmod +x \/usr\/local\/bin\/gre-tunnel.sh<\/pre>\n<p>Enable the service:<\/p>\n<pre>sudo systemctl enable gre-tunnel.service<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Network_Configuration_Files\"><\/span>Network Configuration Files<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Depending on your distro, edit network scripts or Netplan files to persist tunnel config.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Troubleshooting_GRE_Tunnel_on_VPS\"><\/span>Troubleshooting GRE Tunnel on VPS<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Even with clear instructions, hiccups happen. Here\u2019s how to troubleshoot common issues.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"1_Tunnel_Does_Not_Come_Up\"><\/span>1. Tunnel Does Not Come Up<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Check kernel GRE module <code>lsmod | grep gre<\/code><\/li>\n<li>Verify local and remote IP addresses are correct<\/li>\n<li>Ensure GRE protocol is allowed by firewall rules<\/li>\n<li>Check VPS provider restrictions\u2014some block GRE by default<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"2_No_Ping_or_Traffic_Through_Tunnel\"><\/span>2. No Ping or Traffic Through Tunnel<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Verify IP forwarding is enabled <code>sysctl net.ipv4.ip_forward<\/code><\/li>\n<li>Confirm routing table has correct entries <code>ip route<\/code><\/li>\n<li>Check for reverse path filtering on VPS (disable if necessary)<\/li>\n<li>Validate subnet masks and IP addressing are consistent<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"3_Performance_Issues\"><\/span>3. Performance Issues<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Check network latency with <code>ping<\/code> and <code>traceroute<\/code><\/li>\n<li>Consider MTU size on tunnel interface, adjust if fragmentation occurs<\/li>\n<li>Review VPS resource utilization to avoid CPU bottlenecks<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Advanced_GRE_Tunnel_Configuration_Options\"><\/span>Advanced GRE Tunnel Configuration Options<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Once you have the basics solid, you may want to explore advanced options to maximize your GRE tunnel\u2019s efficiency.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Multipoint_GRE_mGRE\"><\/span>Multipoint GRE (mGRE)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>If you want to create a mesh of GRE tunnels dynamically configured, mGRE extends basic GRE functionality, commonly used with routing protocols like DMVPN.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Tunneling_Non-IP_Protocols\"><\/span>Tunneling Non-IP Protocols<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>GRE supports encapsulating many protocols beyond IP, which can be useful for certain legacy or specialized network scenarios.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Combining_GRE_with_IPsec_for_Encryption\"><\/span>Combining GRE with IPsec for Encryption<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>By default, GRE doesn\u2019t encrypt traffic. For sensitive data, you can tunnel GRE inside an IPsec VPN, gaining encrypted transport over the public Internet.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Security_Considerations_When_Configuring_GRE_Tunnel_on_VPS\"><\/span>Security Considerations When Configuring GRE Tunnel on VPS<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>GRE is not inherently encrypted\u2014consider these security best practices:<\/p>\n<ul>\n<li><strong>Use IPsec:<\/strong> Encrypt GRE traffic with IPsec for confidentiality.<\/li>\n<li><strong>Restrict Source IPs:<\/strong> Only allow tunnel traffic from trusted endpoints.<\/li>\n<li><strong>Monitor Logs:<\/strong> Keep an eye on system and network logs for anomalies.<\/li>\n<li><strong>Regular Updates:<\/strong> Keep your VPS OS and <a href=\"https:\/\/avenacloud.com\/blog\/how-to-install-pip-on-windows\/\">packages<\/a> patched.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Use_Cases_for_GRE_Tunnel_on_VPS\"><\/span>Use Cases for GRE Tunnel on VPS<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Understanding real-world applications highlights why this configuration matters:<\/p>\n<ul>\n<li><strong>Secure WAN Connectivity:<\/strong> Connect remote offices securely over the Internet.<\/li>\n<li><strong>Cloud Network Extension:<\/strong> Link cloud VPS instances into your private network.<\/li>\n<li><strong>Bypass ISP Restrictions:<\/strong> GRE tunnels sometimes help maneuver around routing policies.<\/li>\n<li><strong>Multicast Traffic Transport:<\/strong> GRE tunnels can carry multicast packets over networks that don\u2019t support them natively.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Performance_Tips_for_GRE_Tunnel_on_VPS\"><\/span>Performance Tips for GRE Tunnel on VPS<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li>Optimize MTU size to reduce fragmentation handling.<\/li>\n<li>Use VPS instances with better networking capabilities.<\/li>\n<li>Monitor CPU usage, as <a href=\"https:\/\/avenacloud.com\/blog\/how-to-set-up-gre-tunnels-for-private-networking-a-step-by-step-guide\/\">GRE<\/a> encapsulation is CPU intensive.<\/li>\n<li>Consider placement of VPS geographically to reduce latency.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Tools_to_Validate_and_Monitor_GRE_Tunnel\"><\/span>Tools to Validate and Monitor GRE Tunnel<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n<thead>\n<tr>\n<th>Tool<\/th>\n<th>Purpose<\/th>\n<th>Command\/Details<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>ping<\/td>\n<td>Test reachability over GRE tunnel IPs<\/td>\n<td>ping 10.10.10.2<\/td>\n<\/tr>\n<tr>\n<td>traceroute<\/td>\n<td>Check path to remote tunnel endpoint<\/td>\n<td>traceroute 10.10.10.2<\/td>\n<\/tr>\n<tr>\n<td>tcpdump<\/td>\n<td>Capture GRE packets for troubleshooting<\/td>\n<td>sudo tcpdump -i gre1<\/td>\n<\/tr>\n<tr>\n<td>ip<\/td>\n<td>Manage interfaces and routes<\/td>\n<td>ip addr, ip route, ip tunnel<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><span class=\"ez-toc-section\" id=\"Best_Practices_Summary_for_Configuring_GRE_Tunnel_on_VPS\"><\/span>Best Practices Summary for Configuring GRE Tunnel on VPS<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ol>\n<li>Verify kernel modules and firewall settings before setup.<\/li>\n<li>Use consistent IP addressing and routing schemes.<\/li>\n<li>Enable IP forwarding and disable conflicting filters.<\/li>\n<li>Automate tunnel setup to survive VPS reboots.<\/li>\n<li>Secure GRE traffic with additional layers like IPsec.<\/li>\n<li>Monitor tunnel health and network performance regularly.<\/li>\n<\/ol>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Configuring a GRE tunnel on your VPS unlocks numerous possibilities for secure, flexible, and efficient network connectivity. This <strong>Step-by-Step Guide: Configure GRE Tunnel on VPS<\/strong> has equipped you with the knowledge, detailed instructions, and best practices to confidently set up and manage GRE tunnels. Whether you\u2019re extending private networks, enhancing cloud integration, or improving remote connectivity, GRE tunnels provide a powerful tool at your fingertips.<\/p>\n<p>Ready to secure and optimize your network now? Follow the steps, apply the best practices, and take control over your VPS networking like a true pro. Don\u2019t forget to monitor and maintain your setup \u2014 your secure connection depends on it!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In today&#8217;s interconnected world, network security and efficient data routing are more essential than ever. Whether you\u2019re a system administrator, developer, or an IT enthusiast, understanding how to set up a GRE tunnel on your VPS can drastically improve your&#8230; <\/p>\n","protected":false},"author":1,"featured_media":4726,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1693,1694],"class_list":["post-4724","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps-vds","tag-configure-gre-tunnel-vps","tag-vps-gre-tunnel-setup"],"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/posts\/4724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/comments?post=4724"}],"version-history":[{"count":3,"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/posts\/4724\/revisions"}],"predecessor-version":[{"id":4932,"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/posts\/4724\/revisions\/4932"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/media\/4726"}],"wp:attachment":[{"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/media?parent=4724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/categories?post=4724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/tags?post=4724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}