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 $
4 .\" Copyright 1998 (c) The NetBSD Foundation, Inc.
5 .\" All rights reserved.
7 .\" This code is derived from software contributed to The NetBSD Foundation
8 .\" by Heiko W.Rupp <hwr@pilhuhn.de>
10 .\" Redistribution and use in source and binary forms, with or without
11 .\" modification, are permitted provided that the following conditions
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\" notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\" notice, this list of conditions and the following disclaimer in the
17 .\" documentation and/or other materials provided with the distribution.
18 .\" 3. All advertising materials mentioning features or use of this software
19 .\" must display the following acknowledgement:
20 .\" This product includes software developed by the NetBSD
21 .\" Foundation, Inc. and its contributors.
22 .\" 4. Neither the name of the The NetBSD Foundation nor the names of its
23 .\" contributors may be used to endorse or promote products derived
24 .\" from this software without specific prior written permission.
26 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 .\" POSSIBILITY OF SUCH DAMAGE.
43 .Nd encapsulating network device
49 network interface pseudo device encapsulates datagrams
50 into IP. These encapsulated datagrams are routed to a destination host,
51 where they are decapsulated and further routed to their final destination.
54 appears to the inner datagrams as one hop.
57 interfaces are dynamically created and destroyed with the
64 This driver currently supports the following modes of operation:
66 .It GRE encapsulation (IP protocol number 47)
67 Encapsulated datagrams are
68 prepended an outer datagram and a GRE header. The GRE header specifies
69 the type of the encapsulated datagram and thus allows for tunneling other
70 protocols than IP like e.g. AppleTalk. GRE mode is also the default tunnel
71 mode on Cisco routers. This is also the default mode of operation of the
74 .It MOBILE encapsulation (IP protocol number 55)
76 encapsulated into IP, but with a shorter encapsulation. The original
77 IP header is modified and the modifications are inserted between the
78 so modified header and the original payload. Like
80 only for IP in IP encapsulation.
85 interfaces support a number of
90 Set the IP address of the local tunnel end. This is the source address
91 set by or displayed by ifconfig for the
95 Set the IP address of the remote tunnel end. This is the destination address
96 set by or displayed by ifconfig for the
100 Query the IP address that is set for the local tunnel end. This is the
101 address the encapsulation header carries as local address (i.e. the real
102 address of the tunnel start point.)
104 Query the IP address that is set for the remote tunnel end. This is the
105 address the encapsulated packets are sent to (i.e. the real address of
106 the remote tunnel endpoint.)
108 Set the operation mode to the specified IP protocol value. The
109 protocol is passed to the interface in (struct ifreq)-\*[Gt]ifr_flags.
110 The operation mode can also be given as
111 .Bl -tag -width link0xxx
121 The link1 flag is not used to choose encapsulation, but to modify the
122 internal route search for the remote tunnel endpoint, see the
126 Query operation mode.
129 Note that the IP addresses of the tunnel endpoints may be the same as the
132 for the interface (as if IP is encapsulated), but need not be, as e.g. when
133 encapsulating AppleTalk.
135 Configuration example:
137 Host X-- Host A ----------------tunnel---------- cisco D------Host E
140 +------Host B----------Host C----------+
145 # route add default B
146 # ifconfig greN create
147 # ifconfig greN A D netmask 0xffffffff linkX up
148 # ifconfig greN tunnel A D
154 ip unnumbered D ! e.g. address from Ethernet interface
155 tunnel source D ! e.g. address from Ethernet interface
157 ip route C \*[Lt]some interface and mask\*[Gt]
159 ip route X mask tunnelX
165 # route add default C
166 # ifconfig greN create
168 # ifconfig tunnel greN D A
171 If all goes well, you should see packets flowing ;-)
173 If you want to reach Host A over the tunnel (from Host D (Cisco)), then
174 you have to have an alias on Host A for e.g. the Ethernet interface like:
176 ifconfig \*[Lt]etherif\*[Gt] alias Y
180 ip route Y mask tunnelX
183 A similar setup can be used to create a link between two private networks
184 (for example in the 192.168 subnet) over the Internet:
186 192.168.1.* --- Router A -------tunnel-------- Router B --- 192.168.2.*
189 +----- the Internet ------+
191 Assuming router A has the (external) IP address A and the internal address
192 192.168.1.1, while router B has external address B and internal address
193 192.168.2.1, the following commands will configure the tunnel:
197 # ifconfig greN create
198 # ifconfig greN 192.168.1.1 192.168.2.1 link1
199 # ifconfig greN tunnel A B
200 # route add -net 192.168.2 -netmask 255.255.255.0 192.168.2.1
205 # ifconfig greN create
206 # ifconfig greN 192.168.2.1 192.168.1.1 link1
207 # ifconfig greN tunnel B A
208 # route add -net 192.168.1 -netmask 255.255.255.0 192.168.1.1
211 Note that this is a safe situation where the link1 flag (as discussed in the
213 section below) may (and probably should) be set.
217 interfaces is set to 1476 by default to match the value used by Cisco routers.
218 This may not be an optimal value, depending on the link between the two tunnel
219 endpoints. It can be adjusted via
222 For correct operation, the
224 device needs a route to the destination that is less specific than the
226 (Basically, there needs to be a route to the decapsulating host that
227 does not run over the tunnel, as this would be a loop.)
228 If the addresses are ambiguous, doing the
235 IP addresses will help to find a route outside the tunnel.
239 to actually mark the interface as up, the keyword
241 must be given last on its command line.
243 The kernel must be set to forward datagrams by either option
245 in the kernel config file or by issuing the appropriate option to
258 A description of GRE encapsulation can be found in RFC 1701 and RFC 1702.
260 A description of MOBILE encapsulation can be found in RFC 2004.
262 .An Heiko W.Rupp Aq hwr@pilhuhn.de
264 The compute_route() code in if_gre.c toggles the last bit of the
265 IP-address to provoke the search for a less specific route than the
266 one directly over the tunnel to prevent loops. This is possibly not
269 To avoid the address munging described above, turn on the link1 flag
273 This implies that the GRE packet destination and the ifconfig remote host
274 are not the same IP addresses, and that the GRE destination does not route
279 The GRE RFCs are not yet fully implemented (no GRE options).