1 .\" $FreeBSD: src/sbin/natd/natd.8,v 1.27.2.13 2003/02/23 21:17:43 trhodes Exp $
7 .Nd Network Address Translation daemon
11 .Op Fl unregistered_only | u
15 .Op Fl deny_incoming | d
16 .Op Fl use_sockets | s
20 .Op Fl in_port | i Ar port
21 .Op Fl out_port | o Ar port
22 .Op Fl port | p Ar port
23 .Op Fl alias_address | a Ar address
24 .Op Fl target_address | t Ar address
25 .Op Fl interface | n Ar interface
26 .Op Fl proxy_rule Ar proxyspec
27 .Op Fl redirect_port Ar linkspec
28 .Op Fl redirect_proto Ar linkspec
29 .Op Fl redirect_address Ar linkspec
30 .Op Fl config | f Ar configfile
32 .Op Fl log_facility Ar facility_name
33 .Op Fl punch_fw Ar firewall_range
34 .Op Fl log_ipfw_denied
35 .Op Fl exit_delay | P Ar ms
40 utility provides a Network Address Translation facility for use
45 It is intended for use with NICs - if you want to do NAT on a PPP link,
53 utility normally runs in the background as a daemon.
54 It is passed raw IP packets as they travel into and out of the machine,
55 and will possibly change these before re-injecting them back into the
58 It changes all packets destined for another host so that their source
59 IP number is that of the current machine.
60 For each packet changed in this manner, an internal table entry is
61 created to record this fact.
62 The source port number is also changed to indicate the table entry
63 applying to the packet.
64 Packets that are received with a target IP of the current host are
65 checked against this internal table.
66 If an entry is found, it is used to determine the correct target IP
67 number and port to place in the packet.
69 The following command line options are available:
72 Log various aliasing statistics and information to the file
73 .Pa /var/log/alias.log .
74 This file is truncated each time
77 .It Fl deny_incoming | d
78 Do not pass incoming packets that have no
79 entry in the internal translation table.
81 If this option is not used, then such a packet will be altered
84 below, and the entry will be made in the internal translation table.
86 Log denied incoming packets via
90 .It Fl log_facility Ar facility_name
91 Use specified log facility when logging information via
95 is one of the keywords specified in
97 .It Fl use_sockets | s
100 in order to establish an FTP data or IRC DCC send connection.
101 This option uses more system resources, but guarantees successful
102 connections when port numbers conflict.
103 .It Fl same_ports | m
104 Try to keep the same port number when altering outgoing packets.
105 With this option, protocols such as RPC will have a better chance
107 If it is not possible to maintain the port number, it will be silently
108 changed as per normal.
113 Instead, stay attached to the controlling terminal and display all packet
114 alterations to the standard output.
115 This option should only be used for debugging purposes.
116 .It Fl unregistered_only | u
117 Only alter outgoing packets with an
120 According to RFC 1918, unregistered source addresses are 10.0.0.0/8,
121 172.16.0.0/12 and 192.168.0.0/16.
122 .It Fl redirect_port Ar proto Xo
123 .Ar targetIP Ns : Ns Ar targetPORT Ns Op \- Ns Ar targetPORT
124 .Op Ar aliasIP Ns : Ns Ar aliasPORT Ns Op \- Ns Ar aliasPORT
125 .Op Ar remoteIP Ns Op : Ns 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
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_address Xo
222 .Ar localIP Ns Oo , Ns
223 .Ar localIP Ns Oo , Ns
232 are used to transparently offload network load on a single server and
233 distribute the load across a pool of servers.
234 This function is known as
237 For example, the argument
239 .Dl Ar tcp www1:http,www2:http,www3:http www:http
241 means that incoming HTTP requests for host www will be transparently
242 redirected to one of the www1, www2 or www3, where a host is selected
243 simply on a round-robin basis, without regard to load on the net.
251 will monitor the routing socket for alterations to the
254 If the interface's IP number is changed,
256 will dynamically alter its concept of the alias address.
257 .It Fl in_port | i Ar port
258 Read from and write to
262 treating all packets as
264 .It Fl out_port | o Ar port
265 Read from and write to
269 treating all packets as
271 .It Fl port | p Ar port
272 Read from and write to
276 distinguishing packets as
280 using the rules specified in
284 is not numeric, it is searched for in the
287 If this option is not specified, the divert port named
289 will be used as a default.
290 .It Fl alias_address | a Ar address
293 as the aliasing address.
294 If this option is not specified, the
297 The specified address is usually the address assigned to the
303 will be rewritten with a source address equal to
307 will be checked to see if it matches any already-aliased outgoing
309 If it does, the packet is altered accordingly.
315 assignments are checked and actioned.
316 If no other action can be made and if
318 is not specified, the packet is delivered to the local machine
319 using the rules specified in
322 .It Fl t | target_address Ar address
323 Set the target address.
324 When an incoming packet not associated with any pre-existing link
325 arrives at the host machine, it will be sent to the specified
328 The target address may be set to
329 .Ar 255.255.255.255 ,
330 in which case all new incoming packets go to the alias address set by
335 If this option is not used, or called with the argument
337 then all new incoming packets go to the address specified in
339 This allows external machines to talk directly to internal machines if
340 they can route packets to the machine in question.
341 .It Fl interface | n Ar interface
344 to determine the aliasing address.
345 If there is a possibility that the IP number associated with
349 option should also be used.
350 If this option is not specified, the
361 .It Fl config | f Ar file
362 Read configuration from
366 should contain a list of options, one per line, in the same form
367 as the long form of the above command line options.
368 For example, the line
370 .Dl alias_address 158.152.17.1
372 would specify an alias address of 158.152.17.1.
373 Options that do not take an argument are specified with an argument of
377 in the configuration file.
378 For example, the line
385 Trailing spaces and empty lines are ignored.
388 sign will mark the rest of the line as a comment.
392 reverse the way it handles
396 packets, allowing it to operate on the
398 network interface rather than the
402 This can be useful in some transparent proxying situations
403 when outgoing traffic is redirected to the local machine
406 is running on the internal interface (it usually runs on the
411 to perform transparent proxying only.
412 Normal address translation is not performed.
414 .Op Ar type encode_ip_hdr | encode_tcp_stream
416 .Ar server a.b.c.d:yyyy
418 Enable transparent proxying.
419 Outgoing TCP packets with the given port going through this
420 host to any other host are redirected to the given server and port.
421 Optionally, the original target address can be encoded into the packet.
424 to put this information into the IP option field or
425 .Ar encode_tcp_stream
426 to inject the data into the beginning of the TCP stream.
428 .Ar basenumber Ns : Ns Ar count
436 based firewall for FTP/IRC DCC connections.
437 This is done dynamically by installing temporary firewall rules which
438 allow a particular connection (and only that connection) to go through
440 The rules are removed once the corresponding connection terminates.
444 rules starting from the rule number
446 will be used for punching firewall holes.
447 The range will be cleared for all rules on startup.
448 .It Fl log_ipfw_denied
449 Log when a packet cannot be re-injected because an
452 This is the default with
454 .It Fl exit_delay Ar ms
455 Specify delay in ms before daemon exit after signal.
460 The following steps are necessary before attempting to run
464 Build a custom kernel with the following options:
465 .Bd -literal -offset indent
470 Refer to the handbook for detailed instructions on building a custom
473 Ensure that your machine is acting as a gateway.
474 This can be done by specifying the line
476 .Dl gateway_enable=YES
480 file or using the command
482 .Dl "sysctl net.inet.ip.forwarding=1"
486 option, make sure that your interface is already configured.
487 If, for example, you wish to specify
493 on that interface, you must make sure that you start
501 is fairly straight forward.
504 .Dl natd -interface ed0
506 should suffice in most cases (substituting the correct interface name).
509 on how to configure it to be started automatically during boot.
512 is running, you must ensure that traffic is diverted to
516 You will need to adjust the
519 If you are not interested in having a firewall, the
520 following lines will do:
521 .Bd -literal -offset indent
523 /sbin/ipfw add divert natd all from any to any via ed0
524 /sbin/ipfw add pass all from any to any
527 The second line depends on your interface (change
531 You should be aware of the fact that, with these firewall settings,
532 everyone on your local network can fake his source-address using your
534 If there are other hosts on your local network, you are strongly
535 encouraged to create firewall rules that only allow traffic to and
538 If you specify real firewall rules, it is best to specify line 2 at
539 the start of the script so that
541 sees all packets before they are dropped by the firewall.
545 packets re-enter the firewall at the rule number following the rule number
546 that caused the diversion (not the next rule if there are several at the
549 Enable your firewall by setting
551 .Dl firewall_enable=YES
555 This tells the system startup scripts to run the
558 If you do not wish to reboot now, just run this by hand from the console.
559 NEVER run this from a remote session unless you put it into the background.
560 If you do, you will lock yourself out after the flush takes place, and
563 will stop at this point - blocking all accesses permanently.
564 Running the script in the background should be enough to prevent this
581 This program is the result of the efforts of many people at different
584 .An Archie Cobbs Aq Mt archie@FreeBSD.org
586 .An Charles Mott Aq Mt cmott@scientech.com
588 .An Eivind Eklund Aq Mt perhaps@yes.no
589 (IRC support & misc additions)
590 .An Ari Suutari Aq Mt suutari@iki.fi
592 .An Dru Nelson Aq Mt dnelson@redwoodsoft.com
594 .An Brian Somers Aq Mt brian@awfulhak.org
596 .An Ruslan Ermilov Aq Mt ru@FreeBSD.org
597 (natd, packet aliasing, glue)