Gre Tunnel in Linux
How to create a GRE tunnel on Linux Question: I want to connect to remote networks by using a GRE tunnel. How can I create a GRE tunnel between two end points on Linux?
GRE tunnels are IP-over-IP tunnels which can encapsulate IPv4/IPv6 and unicast/multicast traffic. To create a GRE tunnel on Linux, you need ip_gre kernel module, which is GRE over IPv4 tunneling driver.
So first make sure that ip_gre is loaded.
$ sudo modprobe ip_gre $ lsmod | grep gre ip_gre 22432 0 gre 12989 1 ip_gre
Here, we assume that you want to create a GRE tunnel between two interfaces with the following IP addresses.
Host A: 192.168.233.204 Host B: 220.127.116.11
On host A, run the following command.
$ sudo ip tunnel add gre0 mode gre remote 18.104.22.168 local 192.168.233.204 ttl 255 $ sudo ip link set gre0 up $ sudo ip addr add 10.10.10.1/24 dev gre0
In the above, we create a GRE-type tunnel device called gre0, and set its remote address to 22.214.171.124. Tunneling packets will be originating from 192.168.233.204 (local IP address), and their TTL field will be set to 255. The tunnel device is assigned IP address 10.10.10.1 with netmask 255.255.255.0.