xref: /freebsd/sbin/natd/natd.8 (revision 01ba618f4a329f47b71ac6db961beab89f6da538)
17f3dea24SPeter Wemm.\" $FreeBSD$
201ba618fSRuslan Ermilov.Dd February 28, 2003
324084f9bSBrian Somers.Dt NATD 8
49fe48c6eSRuslan Ermilov.Os
524084f9bSBrian Somers.Sh NAME
624084f9bSBrian Somers.Nm natd
7eb083802SRuslan Ermilov.Nd Network Address Translation daemon
824084f9bSBrian Somers.Sh SYNOPSIS
97c7fb079SRuslan Ermilov.Nm
10d2a46bc9SRuslan Ermilov.Bk -words
115a424c8cSRuslan Ermilov.Op Fl unregistered_only | u
125a424c8cSRuslan Ermilov.Op Fl log | l
135a424c8cSRuslan Ermilov.Op Fl proxy_only
145a424c8cSRuslan Ermilov.Op Fl reverse
155a424c8cSRuslan Ermilov.Op Fl deny_incoming | d
165a424c8cSRuslan Ermilov.Op Fl use_sockets | s
175a424c8cSRuslan Ermilov.Op Fl same_ports | m
185a424c8cSRuslan Ermilov.Op Fl verbose | v
1924084f9bSBrian Somers.Op Fl dynamic
205a424c8cSRuslan Ermilov.Op Fl in_port | i Ar port
215a424c8cSRuslan Ermilov.Op Fl out_port | o Ar port
225a424c8cSRuslan Ermilov.Op Fl port | p Ar port
235a424c8cSRuslan Ermilov.Op Fl alias_address | a Ar address
245a424c8cSRuslan Ermilov.Op Fl target_address | t Ar address
255a424c8cSRuslan Ermilov.Op Fl interface | n Ar interface
265a424c8cSRuslan Ermilov.Op Fl proxy_rule Ar proxyspec
2710cffc50SBrian Somers.Op Fl redirect_port Ar linkspec
284330006dSRuslan Ermilov.Op Fl redirect_proto Ar linkspec
29bd690510SRuslan Ermilov.Op Fl redirect_address Ar linkspec
305a424c8cSRuslan Ermilov.Op Fl config | f Ar configfile
315a424c8cSRuslan Ermilov.Op Fl log_denied
325a424c8cSRuslan Ermilov.Op Fl log_facility Ar facility_name
33bc4ebb98SRuslan Ermilov.Op Fl punch_fw Ar firewall_range
3484ef95bdSPoul-Henning Kamp.Op Fl log_ipfw_denied
35d2a46bc9SRuslan Ermilov.Ek
3624084f9bSBrian Somers.Sh DESCRIPTION
37e1205e80SPhilippe CharnierThe
38e1205e80SPhilippe Charnier.Nm
39e1205e80SPhilippe Charnierutility provides a Network Address Translation facility for use
4024084f9bSBrian Somerswith
4124084f9bSBrian Somers.Xr divert 4
425a424c8cSRuslan Ermilovsockets under
435a424c8cSRuslan Ermilov.Fx .
4401ba618fSRuslan Ermilov.Pp
4501ba618fSRuslan Ermilov(If you need NAT on a PPP link,
4601ba618fSRuslan Ermilov.Xr ppp 8
4701ba618fSRuslan Ermilovprovides the
485a424c8cSRuslan Ermilov.Fl nat
4901ba618fSRuslan Ermilovoption that gives most of the
5001ba618fSRuslan Ermilov.Nm
5101ba618fSRuslan Ermilovfunctionality, and uses the same
5201ba618fSRuslan Ermilov.Xr libalias 3
5301ba618fSRuslan Ermilovlibrary.)
5424084f9bSBrian Somers.Pp
555a424c8cSRuslan ErmilovThe
565a424c8cSRuslan Ermilov.Nm
57e1205e80SPhilippe Charnierutility normally runs in the background as a daemon.
585a424c8cSRuslan ErmilovIt is passed raw IP packets as they travel into and out of the machine,
595a424c8cSRuslan Ermilovand will possibly change these before re-injecting them back into the
605a424c8cSRuslan ErmilovIP packet stream.
6124084f9bSBrian Somers.Pp
625a424c8cSRuslan ErmilovIt changes all packets destined for another host so that their source
635a424c8cSRuslan ErmilovIP number is that of the current machine.
645a424c8cSRuslan ErmilovFor each packet changed in this manner, an internal table entry is
655a424c8cSRuslan Ermilovcreated to record this fact.
665a424c8cSRuslan ErmilovThe source port number is also changed to indicate the table entry
675a424c8cSRuslan Ermilovapplying to the packet.
685a424c8cSRuslan ErmilovPackets that are received with a target IP of the current host are
695a424c8cSRuslan Ermilovchecked against this internal table.
705a424c8cSRuslan ErmilovIf an entry is found, it is used to determine the correct target IP
715a424c8cSRuslan Ermilovnumber and port to place in the packet.
7224084f9bSBrian Somers.Pp
73d2a46bc9SRuslan ErmilovThe following command line options are available:
7424084f9bSBrian Somers.Bl -tag -width Fl
7524084f9bSBrian Somers.It Fl log | l
7624084f9bSBrian SomersLog various aliasing statistics and information to the file
7724084f9bSBrian Somers.Pa /var/log/alias.log .
785a424c8cSRuslan ErmilovThis file is truncated each time
795a424c8cSRuslan Ermilov.Nm
805a424c8cSRuslan Ermilovis started.
8124084f9bSBrian Somers.It Fl deny_incoming | d
82d2a46bc9SRuslan ErmilovDo not pass incoming packets that have no
835a424c8cSRuslan Ermiloventry in the internal translation table.
84d2a46bc9SRuslan Ermilov.Pp
85d2a46bc9SRuslan ErmilovIf this option is not used, then such a packet will be altered
86d2a46bc9SRuslan Ermilovusing the rules in
87d2a46bc9SRuslan Ermilov.Fl target_address
88d2a46bc9SRuslan Ermilovbelow, and the entry will be made in the internal translation table.
8959a7c613SBrian Somers.It Fl log_denied
905a424c8cSRuslan ErmilovLog denied incoming packets via
915a424c8cSRuslan Ermilov.Xr syslog 3
92c4d9468eSRuslan Ermilov(see also
93c4d9468eSRuslan Ermilov.Fl log_facility ) .
9459a7c613SBrian Somers.It Fl log_facility Ar facility_name
955a424c8cSRuslan ErmilovUse specified log facility when logging information via
965a424c8cSRuslan Ermilov.Xr syslog 3 .
975a424c8cSRuslan ErmilovArgument
985a424c8cSRuslan Ermilov.Ar facility_name
995a424c8cSRuslan Ermilovis one of the keywords specified in
1005a424c8cSRuslan Ermilov.Xr syslog.conf 5 .
10124084f9bSBrian Somers.It Fl use_sockets | s
10224084f9bSBrian SomersAllocate a
10324084f9bSBrian Somers.Xr socket 2
1045a424c8cSRuslan Ermilovin order to establish an FTP data or IRC DCC send connection.
1055a424c8cSRuslan ErmilovThis option uses more system resources, but guarantees successful
1065a424c8cSRuslan Ermilovconnections when port numbers conflict.
10724084f9bSBrian Somers.It Fl same_ports | m
10824084f9bSBrian SomersTry to keep the same port number when altering outgoing packets.
1097731ee5aSAlexander LangerWith this option, protocols such as RPC will have a better chance
1105a424c8cSRuslan Ermilovof working.
1115a424c8cSRuslan ErmilovIf it is not possible to maintain the port number, it will be silently
1125a424c8cSRuslan Ermilovchanged as per normal.
11324084f9bSBrian Somers.It Fl verbose | v
1145a424c8cSRuslan ErmilovDo not call
11524084f9bSBrian Somers.Xr daemon 3
1165a424c8cSRuslan Ermilovon startup.
117d2a46bc9SRuslan ErmilovInstead, stay attached to the controlling terminal and display all packet
1185a424c8cSRuslan Ermilovalterations to the standard output.
1195a424c8cSRuslan ErmilovThis option should only be used for debugging purposes.
12024084f9bSBrian Somers.It Fl unregistered_only | u
1215a424c8cSRuslan ErmilovOnly alter outgoing packets with an
1225a424c8cSRuslan Ermilov.Em unregistered
1235a424c8cSRuslan Ermilovsource address.
1245a424c8cSRuslan ErmilovAccording to RFC 1918, unregistered source addresses are 10.0.0.0/8,
1257731ee5aSAlexander Langer172.16.0.0/12 and 192.168.0.0/16.
1265a424c8cSRuslan Ermilov.It Fl redirect_port Ar proto Xo
1275a424c8cSRuslan Ermilov.Ar targetIP Ns : Ns Xo
1285a424c8cSRuslan Ermilov.Ar targetPORT Ns Op - Ns Ar targetPORT Xc
1295a424c8cSRuslan Ermilov.Op Ar aliasIP Ns : Ns Xo
1305a424c8cSRuslan Ermilov.Ar aliasPORT Ns Op - Ns Ar aliasPORT Xc
1315a424c8cSRuslan Ermilov.Oo Ar remoteIP Ns Oo : Ns
1325a424c8cSRuslan Ermilov.Ar remotePORT Ns Op - Ns Ar remotePORT
1335a424c8cSRuslan Ermilov.Oc Oc
1345a424c8cSRuslan Ermilov.Xc
1359c501140SBrian SomersRedirect incoming connections arriving to given port(s) to another host
1369c501140SBrian Somersand port(s).
1375a424c8cSRuslan ErmilovArgument
1385a424c8cSRuslan Ermilov.Ar proto
1395a424c8cSRuslan Ermilovis either
1405a424c8cSRuslan Ermilov.Ar tcp
1415a424c8cSRuslan Ermilovor
1425a424c8cSRuslan Ermilov.Ar udp ,
1435a424c8cSRuslan Ermilov.Ar targetIP
1445a424c8cSRuslan Ermilovis the desired target IP number,
1455a424c8cSRuslan Ermilov.Ar targetPORT
1465a424c8cSRuslan Ermilovis the desired target port number or range,
1475a424c8cSRuslan Ermilov.Ar aliasPORT
1485a424c8cSRuslan Ermilovis the requested port number or range, and
1495a424c8cSRuslan Ermilov.Ar aliasIP
1505a424c8cSRuslan Ermilovis the aliasing address.
1515a424c8cSRuslan ErmilovArguments
1525a424c8cSRuslan Ermilov.Ar remoteIP
1535a424c8cSRuslan Ermilovand
1545a424c8cSRuslan Ermilov.Ar remotePORT
1555a424c8cSRuslan Ermilovcan be used to specify the connection more accurately if necessary.
1565a424c8cSRuslan ErmilovThe
1575a424c8cSRuslan Ermilov.Ar targetPORT
1585a424c8cSRuslan Ermilovrange and
1595a424c8cSRuslan Ermilov.Ar aliasPORT
1605a424c8cSRuslan Ermilovrange need not be the same numerically, but must have the same size.
1615a424c8cSRuslan ErmilovIf
1625a424c8cSRuslan Ermilov.Ar remotePORT
1635a424c8cSRuslan Ermilovis not specified, it is assumed to be all ports.
1645a424c8cSRuslan ErmilovIf
1655a424c8cSRuslan Ermilov.Ar remotePORT
1665a424c8cSRuslan Ermilovis specified, it must match the size of
1675a424c8cSRuslan Ermilov.Ar targetPORT ,
1685a424c8cSRuslan Ermilovor be 0 (all ports).
1697731ee5aSAlexander LangerFor example, the argument
1705a424c8cSRuslan Ermilov.Pp
17166648838SBrian Somers.Dl Ar tcp inside1:telnet 6666
1725a424c8cSRuslan Ermilov.Pp
1735a424c8cSRuslan Ermilovmeans that incoming TCP packets destined for port 6666 on this machine
1745a424c8cSRuslan Ermilovwill be sent to the telnet port on the inside1 machine.
1755a424c8cSRuslan Ermilov.Pp
17666648838SBrian Somers.Dl Ar tcp inside2:2300-2399 3300-3399
1775a424c8cSRuslan Ermilov.Pp
1789c501140SBrian Somerswill redirect incoming connections on ports 3300-3399 to host
1799c501140SBrian Somersinside2, ports 2300-2399.
1809c501140SBrian SomersThe mapping is 1:1 meaning port 3300 maps to 2300, 3301 maps to 2301, etc.
1815a424c8cSRuslan Ermilov.It Fl redirect_proto Ar proto localIP Oo
1825a424c8cSRuslan Ermilov.Ar publicIP Op Ar remoteIP
1835a424c8cSRuslan Ermilov.Oc
1844330006dSRuslan ErmilovRedirect incoming IP packets of protocol
1854330006dSRuslan Ermilov.Ar proto
186c4d9468eSRuslan Ermilov(see
187c4d9468eSRuslan Ermilov.Xr protocols 5 )
1884330006dSRuslan Ermilovdestined for
1894330006dSRuslan Ermilov.Ar publicIP
1904330006dSRuslan Ermilovaddress to a
1914330006dSRuslan Ermilov.Ar localIP
1924330006dSRuslan Ermilovaddress and vice versa.
1934330006dSRuslan Ermilov.Pp
1944330006dSRuslan ErmilovIf
1954330006dSRuslan Ermilov.Ar publicIP
1967731ee5aSAlexander Langeris not specified, then the default aliasing address is used.
1974330006dSRuslan ErmilovIf
1984330006dSRuslan Ermilov.Ar remoteIP
1997731ee5aSAlexander Langeris specified, then only packets coming from/to
2004330006dSRuslan Ermilov.Ar remoteIP
2014330006dSRuslan Ermilovwill match the rule.
20224084f9bSBrian Somers.It Fl redirect_address Ar localIP publicIP
2037731ee5aSAlexander LangerRedirect traffic for public IP address to a machine on the local
2047731ee5aSAlexander Langernetwork.
2055a424c8cSRuslan ErmilovThis function is known as
2065a424c8cSRuslan Ermilov.Em static NAT .
2075a424c8cSRuslan ErmilovNormally static NAT is useful if your ISP has allocated a small block
2085a424c8cSRuslan Ermilovof IP addresses to you, but it can even be used in the case of single
2095a424c8cSRuslan Ermilovaddress:
2105a424c8cSRuslan Ermilov.Pp
2115a424c8cSRuslan Ermilov.Dl Ar redirect_address 10.0.0.8 0.0.0.0
2125a424c8cSRuslan Ermilov.Pp
2137731ee5aSAlexander LangerThe above command would redirect all incoming traffic
2147731ee5aSAlexander Langerto machine 10.0.0.8.
2155a424c8cSRuslan Ermilov.Pp
2167731ee5aSAlexander LangerIf several address aliases specify the same public address
2177731ee5aSAlexander Langeras follows
2185a424c8cSRuslan Ermilov.Bd -literal -offset indent
2195a424c8cSRuslan Ermilov.Ar redirect_address 192.168.0.2 public_addr
2205a424c8cSRuslan Ermilov.Ar redirect_address 192.168.0.3 public_addr
2215a424c8cSRuslan Ermilov.Ar redirect_address 192.168.0.4 public_addr
2225a424c8cSRuslan Ermilov.Ed
2235a424c8cSRuslan Ermilov.Pp
22424084f9bSBrian Somersthe incoming traffic will be directed to the last
2257731ee5aSAlexander Langertranslated local address (192.168.0.4), but outgoing
2265a424c8cSRuslan Ermilovtraffic from the first two addresses will still be aliased
2275a424c8cSRuslan Ermilovto appear from the specified
2285a424c8cSRuslan Ermilov.Ar public_addr .
229bd690510SRuslan Ermilov.It Fl redirect_port Ar proto Xo
230bd690510SRuslan Ermilov.Ar targetIP Ns : Ns Xo
231bd690510SRuslan Ermilov.Ar targetPORT Ns Oo , Ns
232bd690510SRuslan Ermilov.Ar targetIP Ns : Ns Xo
233bd690510SRuslan Ermilov.Ar targetPORT Ns Oo , Ns
234d0353b83SRuslan Ermilov.Ar ...\&
235bd690510SRuslan Ermilov.Oc Oc
236bd690510SRuslan Ermilov.Xc
237bd690510SRuslan Ermilov.Xc
238bd690510SRuslan Ermilov.Op Ar aliasIP Ns : Ns Xo
239bd690510SRuslan Ermilov.Ar aliasPORT
240bd690510SRuslan Ermilov.Xc
241bd690510SRuslan Ermilov.Oo Ar remoteIP Ns
242bd690510SRuslan Ermilov.Op : Ns Ar remotePORT
243bd690510SRuslan Ermilov.Oc
244bd690510SRuslan Ermilov.Xc
245bd690510SRuslan Ermilov.It Fl redirect_address Xo
246bd690510SRuslan Ermilov.Ar localIP Ns Oo , Ns
247bd690510SRuslan Ermilov.Ar localIP Ns Oo , Ns
248d0353b83SRuslan Ermilov.Ar ...\&
249bd690510SRuslan Ermilov.Oc Oc
250bd690510SRuslan Ermilov.Ar publicIP
251bd690510SRuslan Ermilov.Xc
252bd690510SRuslan ErmilovThese forms of
253bd690510SRuslan Ermilov.Fl redirect_port
254bd690510SRuslan Ermilovand
255bd690510SRuslan Ermilov.Fl redirect_address
256bd690510SRuslan Ermilovare used to transparently offload network load on a single server and
257bd690510SRuslan Ermilovdistribute the load across a pool of servers.
258bd690510SRuslan ErmilovThis function is known as
259bd690510SRuslan Ermilov.Em LSNAT
260bd690510SRuslan Ermilov(RFC 2391).
2617731ee5aSAlexander LangerFor example, the argument
262bd690510SRuslan Ermilov.Pp
263bd690510SRuslan Ermilov.Dl Ar tcp www1:http,www2:http,www3:http www:http
264bd690510SRuslan Ermilov.Pp
265bd690510SRuslan Ermilovmeans that incoming HTTP requests for host www will be transparently
2667731ee5aSAlexander Langerredirected to one of the www1, www2 or www3, where a host is selected
2677731ee5aSAlexander Langersimply on a round-robin basis, without regard to load on the net.
26824084f9bSBrian Somers.It Fl dynamic
26924084f9bSBrian SomersIf the
27024084f9bSBrian Somers.Fl n
27124084f9bSBrian Somersor
27224084f9bSBrian Somers.Fl interface
27324084f9bSBrian Somersoption is used,
2740fc81af1SPhilippe Charnier.Nm
27524084f9bSBrian Somerswill monitor the routing socket for alterations to the
27624084f9bSBrian Somers.Ar interface
2775a424c8cSRuslan Ermilovpassed.
2785a424c8cSRuslan ErmilovIf the interface's IP number is changed,
2790fc81af1SPhilippe Charnier.Nm
28024084f9bSBrian Somerswill dynamically alter its concept of the alias address.
2815a424c8cSRuslan Ermilov.It Fl in_port | i Ar port
28224084f9bSBrian SomersRead from and write to
283d2a46bc9SRuslan Ermilov.Xr divert 4
284d2a46bc9SRuslan Ermilovport
28524084f9bSBrian Somers.Ar port ,
286d2a46bc9SRuslan Ermilovtreating all packets as
287d2a46bc9SRuslan Ermilov.Dq incoming .
2885a424c8cSRuslan Ermilov.It Fl out_port | o Ar port
2895a424c8cSRuslan ErmilovRead from and write to
290d2a46bc9SRuslan Ermilov.Xr divert 4
291d2a46bc9SRuslan Ermilovport
2925a424c8cSRuslan Ermilov.Ar port ,
293d2a46bc9SRuslan Ermilovtreating all packets as
294d2a46bc9SRuslan Ermilov.Dq outgoing .
2955a424c8cSRuslan Ermilov.It Fl port | p Ar port
2965a424c8cSRuslan ErmilovRead from and write to
297d2a46bc9SRuslan Ermilov.Xr divert 4
298d2a46bc9SRuslan Ermilovport
2995a424c8cSRuslan Ermilov.Ar port ,
300d2a46bc9SRuslan Ermilovdistinguishing packets as
301d2a46bc9SRuslan Ermilov.Dq incoming
302d2a46bc9SRuslan Ermilovor
303d2a46bc9SRuslan Ermilov.Dq outgoing
304d2a46bc9SRuslan Ermilovusing the rules specified in
30524084f9bSBrian Somers.Xr divert 4 .
30624084f9bSBrian SomersIf
30724084f9bSBrian Somers.Ar port
30824084f9bSBrian Somersis not numeric, it is searched for in the
30924084f9bSBrian Somers.Xr services 5
3105a424c8cSRuslan Ermilovdatabase.
3115a424c8cSRuslan ErmilovIf this option is not specified, the divert port named
312d2a46bc9SRuslan Ermilov.Ar natd
3135a424c8cSRuslan Ermilovwill be used as a default.
3145a424c8cSRuslan Ermilov.It Fl alias_address | a Ar address
31524084f9bSBrian SomersUse
31624084f9bSBrian Somers.Ar address
3175a424c8cSRuslan Ermilovas the aliasing address.
3185a424c8cSRuslan ErmilovIf this option is not specified, the
31924084f9bSBrian Somers.Fl interface
3205a424c8cSRuslan Ermilovoption must be used.
3215a424c8cSRuslan ErmilovThe specified address is usually the address assigned to the
322d2a46bc9SRuslan Ermilov.Dq public
323d2a46bc9SRuslan Ermilovnetwork interface.
324f7d1db72SBrian Somers.Pp
3255a424c8cSRuslan ErmilovAll data passing
3265a424c8cSRuslan Ermilov.Em out
3275a424c8cSRuslan Ermilovwill be rewritten with a source address equal to
328f7d1db72SBrian Somers.Ar address .
3295a424c8cSRuslan ErmilovAll data coming
3305a424c8cSRuslan Ermilov.Em in
3315a424c8cSRuslan Ermilovwill be checked to see if it matches any already-aliased outgoing
3325a424c8cSRuslan Ermilovconnection.
3335a424c8cSRuslan ErmilovIf it does, the packet is altered accordingly.
3345a424c8cSRuslan ErmilovIf not, all
3355a424c8cSRuslan Ermilov.Fl redirect_port ,
3365a424c8cSRuslan Ermilov.Fl redirect_proto
337f7d1db72SBrian Somersand
338f7d1db72SBrian Somers.Fl redirect_address
3395a424c8cSRuslan Ermilovassignments are checked and actioned.
3405a424c8cSRuslan ErmilovIf no other action can be made and if
341f7d1db72SBrian Somers.Fl deny_incoming
342d2a46bc9SRuslan Ermilovis not specified, the packet is delivered to the local machine
343d2a46bc9SRuslan Ermilovusing the rules specified in
3445a424c8cSRuslan Ermilov.Fl target_address
3455a424c8cSRuslan Ermilovoption below.
34611c2b3bfSRuslan Ermilov.It Fl t | target_address Ar address
34711c2b3bfSRuslan ErmilovSet the target address.
34811c2b3bfSRuslan ErmilovWhen an incoming packet not associated with any pre-existing link
3497731ee5aSAlexander Langerarrives at the host machine, it will be sent to the specified
35011c2b3bfSRuslan Ermilov.Ar address .
35111c2b3bfSRuslan Ermilov.Pp
35211c2b3bfSRuslan ErmilovThe target address may be set to
3535a424c8cSRuslan Ermilov.Ar 255.255.255.255 ,
35411c2b3bfSRuslan Ermilovin which case all new incoming packets go to the alias address set by
35511c2b3bfSRuslan Ermilov.Fl alias_address
35611c2b3bfSRuslan Ermilovor
35711c2b3bfSRuslan Ermilov.Fl interface .
35811c2b3bfSRuslan Ermilov.Pp
3597731ee5aSAlexander LangerIf this option is not used, or called with the argument
3605a424c8cSRuslan Ermilov.Ar 0.0.0.0 ,
3617731ee5aSAlexander Langerthen all new incoming packets go to the address specified in
3627731ee5aSAlexander Langerthe packet.
36311c2b3bfSRuslan ErmilovThis allows external machines to talk directly to internal machines if
36411c2b3bfSRuslan Ermilovthey can route packets to the machine in question.
3655a424c8cSRuslan Ermilov.It Fl interface | n Ar interface
36624084f9bSBrian SomersUse
36724084f9bSBrian Somers.Ar interface
3685a424c8cSRuslan Ermilovto determine the aliasing address.
3695a424c8cSRuslan ErmilovIf there is a possibility that the IP number associated with
37024084f9bSBrian Somers.Ar interface
37124084f9bSBrian Somersmay change, the
37224084f9bSBrian Somers.Fl dynamic
3735a424c8cSRuslan Ermilovoption should also be used.
3745a424c8cSRuslan ErmilovIf this option is not specified, the
37524084f9bSBrian Somers.Fl alias_address
3765a424c8cSRuslan Ermilovoption must be used.
377f7d1db72SBrian Somers.Pp
378f7d1db72SBrian SomersThe specified
379f7d1db72SBrian Somers.Ar interface
380d2a46bc9SRuslan Ermilovis usually the
381d2a46bc9SRuslan Ermilov.Dq public
382d2a46bc9SRuslan Ermilov(or
383d2a46bc9SRuslan Ermilov.Dq external )
384d2a46bc9SRuslan Ermilovnetwork interface.
3855a424c8cSRuslan Ermilov.It Fl config | f Ar file
38624084f9bSBrian SomersRead configuration from
3875a424c8cSRuslan Ermilov.Ar file .
3885a424c8cSRuslan ErmilovA
3895a424c8cSRuslan Ermilov.Ar file
3905a424c8cSRuslan Ermilovshould contain a list of options, one per line, in the same form
3915a424c8cSRuslan Ermilovas the long form of the above command line options.
3925a424c8cSRuslan ErmilovFor example, the line
3935a424c8cSRuslan Ermilov.Pp
3945a424c8cSRuslan Ermilov.Dl alias_address 158.152.17.1
3955a424c8cSRuslan Ermilov.Pp
3965a424c8cSRuslan Ermilovwould specify an alias address of 158.152.17.1.
397d2a46bc9SRuslan ErmilovOptions that do not take an argument are specified with an argument of
39824084f9bSBrian Somers.Ar yes
39924084f9bSBrian Somersor
40024084f9bSBrian Somers.Ar no
4015a424c8cSRuslan Ermilovin the configuration file.
4025a424c8cSRuslan ErmilovFor example, the line
4035a424c8cSRuslan Ermilov.Pp
4045a424c8cSRuslan Ermilov.Dl log yes
4055a424c8cSRuslan Ermilov.Pp
4065a424c8cSRuslan Ermilovis synonymous with
40724084f9bSBrian Somers.Fl log .
4082e7e7c71SRuslan Ermilov.Pp
4092e7e7c71SRuslan ErmilovTrailing spaces and empty lines are ignored.
4102e7e7c71SRuslan ErmilovA
4112e7e7c71SRuslan Ermilov.Ql \&#
4122522beceSMike Pritchardsign will mark the rest of the line as a comment.
41359a7c613SBrian Somers.It Fl reverse
4145a424c8cSRuslan ErmilovThis option makes
4155a424c8cSRuslan Ermilov.Nm
416d2a46bc9SRuslan Ermilovreverse the way it handles
417d2a46bc9SRuslan Ermilov.Dq incoming
418d2a46bc9SRuslan Ermilovand
419d2a46bc9SRuslan Ermilov.Dq outgoing
420d2a46bc9SRuslan Ermilovpackets, allowing it to operate on the
421d2a46bc9SRuslan Ermilov.Dq internal
422d2a46bc9SRuslan Ermilovnetwork interface rather than the
423d2a46bc9SRuslan Ermilov.Dq external
424d2a46bc9SRuslan Ermilovone.
4255a424c8cSRuslan Ermilov.Pp
4265a424c8cSRuslan ErmilovThis can be useful in some transparent proxying situations
4275a424c8cSRuslan Ermilovwhen outgoing traffic is redirected to the local machine
4285a424c8cSRuslan Ermilovand
4295a424c8cSRuslan Ermilov.Nm
4305a424c8cSRuslan Ermilovis running on the internal interface (it usually runs on the
4315a424c8cSRuslan Ermilovexternal interface).
43259a7c613SBrian Somers.It Fl proxy_only
4335a424c8cSRuslan ErmilovForce
4345a424c8cSRuslan Ermilov.Nm
4355a424c8cSRuslan Ermilovto perform transparent proxying only.
436ef8f7ac9SSheldon HearnNormal address translation is not performed.
4375a424c8cSRuslan Ermilov.It Fl proxy_rule Xo
4385a424c8cSRuslan Ermilov.Op Ar type encode_ip_hdr | encode_tcp_stream
4395a424c8cSRuslan Ermilov.Ar port xxxx
4405a424c8cSRuslan Ermilov.Ar server a.b.c.d:yyyy
4415a424c8cSRuslan Ermilov.Xc
442ef8f7ac9SSheldon HearnEnable transparent proxying.
4435a424c8cSRuslan ErmilovOutgoing TCP packets with the given port going through this
4447731ee5aSAlexander Langerhost to any other host are redirected to the given server and port.
445ef8f7ac9SSheldon HearnOptionally, the original target address can be encoded into the packet.
446ef8f7ac9SSheldon HearnUse
4475a424c8cSRuslan Ermilov.Ar encode_ip_hdr
44859a7c613SBrian Somersto put this information into the IP option field or
4495a424c8cSRuslan Ermilov.Ar encode_tcp_stream
45059a7c613SBrian Somersto inject the data into the beginning of the TCP stream.
451bc4ebb98SRuslan Ermilov.It Fl punch_fw Xo
452bc4ebb98SRuslan Ermilov.Ar basenumber Ns : Ns Ar count
453bc4ebb98SRuslan Ermilov.Xc
454f685a909SRuslan ErmilovThis option directs
455bc4ebb98SRuslan Ermilov.Nm
456f685a909SRuslan Ermilovto
457f685a909SRuslan Ermilov.Dq punch holes
458bc4ebb98SRuslan Ermilovin an
459bc4ebb98SRuslan Ermilov.Xr ipfirewall 4
460bc4ebb98SRuslan Ermilovbased firewall for FTP/IRC DCC connections.
461f685a909SRuslan ErmilovThis is done dynamically by installing temporary firewall rules which
462f685a909SRuslan Ermilovallow a particular connection (and only that connection) to go through
463f685a909SRuslan Ermilovthe firewall.
464f685a909SRuslan ErmilovThe rules are removed once the corresponding connection terminates.
465bc4ebb98SRuslan Ermilov.Pp
466f685a909SRuslan ErmilovA maximum of
467bc4ebb98SRuslan Ermilov.Ar count
468f685a909SRuslan Ermilovrules starting from the rule number
469f685a909SRuslan Ermilov.Ar basenumber
470f685a909SRuslan Ermilovwill be used for punching firewall holes.
471bc4ebb98SRuslan ErmilovThe range will be cleared for all rules on startup.
47284ef95bdSPoul-Henning Kamp.It Fl log_ipfw_denied
4733843533eSRuslan ErmilovLog when a packet cannot be re-injected because an
4743843533eSRuslan Ermilov.Xr ipfw 8
4753843533eSRuslan Ermilovrule blocks it.
476c0956cf8SRuslan ErmilovThis is the default with
477c0956cf8SRuslan Ermilov.Fl verbose .
47824084f9bSBrian Somers.El
47924084f9bSBrian Somers.Sh RUNNING NATD
48024084f9bSBrian SomersThe following steps are necessary before attempting to run
4817c7fb079SRuslan Ermilov.Nm :
48224084f9bSBrian Somers.Bl -enum
48324084f9bSBrian Somers.It
48424084f9bSBrian SomersBuild a custom kernel with the following options:
4855a424c8cSRuslan Ermilov.Bd -literal -offset indent
48624084f9bSBrian Somersoptions IPFIREWALL
48724084f9bSBrian Somersoptions IPDIVERT
4885a424c8cSRuslan Ermilov.Ed
4895a424c8cSRuslan Ermilov.Pp
49024084f9bSBrian SomersRefer to the handbook for detailed instructions on building a custom
49124084f9bSBrian Somerskernel.
49224084f9bSBrian Somers.It
4935a424c8cSRuslan ErmilovEnsure that your machine is acting as a gateway.
4945a424c8cSRuslan ErmilovThis can be done by specifying the line
4955a424c8cSRuslan Ermilov.Pp
4965a424c8cSRuslan Ermilov.Dl gateway_enable=YES
4975a424c8cSRuslan Ermilov.Pp
4985a424c8cSRuslan Ermilovin the
4995a424c8cSRuslan Ermilov.Pa /etc/rc.conf
5005a424c8cSRuslan Ermilovfile or using the command
5015a424c8cSRuslan Ermilov.Pp
502e21a315eSRuslan Ermilov.Dl "sysctl net.inet.ip.forwarding=1"
5035a424c8cSRuslan Ermilov.Pp
50424084f9bSBrian Somers.It
5055a424c8cSRuslan ErmilovIf you use the
50624084f9bSBrian Somers.Fl interface
5075a424c8cSRuslan Ermilovoption, make sure that your interface is already configured.
508d2a46bc9SRuslan ErmilovIf, for example, you wish to specify
509d2a46bc9SRuslan Ermilov.Ql tun0
510d2a46bc9SRuslan Ermilovas your
51124084f9bSBrian Somers.Ar interface ,
5125a424c8cSRuslan Ermilovand you are using
51324084f9bSBrian Somers.Xr ppp 8
5147731ee5aSAlexander Langeron that interface, you must make sure that you start
51524084f9bSBrian Somers.Nm ppp
51624084f9bSBrian Somersprior to starting
5177c7fb079SRuslan Ermilov.Nm .
51824084f9bSBrian Somers.El
51924084f9bSBrian Somers.Pp
52024084f9bSBrian SomersRunning
5210fc81af1SPhilippe Charnier.Nm
5225a424c8cSRuslan Ermilovis fairly straight forward.
5235a424c8cSRuslan ErmilovThe line
5245a424c8cSRuslan Ermilov.Pp
5255a424c8cSRuslan Ermilov.Dl natd -interface ed0
5265a424c8cSRuslan Ermilov.Pp
5275a424c8cSRuslan Ermilovshould suffice in most cases (substituting the correct interface name).
528ecd1fe62SRuslan ErmilovPlease check
529ecd1fe62SRuslan Ermilov.Xr rc.conf 5
530ecd1fe62SRuslan Ermilovon how to configure it to be started automatically during boot.
5315a424c8cSRuslan ErmilovOnce
5320fc81af1SPhilippe Charnier.Nm
5335a424c8cSRuslan Ermilovis running, you must ensure that traffic is diverted to
5347c7fb079SRuslan Ermilov.Nm :
53524084f9bSBrian Somers.Bl -enum
53624084f9bSBrian Somers.It
53724084f9bSBrian SomersYou will need to adjust the
53824084f9bSBrian Somers.Pa /etc/rc.firewall
5395a424c8cSRuslan Ermilovscript to taste.
5405a424c8cSRuslan ErmilovIf you are not interested in having a firewall, the
54124084f9bSBrian Somersfollowing lines will do:
5425a424c8cSRuslan Ermilov.Bd -literal -offset indent
54324084f9bSBrian Somers/sbin/ipfw -f flush
54446b2c559SBrian Somers/sbin/ipfw add divert natd all from any to any via ed0
54524084f9bSBrian Somers/sbin/ipfw add pass all from any to any
5465a424c8cSRuslan Ermilov.Ed
5475a424c8cSRuslan Ermilov.Pp
548d2a46bc9SRuslan ErmilovThe second line depends on your interface (change
549d2a46bc9SRuslan Ermilov.Ql ed0
550d2a46bc9SRuslan Ermilovas appropriate).
5515a424c8cSRuslan Ermilov.Pp
5525a424c8cSRuslan ErmilovYou should be aware of the fact that, with these firewall settings,
5535a424c8cSRuslan Ermiloveveryone on your local network can fake his source-address using your
5545a424c8cSRuslan Ermilovhost as gateway.
5555a424c8cSRuslan ErmilovIf there are other hosts on your local network, you are strongly
5565a424c8cSRuslan Ermilovencouraged to create firewall rules that only allow traffic to and
5575a424c8cSRuslan Ermilovfrom trusted hosts.
5585a424c8cSRuslan Ermilov.Pp
5595a424c8cSRuslan ErmilovIf you specify real firewall rules, it is best to specify line 2 at
5605a424c8cSRuslan Ermilovthe start of the script so that
5610fc81af1SPhilippe Charnier.Nm
56204bf7dcfSRuslan Ermilovsees all packets before they are dropped by the firewall.
56304bf7dcfSRuslan Ermilov.Pp
56404bf7dcfSRuslan ErmilovAfter translation by
5657c7fb079SRuslan Ermilov.Nm ,
56604bf7dcfSRuslan Ermilovpackets re-enter the firewall at the rule number following the rule number
5677731ee5aSAlexander Langerthat caused the diversion (not the next rule if there are several at the
5687731ee5aSAlexander Langersame number).
56924084f9bSBrian Somers.It
57024084f9bSBrian SomersEnable your firewall by setting
5715a424c8cSRuslan Ermilov.Pp
5725a424c8cSRuslan Ermilov.Dl firewall_enable=YES
5735a424c8cSRuslan Ermilov.Pp
57424084f9bSBrian Somersin
575c1b792b2SJordan K. Hubbard.Pa /etc/rc.conf .
57624084f9bSBrian SomersThis tells the system startup scripts to run the
57724084f9bSBrian Somers.Pa /etc/rc.firewall
5785a424c8cSRuslan Ermilovscript.
5795a424c8cSRuslan ErmilovIf you do not wish to reboot now, just run this by hand from the console.
5805a424c8cSRuslan ErmilovNEVER run this from a remote session unless you put it into the background.
5815a424c8cSRuslan ErmilovIf you do, you will lock yourself out after the flush takes place, and
5825a424c8cSRuslan Ermilovexecution of
58324084f9bSBrian Somers.Pa /etc/rc.firewall
5845a424c8cSRuslan Ermilovwill stop at this point - blocking all accesses permanently.
5855a424c8cSRuslan ErmilovRunning the script in the background should be enough to prevent this
5865a424c8cSRuslan Ermilovdisaster.
58724084f9bSBrian Somers.El
58824084f9bSBrian Somers.Sh SEE ALSO
58901ba618fSRuslan Ermilov.Xr libalias 3 ,
59024084f9bSBrian Somers.Xr divert 4 ,
5915a424c8cSRuslan Ermilov.Xr protocols 5 ,
5925a424c8cSRuslan Ermilov.Xr rc.conf 5 ,
59324084f9bSBrian Somers.Xr services 5 ,
5945a424c8cSRuslan Ermilov.Xr syslog.conf 5 ,
5955a424c8cSRuslan Ermilov.Xr ipfw 8 ,
59632e5e4cfSBen Smithurst.Xr ppp 8
59724084f9bSBrian Somers.Sh AUTHORS
59824084f9bSBrian SomersThis program is the result of the efforts of many people at different
59924084f9bSBrian Somerstimes:
6005a424c8cSRuslan Ermilov.Pp
601aa7998d4SRuslan Ermilov.An Archie Cobbs Aq archie@FreeBSD.org
602f12a1471SPhilippe Charnier(divert sockets)
603496f81e0SRuslan Ermilov.An Charles Mott Aq cm@linktel.net
604f12a1471SPhilippe Charnier(packet aliasing)
605f12a1471SPhilippe Charnier.An Eivind Eklund Aq perhaps@yes.no
606f12a1471SPhilippe Charnier(IRC support & misc additions)
607f12a1471SPhilippe Charnier.An Ari Suutari Aq suutari@iki.fi
608f12a1471SPhilippe Charnier(natd)
60959a7c613SBrian Somers.An Dru Nelson Aq dnelson@redwoodsoft.com
610dc1a0225SRuslan Ermilov(early PPTP support)
611f12a1471SPhilippe Charnier.An Brian Somers Aq brian@awfulhak.org
612f12a1471SPhilippe Charnier(glue)
613d2a46bc9SRuslan Ermilov.An Ruslan Ermilov Aq ru@FreeBSD.org
614d2a46bc9SRuslan Ermilov(natd, packet aliasing, glue)
615