]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sbin/natd/natd.8
This commit was generated by cvs2svn to compensate for changes in r53801,
[FreeBSD/FreeBSD.git] / sbin / natd / natd.8
1 .\" manual page [] for natd 1.4
2 .\" $FreeBSD$
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 .Pp
274 Trailing spaces and empty lines are ignored.
275 A
276 .Ql \&#
277 sign will mark the rest of the line as a comment.
278
279 .It Fl reverse
280 Reverse operation of natd. This can be useful in some 
281 transparent proxying situations when outgoing traffic
282 is redirected to the local machine and natd is running on the
283 incoming interface (it usually runs on the outgoing interface).
284
285 .It Fl proxy_only
286 Force natd to perform transparent proxying
287 only. Normal address translation is not performed.
288
289 .It Fl proxy_rule Ar [type encode_ip_hdr|encode_tcp_stream] port xxxx server a.b.c.d:yyyy
290 Enable transparent proxying. Packets with the given port going through this
291 host to any other host are redirected to the given server and port.
292 Optionally, the original target address can be encoded into the packet. Use 
293 .Dq encode_ip_hdr
294 to put this information into the IP option field or
295 .Dq encode_tcp_stream
296 to inject the data into the beginning of the TCP stream.
297
298 .It Fl pptpalias Ar localIP
299 Allow PPTP packets to go to the defined localIP address. PPTP is a VPN or secure
300 IP tunneling technology being developed primarily by Microsoft. For its encrypted traffic,
301 it uses an old IP encapsulation protocol called GRE (47). This
302 natd option will translate any traffic of this protocol to a
303 single, specified IP address. This would allow either one client or one server 
304 to be serviced with natd. If you are setting up a server, don't forget to allow the TCP traffic
305 for the PPTP setup. For a client or server, you must allow GRE (protocol 47) if you have firewall lists active.
306
307 .El
308
309 .Sh RUNNING NATD
310 The following steps are necessary before attempting to run
311 .Nm natd :
312
313 .Bl -enum
314 .It
315 Get FreeBSD version 2.2 or higher.  Versions before this do not support
316 .Xr divert 4
317 sockets.
318
319 .It
320 Build a custom kernel with the following options:
321
322   options IPFIREWALL
323   options IPDIVERT
324
325 Refer to the handbook for detailed instructions on building a custom
326 kernel.
327
328 .It
329 Ensure that your machine is acting as a gateway.  This can be done by
330 specifying the line
331
332   gateway_enable=YES
333
334 in
335 .Pa /etc/rc.conf ,
336 or using the command
337
338   sysctl -w net.inet.ip.forwarding=1
339
340 .It
341 If you wish to use the
342 .Fl n
343 or
344 .Fl interface
345 flags, make sure that your interface is already configured.  If, for
346 example, you wish to specify tun0 as your
347 .Ar interface ,
348 and you're using
349 .Xr ppp 8
350 on that interface, you must make sure that you start
351 .Nm ppp
352 prior to starting
353 .Nm natd .
354
355 .It
356 Create an entry in
357 .Pa /etc/services :
358
359   natd          8668/divert  # Network Address Translation socket
360
361 This gives a default for the
362 .Fl p
363 or
364 .Fl port
365 flag.
366
367 .El
368 .Pp
369 Running
370 .Nm
371 is fairly straight forward.  The line
372
373   natd -interface ed0
374
375 should suffice in most cases (substituting the correct interface name).  Once
376 .Nm
377 is running, you must ensure that traffic is diverted to natd:
378
379 .Bl -enum
380 .It
381 You will need to adjust the
382 .Pa /etc/rc.firewall
383 script to taste.  If you're not interested in having a firewall, the
384 following lines will do:
385
386   /sbin/ipfw -f flush
387   /sbin/ipfw add divert natd all from any to any via ed0
388   /sbin/ipfw add pass all from any to any
389
390 The second line depends on your interface (change ed0 as appropriate)
391 and assumes that you've updated
392 .Pa /etc/services
393 with the natd entry as above.  If you specify real firewall rules, it's
394 best to specify line 2 at the start of the script so that
395 .Nm
396 sees all packets before they are dropped by the firewall.
397 .Pp
398 After translation by
399 .Nm natd ,
400 packets re-enter the firewall at the rule number following the rule number
401 that caused the diversion (not the next rule if there are several at the
402 same number).
403
404 .It
405 Enable your firewall by setting
406
407   firewall_enable=YES
408
409 in
410 .Pa /etc/rc.conf .
411 This tells the system startup scripts to run the
412 .Pa /etc/rc.firewall
413 script.  If you don't wish to reboot now, just run this by hand from the
414 console.  NEVER run this from a virtual session unless you put it into
415 the background.  If you do, you'll lock yourself out after the flush
416 takes place, and execution of
417 .Pa /etc/rc.firewall
418 will stop at this point - blocking all accesses permanently.  Running
419 the script in the background should be enough to prevent this disaster.
420
421 .El
422
423 .Sh SEE ALSO
424 .Xr socket 2 ,
425 .Xr getservbyname 3 ,
426 .Xr divert 4 ,
427 .Xr services 5 ,
428 .Xr ipfw 8
429
430 .Sh AUTHORS
431 This program is the result of the efforts of many people at different
432 times:
433
434 .An Archie Cobbs Aq archie@whistle.com
435 (divert sockets)
436 .An Charles Mott Aq cmott@srv.net
437 (packet aliasing)
438 .An Eivind Eklund Aq perhaps@yes.no
439 (IRC support & misc additions)
440 .An Ari Suutari Aq suutari@iki.fi
441 (natd)
442 .An Dru Nelson Aq dnelson@redwoodsoft.com
443 (PPTP support)
444 .An Brian Somers Aq brian@awfulhak.org
445 (glue)