]> git.saurik.com Git - apple/network_cmds.git/blame - natd.tproj/natd.8
network_cmds-115.2.tar.gz
[apple/network_cmds.git] / natd.tproj / natd.8
CommitLineData
b7080c8e 1.\" manual page [] for natd 1.4
285dd90c 2.\" $Id: natd.8,v 1.4.32.1 2003/03/11 00:59:15 mscopp Exp $
7ba0088d
A
3.Dd June 27, 2000
4.Os Darwin
b7080c8e
A
5.Dt NATD 8
6.Sh NAME
7.Nm natd
7ba0088d 8.Nd Network Address Translation daemon
b7080c8e
A
9.Sh SYNOPSIS
10.Nm
7ba0088d
A
11.Bk -words
12.Op Fl unregistered_only | u
13.Op Fl log | l
14.Op Fl proxy_only
15.Op Fl reverse
16.Op Fl deny_incoming | d
17.Op Fl use_sockets | s
18.Op Fl same_ports | m
19.Op Fl verbose | v
b7080c8e 20.Op Fl dynamic
7ba0088d
A
21.Op Fl in_port | i Ar port
22.Op Fl out_port | o Ar port
23.Op Fl port | p Ar port
24.Op Fl alias_address | a Ar address
25.Op Fl target_address | t Ar address
26.Op Fl interface | n Ar interface
27.Op Fl proxy_rule Ar proxyspec
28.Op Fl redirect_port Ar linkspec
29.Op Fl redirect_proto Ar linkspec
30.Op Fl redirect_address Ar linkspec
31.Op Fl config | f Ar configfile
b7080c8e 32.Op Fl log_denied
b7080c8e 33.Op Fl log_facility Ar facility_name
7ba0088d 34.Op Fl punch_fw Ar firewall_range
285dd90c 35.Op Fl clamp_mss
7ba0088d 36.Ek
b7080c8e
A
37.Sh DESCRIPTION
38This program provides a Network Address Translation facility for use
39with
40.Xr divert 4
7ba0088d
A
41sockets under
42.Fx .
43It is intended for use with NICs - if you want to do NAT on a PPP link,
44use the
45.Fl nat
46switch to
b7080c8e 47.Xr ppp 8 .
7ba0088d
A
48.Pp
49The
50.Nm
51normally runs in the background as a daemon.
52It is passed raw IP packets as they travel into and out of the machine,
53and will possibly change these before re-injecting them back into the
54IP packet stream.
55.Pp
56It changes all packets destined for another host so that their source
57IP number is that of the current machine.
58For each packet changed in this manner, an internal table entry is
59created to record this fact.
60The source port number is also changed to indicate the table entry
61applying to the packet.
62Packets that are received with a target IP of the current host are
63checked against this internal table.
64If an entry is found, it is used to determine the correct target IP
65number and port to place in the packet.
66.Pp
67The following command line options are available:
b7080c8e 68.Bl -tag -width Fl
b7080c8e
A
69.It Fl log | l
70Log various aliasing statistics and information to the file
71.Pa /var/log/alias.log .
7ba0088d
A
72This file is truncated each time
73.Nm
74is started.
b7080c8e 75.It Fl deny_incoming | d
7ba0088d
A
76Do not pass incoming packets that have no
77entry in the internal translation table.
78.Pp
79If this option is not used, then such a packet will be altered
80using the rules in
81.Fl target_address
82below, and the entry will be made in the internal translation table.
b7080c8e 83.It Fl log_denied
7ba0088d
A
84Log denied incoming packets via
85.Xr syslog 3
86.Po
87see also
88.Fl log_facility
89.Pc .
b7080c8e 90.It Fl log_facility Ar facility_name
7ba0088d
A
91Use specified log facility when logging information via
92.Xr syslog 3 .
93Argument
94.Ar facility_name
95is one of the keywords specified in
96.Xr syslog.conf 5 .
b7080c8e
A
97.It Fl use_sockets | s
98Allocate a
99.Xr socket 2
7ba0088d
A
100in order to establish an FTP data or IRC DCC send connection.
101This option uses more system resources, but guarantees successful
102connections when port numbers conflict.
b7080c8e
A
103.It Fl same_ports | m
104Try to keep the same port number when altering outgoing packets.
105With this option, protocols such as RPC will have a better chance
7ba0088d
A
106of working.
107If it is not possible to maintain the port number, it will be silently
108changed as per normal.
b7080c8e 109.It Fl verbose | v
7ba0088d 110Do not call
b7080c8e 111.Xr daemon 3
7ba0088d 112on startup. Instead, stay attached to the controlling terminal and
b7080c8e
A
113display all packet alterations to the standard output. This option
114should only be used for debugging purposes.
b7080c8e 115.It Fl unregistered_only | u
7ba0088d
A
116Only alter outgoing packets with an
117.Em unregistered
118source address.
119According to RFC 1918, unregistered source addresses are 10.0.0.0/8,
b7080c8e 120172.16.0.0/12 and 192.168.0.0/16.
7ba0088d
A
121.It Fl redirect_port Ar proto Xo
122.Ar targetIP Ns : Ns Xo
123.Ar targetPORT Ns Op - Ns Ar targetPORT Xc
124.Op Ar aliasIP Ns : Ns Xo
125.Ar aliasPORT Ns Op - Ns Ar aliasPORT Xc
126.Oo Ar remoteIP Ns Oo : Ns
127.Ar remotePORT Ns Op - Ns Ar remotePORT
128.Oc Oc
129.Xc
130Redirect incoming connections arriving to given port(s) to another host
131and port(s).
132Argument
133.Ar proto
134is either
135.Ar tcp
136or
137.Ar udp ,
138.Ar targetIP
139is the desired target IP number,
140.Ar targetPORT
141is the desired target port number or range,
142.Ar aliasPORT
143is the requested port number or range, and
144.Ar aliasIP
145is the aliasing address.
146Arguments
147.Ar remoteIP
148and
149.Ar remotePORT
150can be used to specify the connection more accurately if necessary.
151The
152.Ar targetPORT
153range and
154.Ar aliasPORT
155range need not be the same numerically, but must have the same size.
156If
157.Ar remotePORT
158is not specified, it is assumed to be all ports.
159If
160.Ar remotePORT
161is specified, it must match the size of
162.Ar targetPORT ,
163or be 0 (all ports).
b7080c8e 164For example, the argument
7ba0088d
A
165.Pp
166.Dl Ar tcp inside1:telnet 6666
167.Pp
168means that incoming TCP packets destined for port 6666 on this machine
169will be sent to the telnet port on the inside1 machine.
170.Pp
171.Dl Ar tcp inside2:2300-2399 3300-3399
172.Pp
173will redirect incoming connections on ports 3300-3399 to host
174inside2, ports 2300-2399.
175The mapping is 1:1 meaning port 3300 maps to 2300, 3301 maps to 2301, etc.
176.It Fl redirect_proto Ar proto localIP Oo
177.Ar publicIP Op Ar remoteIP
178.Oc
179Redirect incoming IP packets of protocol
180.Ar proto
181.Po see Xr protocols 5
182.Pc
183destined for
184.Ar publicIP
185address to a
186.Ar localIP
187address and vice versa.
188.Pp
189If
190.Ar publicIP
191is not specified, then the default aliasing address is used.
192If
193.Ar remoteIP
194is specified, then only packets coming from/to
195.Ar remoteIP
196will match the rule.
b7080c8e
A
197.It Fl redirect_address Ar localIP publicIP
198Redirect traffic for public IP address to a machine on the local
7ba0088d
A
199network.
200This function is known as
201.Em static NAT .
202Normally static NAT is useful if your ISP has allocated a small block
203of IP addresses to you, but it can even be used in the case of single
204address:
205.Pp
206.Dl Ar redirect_address 10.0.0.8 0.0.0.0
207.Pp
b7080c8e
A
208The above command would redirect all incoming traffic
209to machine 10.0.0.8.
7ba0088d 210.Pp
b7080c8e
A
211If several address aliases specify the same public address
212as follows
7ba0088d
A
213.Bd -literal -offset indent
214.Ar redirect_address 192.168.0.2 public_addr
215.Ar redirect_address 192.168.0.3 public_addr
216.Ar redirect_address 192.168.0.4 public_addr
217.Ed
218.Pp
b7080c8e
A
219the incoming traffic will be directed to the last
220translated local address (192.168.0.4), but outgoing
7ba0088d
A
221traffic from the first two addresses will still be aliased
222to appear from the specified
223.Ar public_addr .
224.It Fl redirect_port Ar proto Xo
225.Ar targetIP Ns : Ns Xo
226.Ar targetPORT Ns Oo , Ns
227.Ar targetIP Ns : Ns Xo
228.Ar targetPORT Ns Oo , Ns
229.Ar ...\&
230.Oc Oc
231.Xc
232.Xc
233.Op Ar aliasIP Ns : Ns Xo
234.Ar aliasPORT
235.Xc
236.Oo Ar remoteIP Ns
237.Op : Ns Ar remotePORT
238.Oc
239.Xc
240.It Fl redirect_address Xo
241.Ar localIP Ns Oo , Ns
242.Ar localIP Ns Oo , Ns
243.Ar ...\&
244.Oc Oc
245.Ar publicIP
246.Xc
247These forms of
248.Fl redirect_port
249and
250.Fl redirect_address
251are used to transparently offload network load on a single server and
252distribute the load across a pool of servers.
253This function is known as
254.Em LSNAT
255(RFC 2391).
256For example, the argument
257.Pp
258.Dl Ar tcp www1:http,www2:http,www3:http www:http
259.Pp
260means that incoming HTTP requests for host www will be transparently
261redirected to one of the www1, www2 or www3, where a host is selected
262simply on a round-robin basis, without regard to load on the net.
b7080c8e
A
263.It Fl dynamic
264If the
265.Fl n
266or
267.Fl interface
268option is used,
269.Nm
270will monitor the routing socket for alterations to the
271.Ar interface
7ba0088d
A
272passed.
273If the interface's IP number is changed,
b7080c8e
A
274.Nm
275will dynamically alter its concept of the alias address.
7ba0088d 276.It Fl in_port | i Ar port
b7080c8e 277Read from and write to
7ba0088d
A
278.Xr divert 4
279port
280.Ar port ,
281treating all packets as
282.Dq incoming .
283.It Fl out_port | o Ar port
b7080c8e 284Read from and write to
7ba0088d
A
285.Xr divert 4
286port
287.Ar port ,
288treating all packets as
289.Dq outgoing .
290.It Fl port | p Ar port
b7080c8e 291Read from and write to
7ba0088d
A
292.Xr divert 4
293port
b7080c8e 294.Ar port ,
7ba0088d
A
295distinguishing packets as
296.Dq incoming
297or
298.Dq outgoing
299using the rules specified in
b7080c8e
A
300.Xr divert 4 .
301If
302.Ar port
303is not numeric, it is searched for in the
b7080c8e 304.Xr services 5
7ba0088d
A
305database.
306If this option is not specified, the divert port named
307.Ar natd
308will be used as a default.
309.It Fl alias_address | a Ar address
b7080c8e
A
310Use
311.Ar address
7ba0088d
A
312as the aliasing address.
313If this option is not specified, the
b7080c8e 314.Fl interface
7ba0088d
A
315option must be used.
316The specified address is usually the address assigned to the
317.Dq public
318network interface.
b7080c8e 319.Pp
7ba0088d
A
320All data passing
321.Em out
322will be rewritten with a source address equal to
b7080c8e 323.Ar address .
7ba0088d
A
324All data coming
325.Em in
326will be checked to see if it matches any already-aliased outgoing
327connection.
328If it does, the packet is altered accordingly.
329If not, all
330.Fl redirect_port ,
331.Fl redirect_proto
b7080c8e
A
332and
333.Fl redirect_address
7ba0088d
A
334assignments are checked and actioned.
335If no other action can be made and if
b7080c8e 336.Fl deny_incoming
7ba0088d
A
337is not specified, the packet is delivered to the local machine
338using the rules specified in
339.Fl target_address
340option below.
341.It Fl t | target_address Ar address
342Set the target address.
343When an incoming packet not associated with any pre-existing link
344arrives at the host machine, it will be sent to the specified
345.Ar address .
346.Pp
347The target address may be set to
348.Ar 255.255.255.255 ,
349in which case all new incoming packets go to the alias address set by
350.Fl alias_address
351or
352.Fl interface .
353.Pp
354If this option is not used, or called with the argument
355.Ar 0.0.0.0 ,
356then all new incoming packets go to the address specified in
357the packet.
358This allows external machines to talk directly to internal machines if
359they can route packets to the machine in question.
360.It Fl interface | n Ar interface
b7080c8e
A
361Use
362.Ar interface
7ba0088d
A
363to determine the aliasing address.
364If there is a possibility that the IP number associated with
b7080c8e
A
365.Ar interface
366may change, the
367.Fl dynamic
7ba0088d
A
368option should also be used.
369If this option is not specified, the
b7080c8e 370.Fl alias_address
7ba0088d 371option must be used.
b7080c8e
A
372.Pp
373The specified
374.Ar interface
7ba0088d
A
375is usually the
376.Dq public
377(or
378.Dq external )
379network interface.
380.It Fl config | f Ar file
b7080c8e 381Read configuration from
7ba0088d
A
382.Ar file .
383A
384.Ar file
385should contain a list of options, one per line, in the same form
386as the long form of the above command line options.
387For example, the line
388.Pp
389.Dl alias_address 158.152.17.1
390.Pp
391would specify an alias address of 158.152.17.1.
392Options that do not take an argument are specified with an argument of
b7080c8e
A
393.Ar yes
394or
395.Ar no
396in the configuration file. For example, the line
b7080c8e 397 log yes
7ba0088d 398is synonymous with
b7080c8e 399.Fl log .
7ba0088d
A
400.Pp
401Trailing spaces and empty lines are ignored.
402A
403.Ql \&#
404sign will mark the rest of the line as a comment.
b7080c8e 405.It Fl reverse
7ba0088d
A
406This option makes
407.Nm
408reverse the way it handles
409.Dq incoming
410and
411.Dq outgoing
412packets, allowing it to operate on the
413.Dq internal
414network interface rather than the
415.Dq external
416one.
417.Pp
418This can be useful in some transparent proxying situations
419when outgoing traffic is redirected to the local machine
420and
421.Nm
422is running on the internal interface (it usually runs on the
423external interface).
b7080c8e 424.It Fl proxy_only
7ba0088d
A
425Force
426.Nm
427to perform transparent proxying only.
428Normal address translation is not performed.
429.It Fl proxy_rule Xo
430.Op Ar type encode_ip_hdr | encode_tcp_stream
431.Ar port xxxx
432.Ar server a.b.c.d:yyyy
433.Xc
434Enable transparent proxying.
435Outgoing TCP packets with the given port going through this
b7080c8e 436host to any other host are redirected to the given server and port.
7ba0088d
A
437Optionally, the original target address can be encoded into the packet.
438Use
439.Ar encode_ip_hdr
b7080c8e 440to put this information into the IP option field or
7ba0088d 441.Ar encode_tcp_stream
b7080c8e 442to inject the data into the beginning of the TCP stream.
7ba0088d
A
443.It Fl punch_fw Xo
444.Ar basenumber Ns : Ns Ar count
445.Xc
446This option directs
447.Nm
448to
449.Dq punch holes
450in an
451.Xr ipfirewall 4
452based firewall for FTP/IRC DCC connections.
453This is done dynamically by installing temporary firewall rules which
454allow a particular connection (and only that connection) to go through
455the firewall.
456The rules are removed once the corresponding connection terminates.
457.Pp
458A maximum of
459.Ar count
460rules starting from the rule number
461.Ar basenumber
462will be used for punching firewall holes.
463The range will be cleared for all rules on startup.
285dd90c
A
464.It Fl clamp_mss Xo
465.Xc
466This option enables MSS clamping. The MSS value is derived from the
467MTU of the interface specified in the
468.Fl interface
469option.
b7080c8e 470.El
b7080c8e
A
471.Sh RUNNING NATD
472The following steps are necessary before attempting to run
7ba0088d 473.Nm :
b7080c8e 474.Bl -enum
b7080c8e
A
475.It
476Build a custom kernel with the following options:
7ba0088d
A
477.Bd -literal -offset indent
478options IPFIREWALL
479options IPDIVERT
480.Ed
481.Pp
b7080c8e
A
482Refer to the handbook for detailed instructions on building a custom
483kernel.
b7080c8e 484.It
7ba0088d
A
485Ensure that your machine is acting as a gateway.
486This can be done by specifying the line
487.Pp
488.Dl gateway_enable=YES
489.Pp
490in the
491.Pa /etc/rc.conf
492file or using the command
493.Pp
494.Dl sysctl -w net.inet.ip.forwarding=1
495.Pp
b7080c8e 496.It
7ba0088d 497If you use the
b7080c8e 498.Fl interface
7ba0088d
A
499option, make sure that your interface is already configured.
500If, for example, you wish to specify
501.Ql tun0
502as your
b7080c8e 503.Ar interface ,
7ba0088d 504and you are using
b7080c8e
A
505.Xr ppp 8
506on that interface, you must make sure that you start
507.Nm ppp
508prior to starting
7ba0088d 509.Nm .
b7080c8e
A
510.El
511.Pp
512Running
513.Nm
7ba0088d
A
514is fairly straight forward.
515The line
516.Pp
517.Dl natd -interface en0
518.Pp
519should suffice in most cases (substituting the correct interface name).
520Please check
521.Xr rc.conf 5
522on how to configure it to be started automatically during boot.
523Once
b7080c8e 524.Nm
7ba0088d
A
525is running, you must ensure that traffic is diverted to
526.Nm :
b7080c8e
A
527.Bl -enum
528.It
529You will need to adjust the
530.Pa /etc/rc.firewall
7ba0088d
A
531script to taste.
532If you are not interested in having a firewall, the
b7080c8e 533following lines will do:
7ba0088d
A
534.Bd -literal -offset indent
535/sbin/ipfw -f flush
536/sbin/ipfw add divert natd all from any to any via ed0
537/sbin/ipfw add pass all from any to any
538.Ed
539.Pp
540The second line depends on your interface (change
541.Ql en0
542as appropriate).
543.Pp
544You should be aware of the fact that, with these firewall settings,
545everyone on your local network can fake his source-address using your
546host as gateway.
547If there are other hosts on your local network, you are strongly
548encouraged to create firewall rules that only allow traffic to and
549from trusted hosts.
550.Pp
551If you specify real firewall rules, it is best to specify line 2 at
552the start of the script so that
b7080c8e 553.Nm
7ba0088d
A
554sees all packets before they are dropped by the firewall.
555.Pp
556After translation by
557.Nm ,
558packets re-enter the firewall at the rule number following the rule number
559that caused the diversion (not the next rule if there are several at the
560same number).
b7080c8e
A
561.It
562Enable your firewall by setting
7ba0088d
A
563.Pp
564.Dl firewall_enable=YES
565.Pp
b7080c8e
A
566in
567.Pa /etc/rc.conf .
568This tells the system startup scripts to run the
569.Pa /etc/rc.firewall
7ba0088d
A
570script.
571If you do not wish to reboot now, just run this by hand from the console.
572NEVER run this from a remote session unless you put it into the background.
573If you do, you will lock yourself out after the flush takes place, and
574execution of
b7080c8e 575.Pa /etc/rc.firewall
7ba0088d
A
576will stop at this point - blocking all accesses permanently.
577Running the script in the background should be enough to prevent this
578disaster.
b7080c8e 579.El
b7080c8e 580.Sh SEE ALSO
b7080c8e 581.Xr divert 4 ,
7ba0088d
A
582.Xr protocols 5 ,
583.Xr rc.conf 5 ,
b7080c8e 584.Xr services 5 ,
7ba0088d
A
585.Xr syslog.conf 5 ,
586.Xr ipfw 8 ,
587.Xr ppp 8
b7080c8e
A
588.Sh AUTHORS
589This program is the result of the efforts of many people at different
590times:
7ba0088d 591.Pp
b7080c8e
A
592.An Archie Cobbs Aq archie@whistle.com
593(divert sockets)
7ba0088d 594.An Charles Mott Aq cmott@scientech.com
b7080c8e
A
595(packet aliasing)
596.An Eivind Eklund Aq perhaps@yes.no
597(IRC support & misc additions)
598.An Ari Suutari Aq suutari@iki.fi
599(natd)
600.An Dru Nelson Aq dnelson@redwoodsoft.com
7ba0088d 601(early PPTP support)
b7080c8e
A
602.An Brian Somers Aq brian@awfulhak.org
603(glue)
7ba0088d
A
604.An Ruslan Ermilov Aq ru@FreeBSD.org
605(natd, packet aliasing, glue)