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