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