How to create IP-IP tunnel between FreeBSD and Linux
17 Mar2006

Sometimes, I need to connect remote Unix servers with tunnels to provide some specific services or to get access to some internal networks. I was very surprised, when my friend, young system administrator, asked me about how to bring up IP-IP tunnel between different Unix operating systems (FreeBSD and Linux in his case) and said, that he can’t find information about this configuration. As the result of my discovering, this HOWTO has been created.

Lets see to what we have and what we need to do.

We have 2 servers:

  • Server1:
    • OS: Linux
    • Network Interface: eth0
    • IP:
  • Server2:
    • OS: FreeBSD
    • Network Interface: fxp0
    • IP:

We need to get IPv4 over IPv4 tunnel with the following parameters between described servers:

  • Server1: /
  • Server2: /

To setup described configuration on Linux server we need to do following steps:

  • Create ipip tunnel interface:

    # ip tunnel add tun0 mode ipip \\
    > remote local dev eth0

  • Set interface IP addresses:

    # ifconfig tun0 netmask \\
    > pointopoint

  • Set interface MTU and bring interface up:

    # ifconfig tun0 mtu 1500 up

Now we have following interface on the Linux server:

linux:~# ifconfig tun0
tun77     Link encap:IPIP Tunnel  HWaddr
          inet addr:  P-t-P:  Mask:
          UP POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1
          RX packets:6 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:504 (504.0 b)  TX bytes:624 (624.0 b)

Now, we need to create tunnel point at the FeeeBSD server:

  • Create gif tunnel interface:

    # # ifconfig gif0 create

  • Set interface transport IP addresses:

    # gifconfig gif0 inet

  • Set interface IP addresses:

    # ifconfig gif0 netmask

  • Set interface MTU and bring interface up:

    # ifconfig gif0 mtu 1500 up

The result at the FreeBSD side is following:

# ifconfig gif0
gif0: flags=8051 mtu 1500
        tunnel inet -->
        inet --> netmask 0xfffffffc

To check the result we can use ping utility at linux side:

linux:~# ping -c 4
PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=64 time=0.139 ms
64 bytes from icmp_seq=2 ttl=64 time=0.138 ms
64 bytes from icmp_seq=3 ttl=64 time=0.138 ms
64 bytes from icmp_seq=4 ttl=64 time=0.136 ms

--- ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2997ms
rtt min/avg/max/mdev = 0.136/0.137/0.139/0.014 ms

That is all! Now we have “direct” connection between our two servers and we are able to do some routing via this link.