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
39 utility provides a Network Address Translation facility for use
44 It is intended for use with NICs - if you want to do NAT on a PPP link,
52 utility normally runs in the background as a daemon.
53 It is passed raw IP packets as they travel into and out of the machine,
54 and will possibly change these before re-injecting them back into the
57 It changes all packets destined for another host so that their source
58 IP number is that of the current machine.
59 For each packet changed in this manner, an internal table entry is
60 created to record this fact.
61 The source port number is also changed to indicate the table entry
62 applying to the packet.
63 Packets that are received with a target IP of the current host are
64 checked against this internal table.
65 If an entry is found, it is used to determine the correct target IP
66 number and port to place in the packet.
68 The following command line options are available:
71 Log various aliasing statistics and information to the file
72 .Pa /var/log/alias.log .
73 This file is truncated each time
76 .It Fl deny_incoming | d
77 Do not pass incoming packets that have no
78 entry in the internal translation table.
80 If this option is not used, then such a packet will be altered
83 below, and the entry will be made in the internal translation table.
85 Log denied incoming packets via
89 .It Fl log_facility Ar facility_name
90 Use specified log facility when logging information via
94 is one of the keywords specified in
96 .It Fl use_sockets | s
99 in order to establish an FTP data or IRC DCC send connection.
100 This option uses more system resources, but guarantees successful
101 connections when port numbers conflict.
102 .It Fl same_ports | m
103 Try to keep the same port number when altering outgoing packets.
104 With this option, protocols such as RPC will have a better chance
106 If it is not possible to maintain the port number, it will be silently
107 changed as per normal.
112 Instead, stay attached to the controlling terminal and display all packet
113 alterations to the standard output.
114 This option should only be used for debugging purposes.
115 .It Fl unregistered_only | u
116 Only alter outgoing packets with an
119 According to RFC 1918, unregistered source addresses are 10.0.0.0/8,
120 172.16.0.0/12 and 192.168.0.0/16.
121 .It Fl redirect_port Ar proto Xo
122 .Ar targetIP Ns : Ns Xo
123 .Ar targetPORT Ns Op - Ns Ar targetPORT Xc
124 .Op Ar aliasIP Ns : Ns Xo
125 .Ar aliasPORT Ns Op - Ns Ar aliasPORT Xc
126 .Oo Ar remoteIP Ns Oo : Ns
127 .Ar remotePORT Ns Op - Ns Ar remotePORT
130 Redirect incoming connections arriving to given port(s) to another host
139 is the desired target IP number,
141 is the desired target port number or range,
143 is the requested port number or range, and
145 is the aliasing address.
150 can be used to specify the connection more accurately if necessary.
155 range need not be the same numerically, but must have the same size.
158 is not specified, it is assumed to be all ports.
161 is specified, it must match the size of
164 For example, the argument
166 .Dl Ar tcp inside1:telnet 6666
168 means that incoming TCP packets destined for port 6666 on this machine
169 will be sent to the telnet port on the inside1 machine.
171 .Dl Ar tcp inside2:2300-2399 3300-3399
173 will redirect incoming connections on ports 3300-3399 to host
174 inside2, ports 2300-2399.
175 The mapping is 1:1 meaning port 3300 maps to 2300, 3301 maps to 2301, etc.
176 .It Fl redirect_proto Ar proto localIP Oo
177 .Ar publicIP Op Ar remoteIP
179 Redirect incoming IP packets of protocol
187 address and vice versa.
191 is not specified, then the default aliasing address is used.
194 is specified, then only packets coming from/to
197 .It Fl redirect_address Ar localIP publicIP
198 Redirect traffic for public IP address to a machine on the local
200 This function is known as
202 Normally static NAT is useful if your ISP has allocated a small block
203 of IP addresses to you, but it can even be used in the case of single
206 .Dl Ar redirect_address 10.0.0.8 0.0.0.0
208 The above command would redirect all incoming traffic
211 If several address aliases specify the same public address
213 .Bd -literal -offset indent
214 .Ar redirect_address 192.168.0.2 public_addr
215 .Ar redirect_address 192.168.0.3 public_addr
216 .Ar redirect_address 192.168.0.4 public_addr
219 the incoming traffic will be directed to the last
220 translated local address (192.168.0.4), but outgoing
221 traffic from the first two addresses will still be aliased
222 to appear from the specified
224 .It Fl redirect_port Ar proto Xo
225 .Ar targetIP Ns : Ns Xo
226 .Ar targetPORT Ns Oo , Ns
227 .Ar targetIP Ns : Ns Xo
228 .Ar targetPORT Ns Oo , Ns
233 .Op Ar aliasIP Ns : Ns Xo
237 .Op : Ns Ar remotePORT
240 .It Fl redirect_address Xo
241 .Ar localIP Ns Oo , Ns
242 .Ar localIP Ns Oo , Ns
251 are used to transparently offload network load on a single server and
252 distribute the load across a pool of servers.
253 This function is known as
256 For example, the argument
258 .Dl Ar tcp www1:http,www2:http,www3:http www:http
260 means that incoming HTTP requests for host www will be transparently
261 redirected to one of the www1, www2 or www3, where a host is selected
262 simply on a round-robin basis, without regard to load on the net.
270 will monitor the routing socket for alterations to the
273 If the interface's IP number is changed,
275 will dynamically alter its concept of the alias address.
276 .It Fl in_port | i Ar port
277 Read from and write to
281 treating all packets as
283 .It Fl out_port | o Ar port
284 Read from and write to
288 treating all packets as
290 .It Fl port | p Ar port
291 Read from and write to
295 distinguishing packets as
299 using the rules specified in
303 is not numeric, it is searched for in the
306 If this option is not specified, the divert port named
308 will be used as a default.
309 .It Fl alias_address | a Ar address
312 as the aliasing address.
313 If this option is not specified, the
316 The specified address is usually the address assigned to the
322 will be rewritten with a source address equal to
326 will be checked to see if it matches any already-aliased outgoing
328 If it does, the packet is altered accordingly.
334 assignments are checked and actioned.
335 If no other action can be made and if
337 is not specified, the packet is delivered to the local machine
338 using the rules specified in
341 .It Fl t | target_address Ar address
342 Set the target address.
343 When an incoming packet not associated with any pre-existing link
344 arrives at the host machine, it will be sent to the specified
347 The target address may be set to
348 .Ar 255.255.255.255 ,
349 in which case all new incoming packets go to the alias address set by
354 If this option is not used, or called with the argument
356 then all new incoming packets go to the address specified in
358 This allows external machines to talk directly to internal machines if
359 they can route packets to the machine in question.
360 .It Fl interface | n Ar interface
363 to determine the aliasing address.
364 If there is a possibility that the IP number associated with
368 option should also be used.
369 If this option is not specified, the
380 .It Fl config | f Ar file
381 Read configuration from
385 should contain a list of options, one per line, in the same form
386 as the long form of the above command line options.
387 For example, the line
389 .Dl alias_address 158.152.17.1
391 would specify an alias address of 158.152.17.1.
392 Options that do not take an argument are specified with an argument of
396 in the configuration file.
397 For example, the line
404 Trailing spaces and empty lines are ignored.
407 sign will mark the rest of the line as a comment.
411 reverse the way it handles
415 packets, allowing it to operate on the
417 network interface rather than the
421 This can be useful in some transparent proxying situations
422 when outgoing traffic is redirected to the local machine
425 is running on the internal interface (it usually runs on the
430 to perform transparent proxying only.
431 Normal address translation is not performed.
433 .Op Ar type encode_ip_hdr | encode_tcp_stream
435 .Ar server a.b.c.d:yyyy
437 Enable transparent proxying.
438 Outgoing TCP packets with the given port going through this
439 host to any other host are redirected to the given server and port.
440 Optionally, the original target address can be encoded into the packet.
443 to put this information into the IP option field or
444 .Ar encode_tcp_stream
445 to inject the data into the beginning of the TCP stream.
447 .Ar basenumber Ns : Ns Ar count
455 based firewall for FTP/IRC DCC connections.
456 This is done dynamically by installing temporary firewall rules which
457 allow a particular connection (and only that connection) to go through
459 The rules are removed once the corresponding connection terminates.
463 rules starting from the rule number
465 will be used for punching firewall holes.
466 The range will be cleared for all rules on startup.
467 .It Fl log_ipfw_denied
468 Log when a packet cannot be re-injected because an
471 This is the default with
475 The following steps are necessary before attempting to run
479 Build a custom kernel with the following options:
480 .Bd -literal -offset indent
485 Refer to the handbook for detailed instructions on building a custom
488 Ensure that your machine is acting as a gateway.
489 This can be done by specifying the line
491 .Dl gateway_enable=YES
495 file or using the command
497 .Dl "sysctl net.inet.ip.forwarding=1"
502 option, make sure that your interface is already configured.
503 If, for example, you wish to specify
509 on that interface, you must make sure that you start
517 is fairly straight forward.
520 .Dl natd -interface ed0
522 should suffice in most cases (substituting the correct interface name).
525 on how to configure it to be started automatically during boot.
528 is running, you must ensure that traffic is diverted to
532 You will need to adjust the
535 If you are not interested in having a firewall, the
536 following lines will do:
537 .Bd -literal -offset indent
539 /sbin/ipfw add divert natd all from any to any via ed0
540 /sbin/ipfw add pass all from any to any
543 The second line depends on your interface (change
547 You should be aware of the fact that, with these firewall settings,
548 everyone on your local network can fake his source-address using your
550 If there are other hosts on your local network, you are strongly
551 encouraged to create firewall rules that only allow traffic to and
554 If you specify real firewall rules, it is best to specify line 2 at
555 the start of the script so that
557 sees all packets before they are dropped by the firewall.
561 packets re-enter the firewall at the rule number following the rule number
562 that caused the diversion (not the next rule if there are several at the
565 Enable your firewall by setting
567 .Dl firewall_enable=YES
571 This tells the system startup scripts to run the
574 If you do not wish to reboot now, just run this by hand from the console.
575 NEVER run this from a remote session unless you put it into the background.
576 If you do, you will lock yourself out after the flush takes place, and
579 will stop at this point - blocking all accesses permanently.
580 Running the script in the background should be enough to prevent this
592 This program is the result of the efforts of many people at different
595 .An Archie Cobbs Aq archie@FreeBSD.org
597 .An Charles Mott Aq cmott@scientech.com
599 .An Eivind Eklund Aq perhaps@yes.no
600 (IRC support & misc additions)
601 .An Ari Suutari Aq suutari@iki.fi
603 .An Dru Nelson Aq dnelson@redwoodsoft.com
605 .An Brian Somers Aq brian@awfulhak.org
607 .An Ruslan Ermilov Aq ru@FreeBSD.org
608 (natd, packet aliasing, glue)