1 .\" $NetBSD: gre.4,v 1.41 2009/01/04 16:30:17 wiz Exp $
3 .\" Copyright (c) 1998 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.
35 .Nd encapsulating network device
41 network interface pseudo device encapsulates datagrams
43 These encapsulated datagrams are routed to a destination host,
44 where they are decapsulated and further routed to their final destination.
47 appears to the inner datagrams as one hop.
50 interfaces are dynamically created and destroyed with the
57 This driver currently supports the following modes of operation:
59 .It GRE encapsulation (IP protocol number 47)
60 Encapsulated datagrams are
61 prepended an outer datagram and a GRE header.
62 The GRE header specifies the type of the encapsulated datagram and
63 thus allows for tunneling other protocols than IP like e.g. AppleTalk.
64 GRE mode is also the default tunnel mode on Cisco routers.
65 This is also the default mode of operation of the
68 .It GRE in UDP encapsulation
69 Encapsulated datagrams are prepended a GRE header, and then they
70 are sent over a UDP socket.
71 Userland may create the socket and
73 it to the kernel using the
76 If userland does not supply a socket, then the kernel will create
77 one using the addresses and ports supplied by
83 .It MOBILE encapsulation (IP protocol number 55)
85 encapsulated into IP, but with a shorter encapsulation.
86 The original IP header is modified and the modifications are inserted
87 between the so modified header and the original payload.
90 only for IP in IP encapsulation.
95 interfaces support a number of
100 Set the IP address of the local tunnel end.
101 This is the source address set by or displayed by ifconfig for the
105 Set the IP address of the remote tunnel end.
106 This is the destination address set by or displayed by ifconfig for the
110 Query the IP address that is set for the local tunnel end.
111 This is the address the encapsulation header carries as local
112 address (i.e. the real address of the tunnel start point.)
114 Query the IP address that is set for the remote tunnel end.
115 This is the address the encapsulated packets are sent to (i.e. the
116 real address of the remote tunnel endpoint.)
118 Set the operation mode to the specified IP protocol value.
119 The protocol is passed to the interface in (struct ifreq)-\*[Gt]ifr_flags.
120 The operation mode can also be given as
121 .Bl -tag -width link0xxx
133 Query operation mode.
135 Delegate a socket from userland to a tunnel interface in UDP
137 The file descriptor for the socket is passed in
138 (struct ifreq)-\*[Gt]ifr_value.
141 Note that the IP addresses of the tunnel endpoints may be the same as the
144 for the interface (as if IP is encapsulated), but need not be, as e.g. when
145 encapsulating AppleTalk.
147 .Ss Example 1: Basic GRE tunneling
148 Configuration example:
150 Host X-- Router A --------------tunnel---------- Router D ----Host E
153 +----- Router B ----- Router C --------+
159 # route add default B
160 # ifconfig greN create
161 # ifconfig greN A D netmask 0xffffffff linkX up
162 # ifconfig greN tunnel A D
169 ip unnumbered D ! e.g. address from Ethernet interface
170 tunnel source D ! e.g. address from Ethernet interface
172 ip route C \*[Lt]some interface and mask\*[Gt]
174 ip route X mask tunnelX
180 # route add default C
181 # ifconfig greN create
183 # ifconfig tunnel greN D A
186 If all goes well, you should see packets flowing ;-)
188 If you want to reach Router A over the tunnel (from Router D (Cisco)), then
189 you have to have an alias on Router A for e.g. the Ethernet interface like:
191 ifconfig \*[Lt]etherif\*[Gt] alias Y
196 ip route Y mask tunnelX
198 .Ss Example 2: Linking private subnets
199 A similar setup can be used to create a link between two private networks
200 (for example in the 192.168 subnet) over the Internet:
202 192.168.1.* --- Router A -------tunnel-------- Router B --- 192.168.2.*
205 +----- the Internet ------+
208 Assuming Router A has the (external) IP address A and the internal address
209 192.168.1.1, while Router B has external address B and internal address
210 192.168.2.1, the following commands will configure the tunnel:
214 # ifconfig greN create
215 # ifconfig greN 192.168.1.1 192.168.2.1
216 # ifconfig greN tunnel A B
217 # route add -net 192.168.2 -netmask 255.255.255.0 192.168.2.1
222 # ifconfig greN create
223 # ifconfig greN 192.168.2.1 192.168.1.1
224 # ifconfig greN tunnel B A
225 # route add -net 192.168.1 -netmask 255.255.255.0 192.168.1.1
227 .Ss Example 3: Encapsulating GRE in UDP
228 To setup the same tunnel as above, but using GRE in UDP encapsulation
229 instead of GRE encapsulation, set flags
233 and specify source and destination UDP ports.
237 # ifconfig greN create
238 # ifconfig greN link0 link2
239 # ifconfig greN 192.168.1.1 192.168.2.1
240 # ifconfig greN tunnel A,port-A B,port-B
241 # route add -net 192.168.2 -netmask 255.255.255.0 192.168.2.1
246 # ifconfig greN create
247 # ifconfig greN link0 link2
248 # ifconfig greN 192.168.2.1 192.168.1.1
249 # ifconfig greN tunnel B,port-B A,port-A
250 # route add -net 192.168.1 -netmask 255.255.255.0 192.168.1.1
252 .Ss Example 4: Realizing IPv6 connectivity
253 Along these lines, you can use GRE tunnels to interconnect two IPv6
254 networks over an IPv4 infrastructure, or to hook up to the IPv6 internet
255 via an IPv4 tunnel to a Cisco router.
257 2001:db8:1::/64 -- NetBSD A ---- Tunnel ---- Cisco B --- IPv6 Internet
260 +------ the Internet ------+
263 The example will use the following addressing:
266 A has the IPv4 address A and the IPv6 address 2001:db8:1::1 (connects
267 to internal network 2001:db8:1::/64).
269 has external IPv4 address B.
270 .It All the IPv6 internet world
271 is behind B, so A wants to route 0::0/0
272 (the IPv6 default route) into the tunnel.
274 will use a transit network: 2001:db8:ffff::1/64 on
277 side, and ::2/64 on the Cisco side.
280 Then the following commands will configure the tunnel:
285 # ifconfig greN create
286 # ifconfig greN inet6 2001:db8:ffff::1/64
287 # ifconfig greN tunnel A B
288 # route add -inet6 2001:db8:ffff::/64 2001:db8:ffff::2 -ifp greN
289 # route add -inet6 0::0/0 2001:db8:ffff::2 -ifp greN
296 ipv6 address 2001:db8:ffff::2/64 ! transfer network
297 tunnel source B ! e.g. address from LAN interface
298 tunnel destination A ! where the tunnel is connected to
299 ipv6 route 2001:db8::/64 TunnelX ! route this network through tunnel
304 interfaces is set to 1476 by default to match the value used by Cisco routers.
305 This may not be an optimal value, depending on the link between the two tunnel
307 It can be adjusted via
310 There needs to be a route to the decapsulating host that does not
311 run over the tunnel, as this would be a loop.
312 (This is not relevant for IPv6-over-IPv4 tunnels, of course.)
316 to actually mark the interface as up, the keyword
318 must be given last on its command line.
320 The kernel must be set to forward datagrams by either option
322 in the kernel config file or by issuing the appropriate option to
335 A description of GRE encapsulation can be found in RFC 1701 and RFC 1702.
337 A description of MOBILE encapsulation can be found in RFC 2004.
339 .An Heiko W.Rupp Aq hwr@pilhuhn.de
340 .An David Young Aq dyoung@NetBSD.org
341 .Pq GRE in UDP encapsulation, bug fixes
343 The GRE RFCs are not yet fully implemented (no GRE options).
345 The MOBILE encapsulation appears to have been broken since
346 it was first added to
349 It is known to interoperate with another
351 in MOBILE mode, however, it has not been tested for interoperability
352 with any other implementation of RFC 2004.
358 contain a daemon for automatically establishing a UDP tunnel between
359 a host behind a NAT router and a host on the Internet.