Creating a Gre-tunnel in openwrt.
For creating a gre tunnel you can use basic linux utilities.For example, there are two devices: device А with the local ip-address 192.168.1.100 and device B with the local ip-address 192.168.1.101.
On device А, run the following commands to create a gre-tunnel in openwrt:
ip tunnel add hosta mode gre remote 192.168.1.101 local 192.168.1.100 ttl 255 ip link set hosta up ip addr add 10.0.1.1/24 dev hosta
On device B, run the following commands to create a gre-tunnel in openwrt:
ip tunnel add hostb mode gre remote 192.168.1.100 local 192.168.1.101 ttl 255 ip link set hostb up ip addr add 10.0.1.2/24 dev hostb
Check the output ifconfig:
# ifconfig hostb hostb Link encap:UNSPEC HWaddr C0-A8-01-65-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:10.0.1.2 P-t-P:10.0.1.2 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MTU:1476 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Gre-interface is created. Let's test gre-tunnel in openwrt:
# ping 10.0.1.1 PING 10.0.1.1 (10.0.1.1) 56(84) bytes of data. 64 bytes from 10.0.1.1: icmp_req=1 ttl=64 time=0.246 ms 64 bytes from 10.0.1.1: icmp_req=2 ttl=64 time=0.229 ms 64 bytes from 10.0.1.1: icmp_req=3 ttl=64 time=0.208 ms
Creating ipip-tunnel in openwrt.
On device А, run the following commands to create an ipip tunnel in openwrt:
ip tunnel add ipipA mode ipip remote 192.168.1.101 local 192.168.1.100 ip link set ipipA up ip addr add 10.0.1.1/24 dev ipipA
On device B, run the following commands to create an ipip tunnel:
ip tunnel add ipipB mode ipip remote 192.168.1.100 local 192.168.1.101 ip link set ipipB up ip addr add 10.0.1.2/24 dev ipipB
Check the output ifconfig:
# ifconfig ipipB ipipB Link encap:UNSPEC HWaddr C0-A8-01-65-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:10.0.1.2 P-t-P:10.0.1.2 Mask:255.255.255.0 UP POINTOPOINT RUNNING NOARP MTU:1480 Metric:1 RX packets:3 errors:0 dropped:0 overruns:0 frame:0 TX packets:3 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:252 (252.0 B) TX bytes:192 (192.0 B)
Ipip-interface is created. Let's test the ipip-tunnel in openwrt:
# ping 10.0.1.1 PING 10.0.1.1 (10.0.1.1) 56(84) bytes of data. 64 bytes from 10.0.1.1: icmp_req=1 ttl=64 time=0.288 ms 64 bytes from 10.0.1.1: icmp_req=2 ttl=64 time=0.230 ms 64 bytes from 10.0.1.1: icmp_req=3 ttl=64 time=0.228 ms
You can also create a gre tunnel by editing the file /etc/config/network
For doing that you should install the packages: gre, kmod-gre
Further on device A add the configuration section for gre tunnel to the file:
config interface hosta option proto gre option zone tunnels option peeraddr 192.168.1.101 option tunlink 'eth0' config interface hosta_addr option proto static option ifname @hosta option ipaddr 10.0.1.1 option netmask 255.255.255.0
On device B add the similar configuration section for gre tunnel to the file:
config interface hostb option proto gre option zone tunnels option peeraddr 192.168.1.100 option tunlink 'eth0' config interface hostb_addr option proto static option ifname @hostb option ipaddr 10.0.1.2 option netmask 255.255.255.0
After restarting the system check the output of the command ifconfig:
# ifconfig gre-hostb gre-hostb Link encap:UNSPEC HWaddr C0-A8-01-65-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:10.0.1.2 P-t-P:10.0.1.2 Mask:255.255.255.0 UP POINTOPOINT RUNNING NOARP MTU:1280 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Gre-interface is created successfully.
Let's test the gre tunnel in openwrt:
# ping 10.0.1.1 PING 10.0.1.1 (10.0.1.1) 56(84) bytes of data. 64 bytes from 10.0.1.1: icmp_req=1 ttl=64 time=0.243 ms 64 bytes from 10.0.1.1: icmp_req=2 ttl=64 time=0.214 ms 64 bytes from 10.0.1.1: icmp_req=3 ttl=64 time=0.197 ms