1 .\" $NetBSD: gre.4,v 1.28 2002/06/10 02:49:35 itojun Exp $
2 .\" $FreeBSD: src/share/man/man4/gre.4,v 1.1.2.1 2002/12/01 14:03:11 sobomax Exp $
3 .\" $DragonFly: src/share/man/man4/gre.4,v 1.2 2003/06/17 06:36:59 dillon Exp $
5 .\" Copyright 1998 (c) The NetBSD Foundation, Inc.
6 .\" All rights reserved.
8 .\" This code is derived from software contributed to The NetBSD Foundation
9 .\" by Heiko W.Rupp <hwr@pilhuhn.de>
11 .\" Redistribution and use in source and binary forms, with or without
12 .\" modification, are permitted provided that the following conditions
14 .\" 1. Redistributions of source code must retain the above copyright
15 .\" notice, this list of conditions and the following disclaimer.
16 .\" 2. Redistributions in binary form must reproduce the above copyright
17 .\" notice, this list of conditions and the following disclaimer in the
18 .\" documentation and/or other materials provided with the distribution.
19 .\" 3. All advertising materials mentioning features or use of this software
20 .\" must display the following acknowledgement:
21 .\" This product includes software developed by the NetBSD
22 .\" Foundation, Inc. and its contributors.
23 .\" 4. Neither the name of the The NetBSD Foundation nor the names of its
24 .\" contributors may be used to endorse or promote products derived
25 .\" from this software without specific prior written permission.
27 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 .\" POSSIBILITY OF SUCH DAMAGE.
44 .Nd encapsulating network device
50 network interface pseudo device encapsulates datagrams
51 into IP. These encapsulated datagrams are routed to a destination host,
52 where they are decapsulated and further routed to their final destination.
55 appears to the inner datagrams as one hop.
58 interfaces are dynamically created and destroyed with the
65 This driver currently supports the following modes of operation:
67 .It GRE encapsulation (IP protocol number 47)
68 Encapsulated datagrams are
69 prepended an outer datagram and a GRE header. The GRE header specifies
70 the type of the encapsulated datagram and thus allows for tunneling other
71 protocols than IP like e.g. AppleTalk. GRE mode is also the default tunnel
72 mode on Cisco routers. This is also the default mode of operation of the
75 .It MOBILE encapsulation (IP protocol number 55)
77 encapsulated into IP, but with a shorter encapsulation. The original
78 IP header is modified and the modifications are inserted between the
79 so modified header and the original payload. Like
81 only for IP in IP encapsulation.
86 interfaces support a number of
91 Set the IP address of the local tunnel end. This is the source address
92 set by or displayed by ifconfig for the
96 Set the IP address of the remote tunnel end. This is the destination address
97 set by or displayed by ifconfig for the
101 Query the IP address that is set for the local tunnel end. This is the
102 address the encapsulation header carries as local address (i.e. the real
103 address of the tunnel start point.)
105 Query the IP address that is set for the remote tunnel end. This is the
106 address the encapsulated packets are sent to (i.e. the real address of
107 the remote tunnel endpoint.)
109 Set the operation mode to the specified IP protocol value. The
110 protocol is passed to the interface in (struct ifreq)-\*[Gt]ifr_flags.
111 The operation mode can also be given as
112 .Bl -tag -width link0xxx
122 The link1 flag is not used to choose encapsulation, but to modify the
123 internal route search for the remote tunnel endpoint, see the
127 Query operation mode.
130 Note that the IP addresses of the tunnel endpoints may be the same as the
133 for the interface (as if IP is encapsulated), but need not be, as e.g. when
134 encapsulating AppleTalk.
136 Configuration example:
138 Host X-- Host A ----------------tunnel---------- cisco D------Host E
141 +------Host B----------Host C----------+
146 # route add default B
147 # ifconfig greN create
148 # ifconfig greN A D netmask 0xffffffff linkX up
149 # ifconfig greN tunnel A D
155 ip unnumbered D ! e.g. address from Ethernet interface
156 tunnel source D ! e.g. address from Ethernet interface
158 ip route C \*[Lt]some interface and mask\*[Gt]
160 ip route X mask tunnelX
166 # route add default C
167 # ifconfig greN create
169 # ifconfig tunnel greN D A
172 If all goes well, you should see packets flowing ;-)
174 If you want to reach Host A over the tunnel (from Host D (Cisco)), then
175 you have to have an alias on Host A for e.g. the Ethernet interface like:
177 ifconfig \*[Lt]etherif\*[Gt] alias Y
181 ip route Y mask tunnelX
184 A similar setup can be used to create a link between two private networks
185 (for example in the 192.168 subnet) over the Internet:
187 192.168.1.* --- Router A -------tunnel-------- Router B --- 192.168.2.*
190 +----- the Internet ------+
192 Assuming router A has the (external) IP address A and the internal address
193 192.168.1.1, while router B has external address B and internal address
194 192.168.2.1, the following commands will configure the tunnel:
198 # ifconfig greN create
199 # ifconfig greN 192.168.1.1 192.168.2.1 link1
200 # ifconfig greN tunnel A B
201 # route add -net 192.168.2 -netmask 255.255.255.0 192.168.2.1
206 # ifconfig greN create
207 # ifconfig greN 192.168.2.1 192.168.1.1 link1
208 # ifconfig greN tunnel B A
209 # route add -net 192.168.1 -netmask 255.255.255.0 192.168.1.1
212 Note that this is a safe situation where the link1 flag (as discussed in the
214 section below) may (and probably should) be set.
218 interfaces is set to 1476 by default to match the value used by Cisco routers.
219 This may not be an optimal value, depending on the link between the two tunnel
220 endpoints. It can be adjusted via
223 For correct operation, the
225 device needs a route to the destination that is less specific than the
227 (Basically, there needs to be a route to the decapsulating host that
228 does not run over the tunnel, as this would be a loop.)
229 If the addresses are ambiguous, doing the
236 IP addresses will help to find a route outside the tunnel.
240 to actually mark the interface as up, the keyword
242 must be given last on its command line.
244 The kernel must be set to forward datagrams by either option
246 in the kernel config file or by issuing the appropriate option to
259 A description of GRE encapsulation can be found in RFC 1701 and RFC 1702.
261 A description of MOBILE encapsulation can be found in RFC 2004.
263 .An Heiko W.Rupp Aq hwr@pilhuhn.de
265 The compute_route() code in if_gre.c toggles the last bit of the
266 IP-address to provoke the search for a less specific route than the
267 one directly over the tunnel to prevent loops. This is possibly not
270 To avoid the address munging described above, turn on the link1 flag
274 This implies that the GRE packet destination and the ifconfig remote host
275 are not the same IP addresses, and that the GRE destination does not route
280 The GRE RFCs are not yet fully implemented (no GRE options).