]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sbin/natd/natd.8
Back out previous commit.
[FreeBSD/FreeBSD.git] / sbin / natd / natd.8
1 .\" manual page [] for natd 1.4
2 .\"     $Id: natd.8,v 1.19 1999/06/21 07:58:25 brian Exp $
3 .Dd 15 April 1997
4 .Os FreeBSD
5 .Dt NATD 8
6 .Sh NAME
7 .Nm natd
8 .Nd
9 Network Address Translation Daemon
10 .Sh SYNOPSIS
11 .Nm
12 .Op Fl ldsmvu
13 .Op Fl dynamic
14 .Op Fl i Ar inport
15 .Op Fl o Ar outport
16 .Op Fl p Ar port
17 .Op Fl a Ar address
18 .Op Fl n Ar interface
19 .Op Fl f Ar configfile
20
21 .Nm
22 .Op Fl log
23 .Op Fl deny_incoming
24 .Op Fl log_denied
25 .Op Fl use_sockets
26 .Op Fl same_ports
27 .Op Fl verbose
28 .Op Fl log_facility Ar facility_name
29 .Op Fl unregistered_only
30 .Op Fl dynamic
31 .Op Fl inport Ar inport
32 .Op Fl outport Ar outport
33 .Op Fl port Ar port
34 .Op Fl alias_address Ar address
35 .Op Fl interface Ar interface
36 .Op Fl config Ar configfile
37 .Op Fl redirect_port Ar linkspec
38 .Op Fl redirect_address Ar localIP publicIP
39 .Op Fl reverse
40 .Op Fl proxy_only
41 .Op Fl proxy_rule Ar proxyspec
42 .Op Fl pptpalias Ar localIP
43
44 .Sh DESCRIPTION
45 This program provides a Network Address Translation facility for use
46 with
47 .Xr divert 4
48 sockets under FreeBSD.  It is intended for use with NICs - if you want
49 to do NAT on a PPP link, use the -alias switch to
50 .Xr ppp 8 .
51
52 .Pp
53 .Nm Natd
54 normally runs in the background as a daemon.  It is passed raw IP packets
55 as they travel into and out of the machine, and will possibly change these
56 before re-injecting them back into the IP packet stream.
57
58 .Pp
59 .Nm Natd
60 changes all packets destined for another host so that their source
61 IP number is that of the current machine.  For each packet changed
62 in this manner, an internal table entry is created to record this
63 fact.  The source port number is also changed to indicate the
64 table entry applying to the packet.  Packets that are received with
65 a target IP of the current host are checked against this internal
66 table.  If an entry is found, it is used to determine the correct
67 target IP number and port to place in the packet.
68
69 .Pp
70 The following command line options are available.
71 .Bl -tag -width Fl
72
73 .It Fl log | l
74 Log various aliasing statistics and information to the file
75 .Pa /var/log/alias.log .
76 This file is truncated each time natd is started.
77
78 .It Fl deny_incoming | d
79 Reject packets destined for the current IP number that have no entry
80 in the internal translation table.
81
82 .It Fl log_denied
83 Log denied incoming packets via syslog (see also log_facility)
84
85 .It Fl log_facility Ar facility_name
86 Use specified log facility when logging information via syslog.
87 Facility names are as in
88 .Xr syslog.conf 5
89
90 .It Fl use_sockets | s
91 Allocate a
92 .Xr socket 2
93 in order to establish an FTP data or IRC DCC send connection.  This
94 option uses more system resources, but guarantees successful connections
95 when port numbers conflict.
96
97 .It Fl same_ports | m
98 Try to keep the same port number when altering outgoing packets.
99 With this option, protocols such as RPC will have a better chance
100 of working.  If it is not possible to maintain the port number, it
101 will be silently changed as per normal.
102
103 .It Fl verbose | v
104 Don't call
105 .Xr fork 2
106 or
107 .Xr daemon 3
108 on startup.  Instead, stay attached to the controling terminal and
109 display all packet alterations to the standard output.  This option
110 should only be used for debugging purposes.
111
112 .It Fl unregistered_only | u
113 Only alter outgoing packets with an unregistered source address.
114 According to rfc 1918, unregistered source addresses are 10.0.0.0/8,
115 172.16.0.0/12 and 192.168.0.0/16.
116
117 .It Fl redirect_port Ar proto targetIP:targetPORT[-targetPORT] [aliasIP:]aliasPORT[-aliasPORT] [remoteIP[:remotePORT[-remotePORT]]]
118 Redirect incoming connections arriving to given port(s) to another host
119 and port(s).
120 Proto is either tcp or udp, targetIP is the desired target IP
121 number, targetPORT is the desired target PORT number or range, aliasPORT
122 is the requested PORT number or range, and aliasIP is the aliasing address.
123 RemoteIP and remotePORT can be used to specify the connection
124 more accurately if necessary.
125 The targetPORT range and aliasPORT range need not be the same numerically,
126 but must have the same size.
127 If remotePORT is not specified, it is assumed to be all ports.
128 If remotePORT is specified, it must match the size of targetPORT, or be 0
129 (all ports).
130 For example, the argument
131
132 .Dl Ar tcp inside1:telnet 6666
133
134 means that incoming tcp packets destined for port 6666 on this machine will
135 be sent to the telnet port on the inside1 machine.
136
137 .Dl Ar tcp inside2:2300-2399 3300-3399
138
139 will redirect incoming connections on ports 3300-3399 to host
140 inside2, ports 2300-2399.
141 The mapping is 1:1 meaning port 3300 maps to 2300, 3301 maps to 2301, etc.
142
143 .It Fl redirect_address Ar localIP publicIP
144 Redirect traffic for public IP address to a machine on the local
145 network. This function is known as "static NAT". Normally static NAT
146 is useful if your ISP has allocated a small block of IP addresses to you,
147 but it can even be used in the case of single address:
148
149   redirect_address 10.0.0.8 0.0.0.0
150
151 The above command would redirect all incoming traffic
152 to machine 10.0.0.8.
153
154 If several address aliases specify the same public address
155 as follows
156
157   redirect_address 192.168.0.2 public_addr
158   redirect_address 192.168.0.3 public_addr
159   redirect_address 192.168.0.4 public_addr
160   
161 the incoming traffic will be directed to the last
162 translated local address (192.168.0.4), but outgoing
163 traffic to the first two addresses will still be aliased
164 to specified public address.
165
166 .It Fl dynamic
167 If the
168 .Fl n
169 or
170 .Fl interface
171 option is used,
172 .Nm
173 will monitor the routing socket for alterations to the
174 .Ar interface
175 passed.  If the interfaces IP number is changed,
176 .Nm
177 will dynamically alter its concept of the alias address.
178
179 .It Fl i | inport Ar inport
180 Read from and write to
181 .Ar inport ,
182 treating all packets as packets coming into the machine.
183
184 .It Fl o | outport Ar outport
185 Read from and write to
186 .Ar outport ,
187 treating all packets as packets going out of the machine.
188
189 .It Fl p | port Ar port
190 Read from and write to
191 .Ar port ,
192 distinguishing packets as incoming our outgoing using the rules specified in
193 .Xr divert 4 .
194 If
195 .Ar port
196 is not numeric, it is searched for in the
197 .Pa /etc/services
198 database using the
199 .Xr getservbyname 3
200 function.  If this flag is not specified, the divert port named natd will
201 be used as a default.  An example entry in the
202 .Pa /etc/services
203 database would be:
204
205   natd   8668/divert  # Network Address Translation socket
206
207 Refer to
208 .Xr services 5
209 for further details.
210
211 .It Fl a | alias_address Ar address
212 Use
213 .Ar address
214 as the alias address.  If this option is not specified, the
215 .Fl n
216 or
217 .Fl interface
218 option must be used.  The specified address should be the address assigned
219 to the public network interface.
220 .Pp
221 All data passing out through this addresses interface will be rewritten
222 with a source address equal to
223 .Ar address .
224 All data arriving at the interface from outside will be checked to
225 see if it matches any already-aliased outgoing connection.  If it does,
226 the packet is altered accordingly.  If not, all
227 .Fl redirect_port
228 and
229 .Fl redirect_address
230 assignments are checked and actioned.  If no other action can be made,
231 and if
232 .Fl deny_incoming
233 is not specified, the packet is delivered to the local machine and port
234 as specified in the packet.
235
236 .It Fl n | interface Ar interface
237 Use
238 .Ar interface
239 to determine the alias address.  If there is a possibility that the
240 IP number associated with
241 .Ar interface
242 may change, the
243 .Fl dynamic
244 flag should also be used.  If this option is not specified, the
245 .Fl a
246 or
247 .Fl alias_address
248 flag must be used.
249 .Pp
250 The specified
251 .Ar interface
252 must be the public network interface.
253 .It Fl f | config Ar configfile
254 Read configuration from
255 .Ar configfile .
256 .Ar Configfile
257 contains a list of options, one per line in the same form as the
258 long form of the above command line flags.  For example, the line
259
260   alias_address 158.152.17.1
261
262 would specify an alias address of 158.152.17.1.  Options that don't
263 take an argument are specified with an option of
264 .Ar yes
265 or
266 .Ar no
267 in the configuration file.  For example, the line
268
269   log yes
270
271 is synonomous with
272 .Fl log .
273 Empty lines and lines beginning with '#' are ignored.
274
275 .It Fl reverse
276 Reverse operation of natd. This can be useful in some 
277 transparent proxying situations when outgoing traffic
278 is redirected to the local machine and natd is running on the
279 incoming interface (it usually runs on the outgoing interface).
280
281 .It Fl proxy_only
282 Force natd to perform transparent proxying
283 only. Normal address translation is not performed.
284
285 .It Fl proxy_rule Ar [type encode_ip_hdr|encode_tcp_stream] port xxxx server a.b.c.d:yyyy
286 Enable transparent proxying. Packets with the given port going through this
287 host to any other host are redirected to the given server and port.
288 Optionally, the original target address can be encoded into the packet. Use 
289 .Dq encode_ip_hdr
290 to put this information into the IP option field or
291 .Dq encode_tcp_stream
292 to inject the data into the beginning of the TCP stream.
293
294 .It Fl pptpalias Ar localIP
295 Allow PPTP packets to go to the defined localIP address. PPTP is a VPN or secure
296 IP tunneling technology being developed primarily by Microsoft. For its encrypted traffic,
297 it uses an old IP encapsulation protocol called GRE (47). This
298 natd option will translate any traffic of this protocol to a
299 single, specified IP address. This would allow either one client or one server 
300 to be serviced with natd. If you are setting up a server, don't forget to allow the TCP traffic
301 for the PPTP setup. For a client or server, you must allow GRE (protocol 47) if you have firewall lists active.
302
303 .El
304
305 .Sh RUNNING NATD
306 The following steps are necessary before attempting to run
307 .Nm natd :
308
309 .Bl -enum
310 .It
311 Get FreeBSD version 2.2 or higher.  Versions before this do not support
312 .Xr divert 4
313 sockets.
314
315 .It
316 Build a custom kernel with the following options:
317
318   options IPFIREWALL
319   options IPDIVERT
320
321 Refer to the handbook for detailed instructions on building a custom
322 kernel.
323
324 .It
325 Ensure that your machine is acting as a gateway.  This can be done by
326 specifying the line
327
328   gateway_enable=YES
329
330 in
331 .Pa /etc/rc.conf ,
332 or using the command
333
334   sysctl -w net.inet.ip.forwarding=1
335
336 .It
337 If you wish to use the
338 .Fl n
339 or
340 .Fl interface
341 flags, make sure that your interface is already configured.  If, for
342 example, you wish to specify tun0 as your
343 .Ar interface ,
344 and you're using
345 .Xr ppp 8
346 on that interface, you must make sure that you start
347 .Nm ppp
348 prior to starting
349 .Nm natd .
350
351 .It
352 Create an entry in
353 .Pa /etc/services :
354
355   natd          8668/divert  # Network Address Translation socket
356
357 This gives a default for the
358 .Fl p
359 or
360 .Fl port
361 flag.
362
363 .El
364 .Pp
365 Running
366 .Nm
367 is fairly straight forward.  The line
368
369   natd -interface ed0
370
371 should suffice in most cases (substituting the correct interface name).  Once
372 .Nm
373 is running, you must ensure that traffic is diverted to natd:
374
375 .Bl -enum
376 .It
377 You will need to adjust the
378 .Pa /etc/rc.firewall
379 script to taste.  If you're not interested in having a firewall, the
380 following lines will do:
381
382   /sbin/ipfw -f flush
383   /sbin/ipfw add divert natd all from any to any via ed0
384   /sbin/ipfw add pass all from any to any
385
386 The second line depends on your interface (change ed0 as appropriate)
387 and assumes that you've updated
388 .Pa /etc/services
389 with the natd entry as above.  If you specify real firewall rules, it's
390 best to specify line 2 at the start of the script so that
391 .Nm
392 sees all packets before they are dropped by the firewall.  The firewall
393 rules will be run again on each packet after translation by
394 .Nm natd ,
395 minus any divert rules.
396
397 .It
398 Enable your firewall by setting
399
400   firewall_enable=YES
401
402 in
403 .Pa /etc/rc.conf .
404 This tells the system startup scripts to run the
405 .Pa /etc/rc.firewall
406 script.  If you don't wish to reboot now, just run this by hand from the
407 console.  NEVER run this from a virtual session unless you put it into
408 the background.  If you do, you'll lock yourself out after the flush
409 takes place, and execution of
410 .Pa /etc/rc.firewall
411 will stop at this point - blocking all accesses permanently.  Running
412 the script in the background should be enough to prevent this disaster.
413
414 .El
415
416 .Sh SEE ALSO
417 .Xr getservbyname 2 ,
418 .Xr socket 2 ,
419 .Xr divert 4 ,
420 .Xr services 5 ,
421 .Xr ipfw 8
422
423 .Sh AUTHORS
424 This program is the result of the efforts of many people at different
425 times:
426
427 .An Archie Cobbs Aq archie@whistle.com
428 (divert sockets)
429 .An Charles Mott Aq cmott@srv.net
430 (packet aliasing)
431 .An Eivind Eklund Aq perhaps@yes.no
432 (IRC support & misc additions)
433 .An Ari Suutari Aq suutari@iki.fi
434 (natd)
435 .An Dru Nelson Aq dnelson@redwoodsoft.com
436 (PPTP support)
437 .An Brian Somers Aq brian@awfulhak.org
438 (glue)