1 .\" $NetBSD: gre.4,v 1.28 2002/06/10 02:49:35 itojun Exp $
3 .\" Copyright 1998 (c) The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Heiko W.Rupp <hwr@pilhuhn.de>
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
37 .Nd encapsulating network device
41 device into the kernel, place the following line in the kernel
43 .Bd -ragged -offset indent
47 Alternatively, to load the
49 device as a module at boot time, place the following line in
51 .Bd -literal -offset indent
57 network interface pseudo device encapsulates datagrams
59 These encapsulated datagrams are routed to a destination host,
60 where they are decapsulated and further routed to their final destination.
63 appears to the inner datagrams as one hop.
66 interfaces are dynamically created and destroyed with the
73 This driver currently supports the following modes of operation:
74 .Bl -tag -width indent
75 .It "GRE encapsulation (IP protocol number 47)"
76 Encapsulated datagrams are
77 prepended an outer datagram and a GRE header.
78 The GRE header specifies
79 the type of the encapsulated datagram and thus allows for tunneling other
80 protocols than IP like e.g.\& AppleTalk.
81 GRE mode is also the default tunnel mode on Cisco routers.
82 This is also the default mode of operation of the
85 As part of the GRE mode,
87 also supports Cisco WCCP protocol, both version 1 and version 2.
88 Since there is no reliable way to distinguish between WCCP versions, it
89 should be configured manually using the
94 flag is not set (default), then WCCP version 1 is selected.
95 .It "MOBILE encapsulation (IP protocol number 55)"
97 encapsulated into IP, but with a shorter encapsulation.
99 IP header is modified and the modifications are inserted between the
100 so modified header and the original payload.
103 only for IP-in-IP encapsulation.
108 interfaces support a number of
111 .Bl -tag -width ".Dv GRESADDRS"
113 Set the IP address of the local tunnel end.
114 This is the source address
115 set by or displayed by
121 Set the IP address of the remote tunnel end.
122 This is the destination address
123 set by or displayed by
129 Query the IP address that is set for the local tunnel end.
131 address the encapsulation header carries as local address (i.e., the real
132 address of the tunnel start point).
134 Query the IP address that is set for the remote tunnel end.
136 address the encapsulated packets are sent to (i.e., the real address of
137 the remote tunnel endpoint).
139 Set the operation mode to the specified IP protocol value.
141 protocol is passed to the interface in
142 .Po Vt "struct ifreq" Pc Ns Li -> Ns Va ifr_flags .
143 The operation mode can also be given as
145 .Bl -tag -width ".Cm -link0" -compact
157 flag is not used to choose encapsulation, but to modify the
158 internal route search for the remote tunnel endpoint, see the
162 Query operation mode.
164 Set the GRE key used for outgoing packets.
165 A value of 0 disables the key option.
167 Get the GRE key currently used for outgoing packets.
168 0 means no outgoing key.
171 Note that the IP addresses of the tunnel endpoints may be the same as the
174 for the interface (as if IP is encapsulated), but need not be, as e.g.\& when
175 encapsulating AppleTalk.
177 Configuration example:
179 Host X-- Host A ----------------tunnel---------- Cisco D------Host E
182 +------Host B----------Host C----------+
187 .Bd -literal -offset indent
190 ifconfig greN A D netmask 0xffffffff linkX up
191 ifconfig greN tunnel A D
196 .Bd -literal -offset indent
198 ip unnumbered D ! e.g. address from Ethernet interface
199 tunnel source D ! e.g. address from Ethernet interface
201 ip route C <some interface and mask>
203 ip route X mask tunnelX
210 .Bd -literal -offset indent
214 ifconfig greN tunnel D A
217 If all goes well, you should see packets flowing ;-)
219 If you want to reach Host A over the tunnel (from Host D (Cisco)), then
220 you have to have an alias on Host A for e.g.\& the Ethernet interface like:
222 .Dl "ifconfig <etherif> alias Y"
226 .Dl "ip route Y mask tunnelX"
228 A similar setup can be used to create a link between two private networks
229 (for example in the 192.168 subnet) over the Internet:
231 192.168.1.* --- Router A -------tunnel-------- Router B --- 192.168.2.*
234 +------ the Internet ------+
237 Assuming router A has the (external) IP address A and the internal address
238 192.168.1.1, while router B has external address B and internal address
239 192.168.2.1, the following commands will configure the tunnel:
242 .Bd -literal -offset indent
244 ifconfig greN 192.168.1.1 192.168.2.1 link1
245 ifconfig greN tunnel A B
246 route add -net 192.168.2 -netmask 255.255.255.0 192.168.2.1
250 .Bd -literal -offset indent
252 ifconfig greN 192.168.2.1 192.168.1.1 link1
253 ifconfig greN tunnel B A
254 route add -net 192.168.1 -netmask 255.255.255.0 192.168.1.1
257 Note that this is a safe situation where the
259 flag (as discussed in the
261 section below) may (and probably should) be set.
265 interfaces is set to 1476 by default, to match the value used by Cisco routers.
266 If grekey is set this is lowered to 1472.
267 This may not be an optimal value, depending on the link between the two tunnel
269 It can be adjusted via
272 For correct operation, the
274 device needs a route to the destination that is less specific than the
276 (Basically, there needs to be a route to the decapsulating host that
277 does not run over the tunnel, as this would be a loop.)
278 If the addresses are ambiguous, doing the
279 .Nm ifconfig Cm tunnel
284 IP addresses will help to find a route outside the tunnel.
288 to actually mark the interface as
292 must be given last on its command line.
294 The kernel must be set to forward datagrams by setting the
295 .Va net.inet.ip.forwarding
297 variable to non-zero.
309 A description of GRE encapsulation can be found in RFC 1701 and RFC 1702.
311 A description of MOBILE encapsulation can be found in RFC 2004.
313 .An Heiko W.Rupp Aq hwr@pilhuhn.de
319 toggles the last bit of the
320 IP-address to provoke the search for a less specific route than the
321 one directly over the tunnel to prevent loops.
322 This is possibly not the best solution.
324 To avoid the address munging described above, turn on the
329 This implies that the GRE packet destination and the ifconfig remote host
330 are not the same IP addresses, and that the GRE destination does not route
335 The current implementation uses the key only for outgoing packets.
336 Incoming packets with a different key or without a key will be treated as if they
337 would belong to this interface.
339 RFC1701 is not fully supported, however all unsupported features have been
340 deprecated in RFC2784.