xref: /freebsd/sbin/natd/natd.8 (revision bf5cbf35513d811c5829f8756a46eeb017a0a39b)
1.\" manual page [] for natd 1.4
2.Dd 15 April 1997
3.Os FreeBSD
4.Dt NATD 8
5.Sh NAME
6.Nm natd
7.Nd
8Network Address Translation Daemon
9.Sh SYNOPSIS
10.Nm
11.Op Fl ldsmvu
12.Op Fl permanent_link
13.Op Fl dynamic
14.Op Fl i Ar inport
15.Op Fl o Ar outport
16.Op Fl p Ar port
17.Op Fl a Ar address
18.Op Fl i Ar interface
19.Op Fl f Ar configfile
20
21.Nm
22.Op Fl log
23.Op Fl deny_incoming
24.Op Fl use_sockets
25.Op Fl same_ports
26.Op Fl verbose
27.Op Fl unregistered_only
28.Op Fl permanent_link
29.Op Fl dynamic
30.Op Fl inport Ar inport
31.Op Fl outport Ar outport
32.Op Fl port Ar port
33.Op Fl alias_address Ar address
34.Op Fl interface Ar interface
35.Op Fl config Ar configfile
36
37.Sh DESCRIPTION
38This program provides a Network Address Translation facility for use
39with
40.Xr divert 4
41sockets under FreeBSD.  Most of the command line options are available
42in a single character short form or in a long form.  Use of the long
43form is encouraged as it makes things clearer to the casual observer.
44
45.Pp
46.Nm Natd
47normally runs in the background as a daemon.  It is passed raw IP packets
48as they travel into and out of the machine, and will possibly change these
49before re-injecting them back into the IP packet stream.
50
51.Pp
52.Nm Natd
53changes all packets destined for another host so that their source
54IP number is that of the current machine.  For each packet changed
55in this manner, an internal table entry is created to record this
56fact.  The source port number is also changed to indicate the
57table entry applying to the packet.  Packets that are received with
58a target IP of the current host are checked against this internal
59table.  If an entry is found, it is used to determine the correct
60target IP number and port to place in the packet.
61
62.Pp
63The following command line options are available.
64.Bl -tag -width Fl
65
66.It Fl log | l
67Log various aliasing statistics and information to the file
68.Pa /var/log/alias.log .
69This file is truncated each time natd is started.
70
71.It Fl deny_incoming | d
72Reject packets destined for the current IP number that have no entry
73in the internal translation table.
74
75.It Fl use_sockets | s
76Allocate a
77.Xr socket 2
78in order to establish an FTP data or IRC DCC send connection.  This
79option uses more system resources, but guarantees successful connections
80when port numbers conflict.
81
82.It Fl same_ports | m
83Try to keep the same port number when altering outgoing packets.
84With this option, protocols such as RPC will have a better chance
85of working.  If it is not possible to maintain the port number, it
86will be silently changed as per normal.
87
88.It Fl verbose | v
89Don't call
90.Xr fork 2
91or
92.Xr daemon 3
93on startup.  Instead, stay attached to the controling terminal and
94display all packet alterations to the standard output.  This option
95should only be used for debugging purposes.
96
97.It Fl unregistered_only | u
98Only alter outgoing packets with an unregistered source address.
99According to rfc 1918, unregistered source addresses are 10.0.0.0/8,
100172.16.0.0/12 and 192.168.0.0/16.
101
102.It Fl redirect_port Ar linkspec
103Redirect incoming connections arriving to given port to another host and port.
104Linkspec is of the form
105
106  proto targetIP:targetPORT [aliasIP:]aliasPORT [remoteIP[:remotePORT]]
107
108where proto is either tcp or udp, targetIP is the desired target IP
109number, targetPORT is the desired target PORT number, aliasPORT
110is the requested PORT number and aliasIP is the aliasing address.
111RemoteIP and remotePORT can be used to specify the connection
112more accurately if necessary.
113For example, the argument
114
115.Ar tcp inside1:telnet 6666
116
117means that tcp packets destined for port 6666 on this machine will
118be sent to the telnet port on the inside1 machine.
119
120.It Fl redirect_address Ar localIP publicIP
121Redirect traffic for public IP address to a machine on the local
122network. This function is known as "static NAT". Normally static NAT
123is useful if your ISP has allocated a small block of IP addresses to you,
124but it can even be used in the case of single address:
125
126  redirect_address 10.0.0.8 0.0.0.0
127
128The above command would redirect all incoming traffic
129to machine 10.0.0.8.
130
131If several address aliases specify the same public address
132as follows
133
134  redirect_address 192.168.0.2 public_addr
135  redirect_address 192.168.0.3 public_addr
136  redirect_address 192.168.0.4 public_addr
137
138the incoming traffic will be directed to the last
139translated local address (192.168.0.4), but outgoing
140traffic to the first two addresses will still be aliased
141to specified public address.
142
143.It Fl permanent_link Ar linkspec
144Create a permanent entry in the internal alias table. Linkspec is
145of the form
146
147  proto targetIP:targetPORT sourceIP:sourcePORT aliasPORT
148
149where proto is either tcp or udp, targetIP is the desired target IP
150number, targetPORT is the desired target PORT number, sourceIP and
151sourcePORT match the incoming packet, and aliasPORT is the requested
152PORT number.  Values of zero are considered as wildcards.  For example,
153the argument
154
155.Ar tcp inside1:telnet outside1:0 6666
156
157means that tcp packets destined for port 6666 on this machine from the
158outside1 machine (any port) will be sent to the telnet port on the
159inside1 machine.
160
161New installations are encouraged to use redirect_port instead.
162
163.It Fl dynamic
164If the
165.Fl n
166or
167.Fl interface
168option is used,
169.Nm natd
170will monitor the routing socket for alterations to the
171.Ar interface
172passed.  If the interfaces IP number is changed,
173.Nm natd
174will dynamically alter its concept of the alias address.
175
176.It Fl i | inport Ar inport
177Read from and write to
178.Ar inport ,
179treating all packets as packets coming into the machine.
180
181.It Fl o | outport Ar outport
182Read from and write to
183.Ar outport ,
184treating all packets as packets going out of the machine.
185
186.It Fl p | port Ar port
187Read from and write to
188.Ar port ,
189distinguishing packets as incoming our outgoing using the rules specified in
190.Xr divert 4 .
191If
192.Ar port
193is not numeric, it is searched for in the
194.Pa /etc/services
195database using the
196.Xr getservbyname 3
197function.  If this flag is not specified, the divert port named natd will
198be used as a default.  An example entry in the
199.Pa /etc/services
200database would be:
201
202  natd   6668/divert  # Network Address Translation socket
203
204Refer to
205.Xr services 5
206for further details.
207
208.It Fl a | alias_address Ar address
209Use
210.Ar address
211as the alias address.  If this option is not specified, the
212.Fl n
213or
214.Fl interface
215option must be used.
216
217.It Fl n | interface Ar interface
218Use
219.Ar interface
220to determine the alias address.  If there is a possibility that the
221IP number associated with
222.Ar interface
223may change, the
224.Fl dynamic
225flag should also be used.  If this option is not specified, the
226.Fl a
227or
228.Fl alias_address
229flag must be used.
230
231.It Fl f | config Ar configfile
232Read configuration from
233.Ar configfile .
234.Ar Configfile
235contains a list of options, one per line in the same form as the
236long form of the above command line flags.  For example, the line
237
238  alias_address 158.152.17.1
239
240would specify an alias address of 158.152.17.1.  Options that don't
241take an argument are specified with an option of
242.Ar yes
243or
244.Ar no
245in the configuration file.  For example, the line
246
247  log yes
248
249is synonomous with
250.Fl log .
251Empty lines and lines beginning with '#' are ignored.
252
253.El
254
255.Sh RUNNING NATD
256The following steps are necessary before attempting to run
257.Nm natd :
258
259.Bl -enum
260.It
261Get FreeBSD version 2.2 or higher.  Versions before this do not support
262.Xr divert 4
263sockets.
264
265.It
266Build a custom kernel with the following options:
267
268  options IPFIREWALL
269  options IPDIVERT
270
271Refer to the handbook for detailed instructions on building a custom
272kernel.
273
274.It
275Ensure that your machine is acting as a gateway.  This can be done by
276specifying the line
277
278  gateway_enable=YES
279
280in
281.Pa /etc/rc.conf ,
282or using the command
283
284  sysctl -w net.inet.ip.forwarding=1
285
286.It
287If you wish to use the
288.Fl n
289or
290.Fl interface
291flags, make sure that your interface is already configured.  If, for
292example, you wish to specify tun0 as your
293.Ar interface ,
294and you're using
295.Xr ppp 8
296on that interface, you must make sure that you start
297.Nm ppp
298prior to starting
299.Nm natd .
300
301.It
302Create an entry in
303.Pa /etc/services :
304
305  natd          6668/divert  # Network Address Translation socket
306
307This gives a default for the
308.Fl p
309or
310.Fl port
311flag.
312
313.El
314.Pp
315Running
316.Nm natd
317is fairly straight forward.  The line
318
319  natd -interface ed0
320
321should suffice in most cases (substituting the correct interface name).  Once
322.Nm natd
323is running, you must ensure that traffic is diverted to natd:
324
325.Bl -enum
326.It
327You will need to adjust the
328.Pa /etc/rc.firewall
329script to taste.  If you're not interested in having a firewall, the
330following lines will do:
331
332  /sbin/ipfw -f flush
333  /sbin/ipfw add divert natd all from any to any via ed0
334  /sbin/ipfw add pass all from any to any
335
336The second line depends on your interface (change ed0 as appropriate)
337and assumes that you've updated
338.Pa /etc/services
339with the natd entry as above.  If you specify real firewall rules, it's
340best to specify line 2 at the start of the script so that
341.Nm natd
342sees all packets before they are dropped by the firewall.  The firewall
343rules will be run again on each packet after translation by
344.Nm natd ,
345minus any divert rules.
346
347.It
348Enable your firewall by setting
349
350  firewall=YES
351
352in
353.Pa /etc/rc.conf .
354This tells the system startup scripts to run the
355.Pa /etc/rc.firewall
356script.  If you don't wish to reboot now, just run this by hand from the
357console.  NEVER run this from a virtual session unless you put it into
358the background.  If you do, you'll lock yourself out after the flush
359takes place, and execution of
360.Pa /etc/rc.firewall
361will stop at this point - blocking all accesses permanently.  Running
362the script in the background should be enough to prevent this disaster.
363
364.El
365
366.Sh SEE ALSO
367.Xr getservbyname 2 ,
368.Xr socket 2 ,
369.Xr divert 4 ,
370.Xr services 5 ,
371.Xr ipfw 8
372
373.Sh AUTHORS
374This program is the result of the efforts of many people at different
375times:
376
377  Divert sockets:               Archie Cobbs <archie@whistle.com>
378  Packet aliasing:              Charles Mott <cmott@srv.net>
379  IRC support & misc additions: Eivind Eklund <perhaps@yes.no>
380  Natd:                         Ari Suutari <suutari@iki.fi>
381  Glue:                         Brian Somers <brian@awfulhak.org>
382