1 .\" manual page [] for natd 1.4
2 .\" $Id: natd.8,v 1.6 2004/10/21 21:48:41 vazquez Exp $
8 .Nd Network Address Translation daemon
12 .Op Fl unregistered_only | u
16 .Op Fl deny_incoming | d
17 .Op Fl use_sockets | s
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
33 .Op Fl log_facility Ar facility_name
34 .Op Fl punch_fw Ar firewall_range
38 This program provides a Network Address Translation facility for use
46 normally runs in the background as a daemon.
47 It is passed raw IP packets as they travel into and out of the machine,
48 and will possibly change these before re-injecting them back into the
51 It changes all packets destined for another host so that their source
52 IP number is that of the current machine.
53 For each packet changed in this manner, an internal table entry is
54 created to record this fact.
55 The source port number is also changed to indicate the table entry
56 applying to the packet.
57 Packets that are received with a target IP of the current host are
58 checked against this internal table.
59 If an entry is found, it is used to determine the correct target IP
60 number and port to place in the packet.
62 The following command line options are available:
65 Log various aliasing statistics and information to the file
66 .Pa /var/log/alias.log .
67 This file is truncated each time
70 .It Fl deny_incoming | d
71 Do not pass incoming packets that have no
72 entry in the internal translation table.
74 If this option is not used, then such a packet will be altered
77 below, and the entry will be made in the internal translation table.
79 Log denied incoming packets via
85 .It Fl log_facility Ar facility_name
86 Use specified log facility when logging information via
90 is one of the keywords specified in
92 .It Fl use_sockets | s
95 in order to establish an FTP data or IRC DCC send connection.
96 This option uses more system resources, but guarantees successful
97 connections when port numbers conflict.
99 Try to keep the same port number when altering outgoing packets.
100 With this option, protocols such as RPC will have a better chance
102 If it is not possible to maintain the port number, it will be silently
103 changed as per normal.
107 on startup. Instead, stay attached to the controlling terminal and
108 display all packet alterations to the standard output. This option
109 should only be used for debugging purposes.
110 .It Fl unregistered_only | u
111 Only alter outgoing packets with an
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 .It Fl redirect_port Ar proto Xo
117 .Ar targetIP Ns : Ns Xo
118 .Ar targetPORT Ns Op - Ns Ar targetPORT Xc
119 .Op Ar aliasIP Ns : Ns Xo
120 .Ar aliasPORT Ns Op - Ns Ar aliasPORT Xc
121 .Oo Ar remoteIP Ns Oo : Ns
122 .Ar remotePORT Ns Op - Ns Ar remotePORT
125 Redirect incoming connections arriving to given port(s) to another host
134 is the desired target IP number,
136 is the desired target port number or range,
138 is the requested port number or range, and
140 is the aliasing address.
145 can be used to specify the connection more accurately if necessary.
150 range need not be the same numerically, but must have the same size.
153 is not specified, it is assumed to be all ports.
156 is specified, it must match the size of
159 For example, the argument
161 .Dl Ar tcp inside1:telnet 6666
163 means that incoming TCP packets destined for port 6666 on this machine
164 will be sent to the telnet port on the inside1 machine.
166 .Dl Ar tcp inside2:2300-2399 3300-3399
168 will redirect incoming connections on ports 3300-3399 to host
169 inside2, ports 2300-2399.
170 The mapping is 1:1 meaning port 3300 maps to 2300, 3301 maps to 2301, etc.
171 .It Fl redirect_proto Ar proto localIP Oo
172 .Ar publicIP Op Ar remoteIP
174 Redirect incoming IP packets of protocol
176 .Po see Xr protocols 5
182 address and vice versa.
186 is not specified, then the default aliasing address is used.
189 is specified, then only packets coming from/to
192 .It Fl redirect_address Ar localIP publicIP
193 Redirect traffic for public IP address to a machine on the local
195 This function is known as
197 Normally static NAT is useful if your ISP has allocated a small block
198 of IP addresses to you, but it can even be used in the case of single
201 .Dl Ar redirect_address 10.0.0.8 0.0.0.0
203 The above command would redirect all incoming traffic
206 If several address aliases specify the same public address
208 .Bd -literal -offset indent
209 .Ar redirect_address 192.168.0.2 public_addr
210 .Ar redirect_address 192.168.0.3 public_addr
211 .Ar redirect_address 192.168.0.4 public_addr
214 the incoming traffic will be directed to the last
215 translated local address (192.168.0.4), but outgoing
216 traffic from the first two addresses will still be aliased
217 to appear from the specified
219 .It Fl redirect_port Ar proto Xo
220 .Ar targetIP Ns : Ns Xo
221 .Ar targetPORT Ns Oo , Ns
222 .Ar targetIP Ns : Ns Xo
223 .Ar targetPORT Ns Oo , Ns
228 .Op Ar aliasIP Ns : Ns Xo
232 .Op : Ns Ar remotePORT
235 .It Fl redirect_address Xo
236 .Ar localIP Ns Oo , Ns
237 .Ar localIP Ns Oo , Ns
246 are used to transparently offload network load on a single server and
247 distribute the load across a pool of servers.
248 This function is known as
251 For example, the argument
253 .Dl Ar tcp www1:http,www2:http,www3:http www:http
255 means that incoming HTTP requests for host www will be transparently
256 redirected to one of the www1, www2 or www3, where a host is selected
257 simply on a round-robin basis, without regard to load on the net.
265 will monitor the routing socket for alterations to the
268 If the interface's IP number is changed,
270 will dynamically alter its concept of the alias address.
271 .It Fl in_port | i Ar port
272 Read from and write to
276 treating all packets as
278 .It Fl out_port | o Ar port
279 Read from and write to
283 treating all packets as
285 .It Fl port | p Ar port
286 Read from and write to
290 distinguishing packets as
294 using the rules specified in
298 is not numeric, it is searched for in the
301 If this option is not specified, the divert port named
303 will be used as a default.
304 .It Fl alias_address | a Ar address
307 as the aliasing address.
308 If this option is not specified, the
311 The specified address is usually the address assigned to the
317 will be rewritten with a source address equal to
321 will be checked to see if it matches any already-aliased outgoing
323 If it does, the packet is altered accordingly.
329 assignments are checked and actioned.
330 If no other action can be made and if
332 is not specified, the packet is delivered to the local machine
333 using the rules specified in
336 .It Fl t | target_address Ar address
337 Set the target address.
338 When an incoming packet not associated with any pre-existing link
339 arrives at the host machine, it will be sent to the specified
342 The target address may be set to
343 .Ar 255.255.255.255 ,
344 in which case all new incoming packets go to the alias address set by
349 If this option is not used, or called with the argument
351 then all new incoming packets go to the address specified in
353 This allows external machines to talk directly to internal machines if
354 they can route packets to the machine in question.
355 .It Fl interface | n Ar interface
358 to determine the aliasing address.
359 If there is a possibility that the IP number associated with
363 option should also be used.
364 If this option is not specified, the
375 .It Fl config | f Ar file
376 Read configuration from
380 should contain a list of options, one per line, in the same form
381 as the long form of the above command line options.
382 For example, the line
384 .Dl alias_address 158.152.17.1
386 would specify an alias address of 158.152.17.1.
387 Options that do not take an argument are specified with an argument of
391 in the configuration file. For example, the line
396 Trailing spaces and empty lines are ignored.
399 sign will mark the rest of the line as a comment.
403 reverse the way it handles
407 packets, allowing it to operate on the
409 network interface rather than the
413 This can be useful in some transparent proxying situations
414 when outgoing traffic is redirected to the local machine
417 is running on the internal interface (it usually runs on the
422 to perform transparent proxying only.
423 Normal address translation is not performed.
425 .Op Ar type encode_ip_hdr | encode_tcp_stream
427 .Ar server a.b.c.d:yyyy
429 Enable transparent proxying.
430 Outgoing TCP packets with the given port going through this
431 host to any other host are redirected to the given server and port.
432 Optionally, the original target address can be encoded into the packet.
435 to put this information into the IP option field or
436 .Ar encode_tcp_stream
437 to inject the data into the beginning of the TCP stream.
439 .Ar basenumber Ns : Ns Ar count
447 based firewall for FTP/IRC DCC connections.
448 This is done dynamically by installing temporary firewall rules which
449 allow a particular connection (and only that connection) to go through
451 The rules are removed once the corresponding connection terminates.
455 rules starting from the rule number
457 will be used for punching firewall holes.
458 The range will be cleared for all rules on startup.
461 This option enables MSS clamping. The MSS value is derived from the
462 MTU of the interface specified in the
467 The following steps are necessary before attempting to run
471 Build a custom kernel with the following options:
472 .Bd -literal -offset indent
477 Refer to the handbook for detailed instructions on building a custom
480 Ensure that your machine is acting as a gateway.
481 This can be done by specifying the line
483 .Dl gateway_enable=YES
487 file or using the command
489 .Dl sysctl -w net.inet.ip.forwarding=1
494 option, make sure that your interface is already configured.
495 If, for example, you wish to specify
501 on that interface, you must make sure that you start
509 is fairly straight forward.
512 .Dl natd -interface en0
514 should suffice in most cases (substituting the correct interface name).
517 on how to configure it to be started automatically during boot.
520 is running, you must ensure that traffic is diverted to
524 You will need to adjust the
527 If you are not interested in having a firewall, the
528 following lines will do:
529 .Bd -literal -offset indent
531 /sbin/ipfw add divert natd all from any to any via ed0
532 /sbin/ipfw add pass all from any to any
535 The second line depends on your interface (change
539 You should be aware of the fact that, with these firewall settings,
540 everyone on your local network can fake his source-address using your
542 If there are other hosts on your local network, you are strongly
543 encouraged to create firewall rules that only allow traffic to and
546 If you specify real firewall rules, it is best to specify line 2 at
547 the start of the script so that
549 sees all packets before they are dropped by the firewall.
553 packets re-enter the firewall at the rule number following the rule number
554 that caused the diversion (not the next rule if there are several at the
557 Enable your firewall by setting
559 .Dl firewall_enable=YES
563 This tells the system startup scripts to run the
566 If you do not wish to reboot now, just run this by hand from the console.
567 NEVER run this from a remote session unless you put it into the background.
568 If you do, you will lock yourself out after the flush takes place, and
571 will stop at this point - blocking all accesses permanently.
572 Running the script in the background should be enough to prevent this
584 This program is the result of the efforts of many people at different
587 .An Archie Cobbs Aq archie@whistle.com
589 .An Charles Mott Aq cmott@scientech.com
591 .An Eivind Eklund Aq perhaps@yes.no
592 (IRC support & misc additions)
593 .An Ari Suutari Aq suutari@iki.fi
595 .An Dru Nelson Aq dnelson@redwoodsoft.com
597 .An Brian Somers Aq brian@awfulhak.org
599 .An Ruslan Ermilov Aq ru@FreeBSD.org
600 (natd, packet aliasing, glue)