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 skinny_port Ar port
35 .Op Fl log_ipfw_denied
36 .Op Fl pid_file | P Ar pidfile
41 utility provides a Network Address Translation facility for use
47 (If you need NAT on a PPP link,
51 option that gives most of the
53 functionality, and uses the same
59 utility normally runs in the background as a daemon.
60 It is passed raw IP packets as they travel into and out of the machine,
61 and will possibly change these before re-injecting them back into the
64 It changes all packets destined for another host so that their source
65 IP address is that of the current machine.
66 For each packet changed in this manner, an internal table entry is
67 created to record this fact.
68 The source port number is also changed to indicate the table entry
69 applying to the packet.
70 Packets that are received with a target IP of the current host are
71 checked against this internal table.
72 If an entry is found, it is used to determine the correct target IP
73 address and port to place in the packet.
75 The following command line options are available:
78 Log various aliasing statistics and information to the file
79 .Pa /var/log/alias.log .
80 This file is truncated each time
83 .It Fl deny_incoming | d
84 Do not pass incoming packets that have no
85 entry in the internal translation table.
87 If this option is not used, then such a packet will be altered
90 below, and the entry will be made in the internal translation table.
92 Log denied incoming packets via
96 .It Fl log_facility Ar facility_name
97 Use specified log facility when logging information via
101 is one of the keywords specified in
103 .It Fl use_sockets | s
106 in order to establish an FTP data or IRC DCC send connection.
107 This option uses more system resources, but guarantees successful
108 connections when port numbers conflict.
109 .It Fl same_ports | m
110 Try to keep the same port number when altering outgoing packets.
111 With this option, protocols such as RPC will have a better chance
113 If it is not possible to maintain the port number, it will be silently
114 changed as per normal.
119 Instead, stay attached to the controlling terminal and display all packet
120 alterations to the standard output.
121 This option should only be used for debugging purposes.
122 .It Fl unregistered_only | u
123 Only alter outgoing packets with an
126 According to RFC 1918, unregistered source addresses are 10.0.0.0/8,
127 172.16.0.0/12 and 192.168.0.0/16.
128 .It Fl redirect_port Ar proto Xo
129 .Ar targetIP Ns : Ns Xo
130 .Ar targetPORT Ns Op - Ns Ar targetPORT Xc
131 .Op Ar aliasIP Ns : Ns Xo
132 .Ar aliasPORT Ns Op - Ns Ar aliasPORT Xc
133 .Oo Ar remoteIP Ns Oo : Ns
134 .Ar remotePORT Ns Op - Ns Ar remotePORT
137 Redirect incoming connections arriving to given port(s) to another host
146 is the desired target IP address,
148 is the desired target port number or range,
150 is the requested port number or range, and
152 is the aliasing address.
157 can be used to specify the connection more accurately if necessary.
160 is not specified, it is assumed to be all ports.
163 .Ar targetIP , aliasIP
166 can be given as IP addresses or as hostnames.
168 .Ar targetPORT , aliasPORT
171 ranges need not be the same numerically, but must have the same size.
173 .Ar targetPORT , aliasPORT
176 specifies a singular value (not a range), it can be given as a service
177 name that is searched for in the
181 For example, the argument
183 .Dl Ar tcp inside1:telnet 6666
185 means that incoming TCP packets destined for port 6666 on this machine
186 will be sent to the telnet port on the inside1 machine.
188 .Dl Ar tcp inside2:2300-2399 3300-3399
190 will redirect incoming connections on ports 3300-3399 to host
191 inside2, ports 2300-2399.
192 The mapping is 1:1 meaning port 3300 maps to 2300, 3301 maps to 2301, etc.
193 .It Fl redirect_proto Ar proto localIP Oo
194 .Ar publicIP Op Ar remoteIP
196 Redirect incoming IP packets of protocol
204 address and vice versa.
208 is not specified, then the default aliasing address is used.
211 is specified, then only packets coming from/to
214 .It Fl redirect_address Ar localIP publicIP
215 Redirect traffic for public IP address to a machine on the local
217 This function is known as
219 Normally static NAT is useful if your ISP has allocated a small block
220 of IP addresses to you, but it can even be used in the case of single
223 .Dl Ar redirect_address 10.0.0.8 0.0.0.0
225 The above command would redirect all incoming traffic
228 If several address aliases specify the same public address
230 .Bd -literal -offset indent
231 redirect_address 192.168.0.2 public_addr
232 redirect_address 192.168.0.3 public_addr
233 redirect_address 192.168.0.4 public_addr
236 the incoming traffic will be directed to the last
237 translated local address (192.168.0.4), but outgoing
238 traffic from the first two addresses will still be aliased
239 to appear from the specified
241 .It Fl redirect_port Ar proto Xo
242 .Ar targetIP Ns : Ns Xo
243 .Ar targetPORT Ns Oo , Ns
244 .Ar targetIP Ns : Ns Xo
245 .Ar targetPORT Ns Oo , Ns
250 .Op Ar aliasIP Ns : Ns Xo
254 .Op : Ns Ar remotePORT
257 .It Fl redirect_address Xo
258 .Ar localIP Ns Oo , Ns
259 .Ar localIP Ns Oo , Ns
268 are used to transparently offload network load on a single server and
269 distribute the load across a pool of servers.
270 This function is known as
273 For example, the argument
275 .Dl Ar tcp www1:http,www2:http,www3:http www:http
277 means that incoming HTTP requests for host www will be transparently
278 redirected to one of the www1, www2 or www3, where a host is selected
279 simply on a round-robin basis, without regard to load on the net.
287 will monitor the routing socket for alterations to the
290 If the interface's IP address is changed,
292 will dynamically alter its concept of the alias address.
293 .It Fl in_port | i Ar port
294 Read from and write to
298 treating all packets as
300 .It Fl out_port | o Ar port
301 Read from and write to
305 treating all packets as
307 .It Fl port | p Ar port
308 Read from and write to
312 distinguishing packets as
316 using the rules specified in
320 is not numeric, it is searched for in the
323 If this option is not specified, the divert port named
325 will be used as a default.
326 .It Fl alias_address | a Ar address
329 as the aliasing address.
332 option must be used (but not both),
335 option is not specified.
336 The specified address is usually the address assigned to the
342 will be rewritten with a source address equal to
346 will be checked to see if it matches any already-aliased outgoing
348 If it does, the packet is altered accordingly.
354 assignments are checked and actioned.
355 If no other action can be made and if
357 is not specified, the packet is delivered to the local machine
358 using the rules specified in
361 .It Fl t | target_address Ar address
362 Set the target address.
363 When an incoming packet not associated with any pre-existing link
364 arrives at the host machine, it will be sent to the specified
367 The target address may be set to
368 .Ar 255.255.255.255 ,
369 in which case all new incoming packets go to the alias address set by
374 If this option is not used, or called with the argument
376 then all new incoming packets go to the address specified in
378 This allows external machines to talk directly to internal machines if
379 they can route packets to the machine in question.
380 .It Fl interface | n Ar interface
383 to determine the aliasing address.
384 If there is a possibility that the IP address associated with
388 option should also be used.
389 If this option is not specified, the
400 .It Fl config | f Ar file
401 Read configuration from
405 should contain a list of options, one per line, in the same form
406 as the long form of the above command line options.
407 For example, the line
409 .Dl alias_address 158.152.17.1
411 would specify an alias address of 158.152.17.1.
412 Options that do not take an argument are specified with an argument of
416 in the configuration file.
417 For example, the line
424 Options can be divided to several sections.
425 Each section applies to own
428 This ability allows to configure one
430 process for several NAT instances.
431 The first instance that always exists is a "default" instance.
432 Each another instance should begin with
434 .Dl instance Ar instance_name
436 At the next should be placed a configuration option.
439 .Dl \&# default instance
441 .Dl alias_address 158.152.17.1
443 .Dl \&# second instance
446 .Dl alias_address 192.168.0.1
448 Trailing spaces and empty lines are ignored.
451 sign will mark the rest of the line as a comment.
455 reverse the way it handles
459 packets, allowing it to operate on the
461 network interface rather than the
465 This can be useful in some transparent proxying situations
466 when outgoing traffic is redirected to the local machine
469 is running on the internal interface (it usually runs on the
474 to perform transparent proxying only.
475 Normal address translation is not performed.
477 .Op Ar type encode_ip_hdr | encode_tcp_stream
479 .Ar server a.b.c.d:yyyy
481 Enable transparent proxying.
482 Outgoing TCP packets with the given port going through this
483 host to any other host are redirected to the given server and port.
484 Optionally, the original target address can be encoded into the packet.
487 to put this information into the IP option field or
488 .Ar encode_tcp_stream
489 to inject the data into the beginning of the TCP stream.
491 .Ar basenumber Ns : Ns Ar count
499 based firewall for FTP/IRC DCC connections.
500 This is done dynamically by installing temporary firewall rules which
501 allow a particular connection (and only that connection) to go through
503 The rules are removed once the corresponding connection terminates.
507 rules starting from the rule number
509 will be used for punching firewall holes.
510 The range will be cleared for all rules on startup.
511 This option has no effect when the kernel is in security
514 for more information.
515 .It Fl skinny_port Ar port
516 This option allows you to specify the TCP port used for
517 the Skinny Station protocol.
518 Skinny is used by Cisco IP phones to communicate with
519 Cisco Call Managers to set up voice over IP calls.
520 By default, Skinny aliasing is not performed.
521 The typical port value for Skinny is 2000.
522 .It Fl log_ipfw_denied
523 Log when a packet cannot be re-injected because an
526 This is the default with
528 .It Fl pid_file | P Ar file
529 Specify an alternate file in which to store the process ID.
531 .Pa /var/run/natd.pid .
534 The following steps are necessary before attempting to run
538 Build a custom kernel with the following options:
539 .Bd -literal -offset indent
544 Refer to the handbook for detailed instructions on building a custom
547 Ensure that your machine is acting as a gateway.
548 This can be done by specifying the line
550 .Dl gateway_enable=YES
554 file or using the command
556 .Dl "sysctl net.inet.ip.forwarding=1"
561 option, make sure that your interface is already configured.
562 If, for example, you wish to specify
568 on that interface, you must make sure that you start
576 is fairly straight forward.
579 .Dl natd -interface ed0
581 should suffice in most cases (substituting the correct interface name).
584 on how to configure it to be started automatically during boot.
587 is running, you must ensure that traffic is diverted to
591 You will need to adjust the
594 If you are not interested in having a firewall, the
595 following lines will do:
596 .Bd -literal -offset indent
598 /sbin/ipfw add divert natd all from any to any via ed0
599 /sbin/ipfw add pass all from any to any
602 The second line depends on your interface (change
606 You should be aware of the fact that, with these firewall settings,
607 everyone on your local network can fake his source-address using your
609 If there are other hosts on your local network, you are strongly
610 encouraged to create firewall rules that only allow traffic to and
613 If you specify real firewall rules, it is best to specify line 2 at
614 the start of the script so that
616 sees all packets before they are dropped by the firewall.
620 packets re-enter the firewall at the rule number following the rule number
621 that caused the diversion (not the next rule if there are several at the
624 Enable your firewall by setting
626 .Dl firewall_enable=YES
630 This tells the system startup scripts to run the
633 If you do not wish to reboot now, just run this by hand from the console.
634 NEVER run this from a remote session unless you put it into the background.
635 If you do, you will lock yourself out after the flush takes place, and
638 will stop at this point - blocking all accesses permanently.
639 Running the script in the background should be enough to prevent this
653 This program is the result of the efforts of many people at different
656 .An Archie Cobbs Aq archie@FreeBSD.org
658 .An Charles Mott Aq cm@linktel.net
660 .An Eivind Eklund Aq perhaps@yes.no
661 (IRC support & misc additions)
662 .An Ari Suutari Aq suutari@iki.fi
664 .An Dru Nelson Aq dnelson@redwoodsoft.com
666 .An Brian Somers Aq brian@awfulhak.org
668 .An Ruslan Ermilov Aq ru@FreeBSD.org
669 (natd, packet aliasing, glue)