3

Can someone please explain the difference between linux ip tunnel and ip link command when it comes to configuring tunnels (such as GRE, IPIP, or VXLAN)?

I can see that I can configure a GRE tunnel, for example, in two ways:

  1. ip link add name gre1 type gre ...
  2. ip tunnel add gre1 mode gre ...

Is there any difference between the two when it comes to the Linux resources created, performance etc.? Is one of the ways old fashined?

Cheers.

poige
  • 9,171
  • 2
  • 24
  • 50
FitzChivalry
  • 177
  • 8

2 Answers2

2

Both iproute2's commands interact with the same kernel, they don't implement anything except this communication only, effectively meaning you should expect no difference in terms of performance.

As can be seen from a relevant commit ip link uses more fresh kernel interface — rtnl_link, compared to ip tunnel: "…

This is accessed through the "ip link" command. The previous tunnel configuration interface "ip tunnel" remains as it is and should be retained for compatibility with old kernels. …

…"

poige
  • 9,171
  • 2
  • 24
  • 50
  • But are they completely equal? Obviously they interact with the same device and kernel, and I assumed there's no performance difference. Are they synonyms? do they both create the same netdev? – FitzChivalry Sep 11 '19 at 06:00
  • https://github.com/shemminger/iproute2/commit/237d9e82c56918a1c972e6f30dd3cf1cfb957412 Probably this commit message can be cited in answer, I guess. – poige Sep 11 '19 at 06:04
  • Ah, fantastic. I should've assumed that iproute2 is just a newer version (and it supports many more types of tunnels) – FitzChivalry Sep 11 '19 at 06:07
  • Both are parts of iproute2 actually – poige Sep 11 '19 at 06:12
0

(Sorry for typing an answer instead of what should be a comment, the comment would be too long to fit...)

I had exactly the same question as you a little while ago, so I read the source code of iproute2. As poige says, ip link uses a different interface than ip tunnel. ip tunnel uses the ioctl SIOCGETTUNNEL, SIOCADDTUNNEL, etc, while ip link uses the rtnl_link interface.

This changes a bit the mode of the interface:

$ sudo ip tunnel add ipiptun mode ipip local 10.3.3.3 remote 10.4.4.4 ttl 64 dev eno1
$ sudo ip link add ipiptun2 type ipip local 10.6.6.6 remote 10.7.7.7 ttl 64 dev eno1 #curiously the mode is any/ip here

    ipiptun: ip/ip remote 10.4.4.4 local 10.3.3.3 dev eno1 ttl 64
    ipiptun2: any/ip remote 10.7.7.7 local 10.6.6.6 dev eno1 ttl 64

Note that now there is an even newer way to create tunnel, which is to use lightweight route tunnels. Cf my question here, trying to understand them: Linux lightweight tunnels