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
36 .Op Fl enable_natportmap
37 .Op Fl natportmap_interface Ar interface
40 This program provides a Network Address Translation facility for use
48 normally runs in the background as a daemon.
49 It is passed raw IP packets as they travel into and out of the machine,
50 and will possibly change these before re-injecting them back into the
53 It changes all packets destined for another host so that their source
54 IP number is that of the current machine.
55 For each packet changed in this manner, an internal table entry is
56 created to record this fact.
57 The source port number is also changed to indicate the table entry
58 applying to the packet.
59 Packets that are received with a target IP of the current host are
60 checked against this internal table.
61 If an entry is found, it is used to determine the correct target IP
62 number and port to place in the packet.
64 The following command line options are available:
67 Log various aliasing statistics and information to the file
68 .Pa /var/log/alias.log .
69 This file is truncated each time
72 .It Fl deny_incoming | d
73 Do not pass incoming packets that have no
74 entry in the internal translation table.
76 If this option is not used, then such a packet will be altered
79 below, and the entry will be made in the internal translation table.
81 Log denied incoming packets via
87 .It Fl log_facility Ar facility_name
88 Use specified log facility when logging information via
92 is one of the keywords specified in
94 .It Fl use_sockets | s
97 in order to establish an FTP data or IRC DCC send connection.
98 This option uses more system resources, but guarantees successful
99 connections when port numbers conflict.
100 .It Fl same_ports | m
101 Try to keep the same port number when altering outgoing packets.
102 With this option, protocols such as RPC will have a better chance
104 If it is not possible to maintain the port number, it will be silently
105 changed as per normal.
109 on startup. Instead, stay attached to the controlling terminal and
110 display all packet alterations to the standard output. This option
111 should only be used for debugging purposes.
112 .It Fl unregistered_only | u
113 Only alter outgoing packets with an
116 According to RFC 1918, unregistered source addresses are 10.0.0.0/8,
117 172.16.0.0/12 and 192.168.0.0/16.
118 .It Fl redirect_port Ar proto Xo
119 .Ar targetIP Ns : Ns Xo
120 .Ar targetPORT Ns Op - Ns Ar targetPORT Xc
121 .Op Ar aliasIP Ns : Ns Xo
122 .Ar aliasPORT Ns Op - Ns Ar aliasPORT Xc
123 .Oo Ar remoteIP Ns Oo : Ns
124 .Ar remotePORT Ns Op - Ns Ar remotePORT
127 Redirect incoming connections arriving to given port(s) to another host
136 is the desired target IP number,
138 is the desired target port number or range,
140 is the requested port number or range, and
142 is the aliasing address.
147 can be used to specify the connection more accurately if necessary.
152 range need not be the same numerically, but must have the same size.
155 is not specified, it is assumed to be all ports.
158 is specified, it must match the size of
161 For example, the argument
163 .Dl Ar tcp inside1:telnet 6666
165 means that incoming TCP packets destined for port 6666 on this machine
166 will be sent to the telnet port on the inside1 machine.
168 .Dl Ar tcp inside2:2300-2399 3300-3399
170 will redirect incoming connections on ports 3300-3399 to host
171 inside2, ports 2300-2399.
172 The mapping is 1:1 meaning port 3300 maps to 2300, 3301 maps to 2301, etc.
173 .It Fl redirect_proto Ar proto localIP Oo
174 .Ar publicIP Op Ar remoteIP
176 Redirect incoming IP packets of protocol
178 .Po see Xr protocols 5
184 address and vice versa.
188 is not specified, then the default aliasing address is used.
191 is specified, then only packets coming from/to
194 .It Fl redirect_address Ar localIP publicIP
195 Redirect traffic for public IP address to a machine on the local
197 This function is known as
199 Normally static NAT is useful if your ISP has allocated a small block
200 of IP addresses to you, but it can even be used in the case of single
203 .Dl Ar redirect_address 10.0.0.8 0.0.0.0
205 The above command would redirect all incoming traffic
208 If several address aliases specify the same public address
210 .Bd -literal -offset indent
211 .Ar redirect_address 192.168.0.2 public_addr
212 .Ar redirect_address 192.168.0.3 public_addr
213 .Ar redirect_address 192.168.0.4 public_addr
216 the incoming traffic will be directed to the last
217 translated local address (192.168.0.4), but outgoing
218 traffic from the first two addresses will still be aliased
219 to appear from the specified
221 .It Fl redirect_port Ar proto Xo
222 .Ar targetIP Ns : Ns Xo
223 .Ar targetPORT Ns Oo , Ns
224 .Ar targetIP Ns : Ns Xo
225 .Ar targetPORT Ns Oo , Ns
230 .Op Ar aliasIP Ns : Ns Xo
234 .Op : Ns Ar remotePORT
237 .It Fl redirect_address Xo
238 .Ar localIP Ns Oo , Ns
239 .Ar localIP Ns Oo , Ns
248 are used to transparently offload network load on a single server and
249 distribute the load across a pool of servers.
250 This function is known as
253 For example, the argument
255 .Dl Ar tcp www1:http,www2:http,www3:http www:http
257 means that incoming HTTP requests for host www will be transparently
258 redirected to one of the www1, www2 or www3, where a host is selected
259 simply on a round-robin basis, without regard to load on the net.
267 will monitor the routing socket for alterations to the
270 If the interface's IP number is changed,
272 will dynamically alter its concept of the alias address.
273 .It Fl in_port | i Ar port
274 Read from and write to
278 treating all packets as
280 .It Fl out_port | o Ar port
281 Read from and write to
285 treating all packets as
287 .It Fl port | p Ar port
288 Read from and write to
292 distinguishing packets as
296 using the rules specified in
300 is not numeric, it is searched for in the
303 If this option is not specified, the divert port named
305 will be used as a default.
306 .It Fl alias_address | a Ar address
309 as the aliasing address.
310 If this option is not specified, the
313 The specified address is usually the address assigned to the
319 will be rewritten with a source address equal to
323 will be checked to see if it matches any already-aliased outgoing
325 If it does, the packet is altered accordingly.
331 assignments are checked and actioned.
332 If no other action can be made and if
334 is not specified, the packet is delivered to the local machine
335 using the rules specified in
338 .It Fl t | target_address Ar address
339 Set the target address.
340 When an incoming packet not associated with any pre-existing link
341 arrives at the host machine, it will be sent to the specified
344 The target address may be set to
345 .Ar 255.255.255.255 ,
346 in which case all new incoming packets go to the alias address set by
351 If this option is not used, or called with the argument
353 then all new incoming packets go to the address specified in
355 This allows external machines to talk directly to internal machines if
356 they can route packets to the machine in question.
357 .It Fl interface | n Ar interface
360 to determine the aliasing address.
361 If there is a possibility that the IP number associated with
365 option should also be used.
366 If this option is not specified, the
377 .It Fl config | f Ar file
378 Read configuration from
382 should contain a list of options, one per line, in the same form
383 as the long form of the above command line options.
384 For example, the line
386 .Dl alias_address 158.152.17.1
388 would specify an alias address of 158.152.17.1.
389 Options that do not take an argument are specified with an argument of
393 in the configuration file. For example, the line
398 Trailing spaces and empty lines are ignored.
401 sign will mark the rest of the line as a comment.
405 reverse the way it handles
409 packets, allowing it to operate on the
411 network interface rather than the
415 This can be useful in some transparent proxying situations
416 when outgoing traffic is redirected to the local machine
419 is running on the internal interface (it usually runs on the
424 to perform transparent proxying only.
425 Normal address translation is not performed.
427 .Op Ar type encode_ip_hdr | encode_tcp_stream
429 .Ar server a.b.c.d:yyyy
431 Enable transparent proxying.
432 Outgoing TCP packets with the given port going through this
433 host to any other host are redirected to the given server and port.
434 Optionally, the original target address can be encoded into the packet.
437 to put this information into the IP option field or
438 .Ar encode_tcp_stream
439 to inject the data into the beginning of the TCP stream.
441 .Ar basenumber Ns : Ns Ar count
449 based firewall for FTP/IRC DCC connections.
450 This is done dynamically by installing temporary firewall rules which
451 allow a particular connection (and only that connection) to go through
453 The rules are removed once the corresponding connection terminates.
457 rules starting from the rule number
459 will be used for punching firewall holes.
460 The range will be cleared for all rules on startup.
463 This option enables MSS clamping. The MSS value is derived from the
464 MTU of the interface specified in the
467 .It Fl enable_natportmap Xo
469 This option enables port forwarding using the NATPMP protocol.
470 .It Fl natportmap_interface Ar interface Xo
472 This option instructs natd to listen for NATPMP requests. This option should appear for each
473 interface on which natd will listen for NATPMP requests.
476 The following steps are necessary before attempting to run
480 Ensure that your machine is acting as a gateway.
481 This can be done by using the command
483 .Dl sysctl -w net.inet.ip.forwarding=1
488 option, make sure that your interface is already configured.
489 If, for example, you wish to specify
495 on that interface, you must make sure that you start
503 is fairly straight forward.
506 .Dl natd -interface en0
508 should suffice in most cases (substituting the correct interface name).
512 is running, you must ensure that traffic is diverted to
516 If you are not interested in having a firewall, the
517 following lines will do:
518 .Bd -literal -offset indent
520 /sbin/ipfw add divert natd all from any to any via en0
521 /sbin/ipfw add pass all from any to any
524 The second line depends on your interface (change
528 You should be aware of the fact that, with these firewall settings,
529 everyone on your local network can fake his source-address using your
531 If there are other hosts on your local network, you are strongly
532 encouraged to create firewall rules that only allow traffic to and
535 If you specify real firewall rules, it is best to specify line 2 at
536 the start of the rules so that
538 sees all packets before they are dropped by the firewall.
542 packets re-enter the firewall at the rule number following the rule number
543 that caused the diversion (not the next rule if there are several at the
546 Enable your firewall by using the command
548 .Dl sysctl -w net.inet.ip.fw.enable=1
560 This program is the result of the efforts of many people at different
563 .An Archie Cobbs Aq archie@whistle.com
565 .An Charles Mott Aq cmott@scientech.com
567 .An Eivind Eklund Aq perhaps@yes.no
568 (IRC support & misc additions)
569 .An Ari Suutari Aq suutari@iki.fi
571 .An Dru Nelson Aq dnelson@redwoodsoft.com
573 .An Brian Somers Aq brian@awfulhak.org
575 .An Ruslan Ermilov Aq ru@FreeBSD.org
576 (natd, packet aliasing, glue)