xref: /freebsd/sbin/natd/natd.8 (revision d0353b836e88609b9400851d32e0aa6645ff9be3)
17f3dea24SPeter Wemm.\" $FreeBSD$
25a424c8cSRuslan Ermilov.Dd June 27, 2000
324084f9bSBrian Somers.Dt NATD 8
45a424c8cSRuslan Ermilov.Os FreeBSD
524084f9bSBrian Somers.Sh NAME
624084f9bSBrian Somers.Nm natd
75a424c8cSRuslan 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
34d2a46bc9SRuslan Ermilov.Ek
3524084f9bSBrian Somers.Sh DESCRIPTION
3624084f9bSBrian SomersThis program provides a Network Address Translation facility for use
3724084f9bSBrian Somerswith
3824084f9bSBrian Somers.Xr divert 4
395a424c8cSRuslan Ermilovsockets under
405a424c8cSRuslan Ermilov.Fx .
415a424c8cSRuslan ErmilovIt is intended for use with NICs - if you want to do NAT on a PPP link,
425a424c8cSRuslan Ermilovuse the
435a424c8cSRuslan Ermilov.Fl nat
445a424c8cSRuslan Ermilovswitch to
4526b4eff6SEivind Eklund.Xr ppp 8 .
4624084f9bSBrian Somers.Pp
475a424c8cSRuslan ErmilovThe
485a424c8cSRuslan Ermilov.Nm
495a424c8cSRuslan Ermilovnormally runs in the background as a daemon.
505a424c8cSRuslan ErmilovIt is passed raw IP packets as they travel into and out of the machine,
515a424c8cSRuslan Ermilovand will possibly change these before re-injecting them back into the
525a424c8cSRuslan ErmilovIP packet stream.
5324084f9bSBrian Somers.Pp
545a424c8cSRuslan ErmilovIt changes all packets destined for another host so that their source
555a424c8cSRuslan ErmilovIP number is that of the current machine.
565a424c8cSRuslan ErmilovFor each packet changed in this manner, an internal table entry is
575a424c8cSRuslan Ermilovcreated to record this fact.
585a424c8cSRuslan ErmilovThe source port number is also changed to indicate the table entry
595a424c8cSRuslan Ermilovapplying to the packet.
605a424c8cSRuslan ErmilovPackets that are received with a target IP of the current host are
615a424c8cSRuslan Ermilovchecked against this internal table.
625a424c8cSRuslan ErmilovIf an entry is found, it is used to determine the correct target IP
635a424c8cSRuslan Ermilovnumber and port to place in the packet.
6424084f9bSBrian Somers.Pp
65d2a46bc9SRuslan ErmilovThe following command line options are available:
6624084f9bSBrian Somers.Bl -tag -width Fl
6724084f9bSBrian Somers.It Fl log | l
6824084f9bSBrian SomersLog various aliasing statistics and information to the file
6924084f9bSBrian Somers.Pa /var/log/alias.log .
705a424c8cSRuslan ErmilovThis file is truncated each time
715a424c8cSRuslan Ermilov.Nm
725a424c8cSRuslan Ermilovis started.
7324084f9bSBrian Somers.It Fl deny_incoming | d
74d2a46bc9SRuslan ErmilovDo not pass incoming packets that have no
755a424c8cSRuslan Ermiloventry in the internal translation table.
76d2a46bc9SRuslan Ermilov.Pp
77d2a46bc9SRuslan ErmilovIf this option is not used, then such a packet will be altered
78d2a46bc9SRuslan Ermilovusing the rules in
79d2a46bc9SRuslan Ermilov.Fl target_address
80d2a46bc9SRuslan Ermilovbelow, and the entry will be made in the internal translation table.
8159a7c613SBrian Somers.It Fl log_denied
825a424c8cSRuslan ErmilovLog denied incoming packets via
835a424c8cSRuslan Ermilov.Xr syslog 3
845a424c8cSRuslan Ermilov.Po
855a424c8cSRuslan Ermilovsee also
865a424c8cSRuslan Ermilov.Fl log_facility
875a424c8cSRuslan Ermilov.Pc .
8859a7c613SBrian Somers.It Fl log_facility Ar facility_name
895a424c8cSRuslan ErmilovUse specified log facility when logging information via
905a424c8cSRuslan Ermilov.Xr syslog 3 .
915a424c8cSRuslan ErmilovArgument
925a424c8cSRuslan Ermilov.Ar facility_name
935a424c8cSRuslan Ermilovis one of the keywords specified in
945a424c8cSRuslan Ermilov.Xr syslog.conf 5 .
9524084f9bSBrian Somers.It Fl use_sockets | s
9624084f9bSBrian SomersAllocate a
9724084f9bSBrian Somers.Xr socket 2
985a424c8cSRuslan Ermilovin order to establish an FTP data or IRC DCC send connection.
995a424c8cSRuslan ErmilovThis option uses more system resources, but guarantees successful
1005a424c8cSRuslan Ermilovconnections when port numbers conflict.
10124084f9bSBrian Somers.It Fl same_ports | m
10224084f9bSBrian SomersTry to keep the same port number when altering outgoing packets.
1037731ee5aSAlexander LangerWith this option, protocols such as RPC will have a better chance
1045a424c8cSRuslan Ermilovof working.
1055a424c8cSRuslan ErmilovIf it is not possible to maintain the port number, it will be silently
1065a424c8cSRuslan Ermilovchanged as per normal.
10724084f9bSBrian Somers.It Fl verbose | v
1085a424c8cSRuslan ErmilovDo not call
10924084f9bSBrian Somers.Xr daemon 3
1105a424c8cSRuslan Ermilovon startup.
111d2a46bc9SRuslan ErmilovInstead, stay attached to the controlling terminal and display all packet
1125a424c8cSRuslan Ermilovalterations to the standard output.
1135a424c8cSRuslan ErmilovThis option should only be used for debugging purposes.
11424084f9bSBrian Somers.It Fl unregistered_only | u
1155a424c8cSRuslan ErmilovOnly alter outgoing packets with an
1165a424c8cSRuslan Ermilov.Em unregistered
1175a424c8cSRuslan Ermilovsource address.
1185a424c8cSRuslan ErmilovAccording to RFC 1918, unregistered source addresses are 10.0.0.0/8,
1197731ee5aSAlexander Langer172.16.0.0/12 and 192.168.0.0/16.
1205a424c8cSRuslan Ermilov.It Fl redirect_port Ar proto Xo
1215a424c8cSRuslan Ermilov.Ar targetIP Ns : Ns Xo
1225a424c8cSRuslan Ermilov.Ar targetPORT Ns Op - Ns Ar targetPORT Xc
1235a424c8cSRuslan Ermilov.Op Ar aliasIP Ns : Ns Xo
1245a424c8cSRuslan Ermilov.Ar aliasPORT Ns Op - Ns Ar aliasPORT Xc
1255a424c8cSRuslan Ermilov.Oo Ar remoteIP Ns Oo : Ns
1265a424c8cSRuslan Ermilov.Ar remotePORT Ns Op - Ns Ar remotePORT
1275a424c8cSRuslan Ermilov.Oc Oc
1285a424c8cSRuslan Ermilov.Xc
1299c501140SBrian SomersRedirect incoming connections arriving to given port(s) to another host
1309c501140SBrian Somersand port(s).
1315a424c8cSRuslan ErmilovArgument
1325a424c8cSRuslan Ermilov.Ar proto
1335a424c8cSRuslan Ermilovis either
1345a424c8cSRuslan Ermilov.Ar tcp
1355a424c8cSRuslan Ermilovor
1365a424c8cSRuslan Ermilov.Ar udp ,
1375a424c8cSRuslan Ermilov.Ar targetIP
1385a424c8cSRuslan Ermilovis the desired target IP number,
1395a424c8cSRuslan Ermilov.Ar targetPORT
1405a424c8cSRuslan Ermilovis the desired target port number or range,
1415a424c8cSRuslan Ermilov.Ar aliasPORT
1425a424c8cSRuslan Ermilovis the requested port number or range, and
1435a424c8cSRuslan Ermilov.Ar aliasIP
1445a424c8cSRuslan Ermilovis the aliasing address.
1455a424c8cSRuslan ErmilovArguments
1465a424c8cSRuslan Ermilov.Ar remoteIP
1475a424c8cSRuslan Ermilovand
1485a424c8cSRuslan Ermilov.Ar remotePORT
1495a424c8cSRuslan Ermilovcan be used to specify the connection more accurately if necessary.
1505a424c8cSRuslan ErmilovThe
1515a424c8cSRuslan Ermilov.Ar targetPORT
1525a424c8cSRuslan Ermilovrange and
1535a424c8cSRuslan Ermilov.Ar aliasPORT
1545a424c8cSRuslan Ermilovrange need not be the same numerically, but must have the same size.
1555a424c8cSRuslan ErmilovIf
1565a424c8cSRuslan Ermilov.Ar remotePORT
1575a424c8cSRuslan Ermilovis not specified, it is assumed to be all ports.
1585a424c8cSRuslan ErmilovIf
1595a424c8cSRuslan Ermilov.Ar remotePORT
1605a424c8cSRuslan Ermilovis specified, it must match the size of
1615a424c8cSRuslan Ermilov.Ar targetPORT ,
1625a424c8cSRuslan Ermilovor be 0 (all ports).
1637731ee5aSAlexander LangerFor example, the argument
1645a424c8cSRuslan Ermilov.Pp
16566648838SBrian Somers.Dl Ar tcp inside1:telnet 6666
1665a424c8cSRuslan Ermilov.Pp
1675a424c8cSRuslan Ermilovmeans that incoming TCP packets destined for port 6666 on this machine
1685a424c8cSRuslan Ermilovwill be sent to the telnet port on the inside1 machine.
1695a424c8cSRuslan Ermilov.Pp
17066648838SBrian Somers.Dl Ar tcp inside2:2300-2399 3300-3399
1715a424c8cSRuslan Ermilov.Pp
1729c501140SBrian Somerswill redirect incoming connections on ports 3300-3399 to host
1739c501140SBrian Somersinside2, ports 2300-2399.
1749c501140SBrian SomersThe mapping is 1:1 meaning port 3300 maps to 2300, 3301 maps to 2301, etc.
1755a424c8cSRuslan Ermilov.It Fl redirect_proto Ar proto localIP Oo
1765a424c8cSRuslan Ermilov.Ar publicIP Op Ar remoteIP
1775a424c8cSRuslan Ermilov.Oc
1784330006dSRuslan ErmilovRedirect incoming IP packets of protocol
1794330006dSRuslan Ermilov.Ar proto
1805a424c8cSRuslan Ermilov.Po see Xr protocols 5
1815a424c8cSRuslan Ermilov.Pc
1824330006dSRuslan Ermilovdestined for
1834330006dSRuslan Ermilov.Ar publicIP
1844330006dSRuslan Ermilovaddress to a
1854330006dSRuslan Ermilov.Ar localIP
1864330006dSRuslan Ermilovaddress and vice versa.
1874330006dSRuslan Ermilov.Pp
1884330006dSRuslan ErmilovIf
1894330006dSRuslan Ermilov.Ar publicIP
1907731ee5aSAlexander Langeris not specified, then the default aliasing address is used.
1914330006dSRuslan ErmilovIf
1924330006dSRuslan Ermilov.Ar remoteIP
1937731ee5aSAlexander Langeris specified, then only packets coming from/to
1944330006dSRuslan Ermilov.Ar remoteIP
1954330006dSRuslan Ermilovwill match the rule.
19624084f9bSBrian Somers.It Fl redirect_address Ar localIP publicIP
1977731ee5aSAlexander LangerRedirect traffic for public IP address to a machine on the local
1987731ee5aSAlexander Langernetwork.
1995a424c8cSRuslan ErmilovThis function is known as
2005a424c8cSRuslan Ermilov.Em static NAT .
2015a424c8cSRuslan ErmilovNormally static NAT is useful if your ISP has allocated a small block
2025a424c8cSRuslan Ermilovof IP addresses to you, but it can even be used in the case of single
2035a424c8cSRuslan Ermilovaddress:
2045a424c8cSRuslan Ermilov.Pp
2055a424c8cSRuslan Ermilov.Dl Ar redirect_address 10.0.0.8 0.0.0.0
2065a424c8cSRuslan Ermilov.Pp
2077731ee5aSAlexander LangerThe above command would redirect all incoming traffic
2087731ee5aSAlexander Langerto machine 10.0.0.8.
2095a424c8cSRuslan Ermilov.Pp
2107731ee5aSAlexander LangerIf several address aliases specify the same public address
2117731ee5aSAlexander Langeras follows
2125a424c8cSRuslan Ermilov.Bd -literal -offset indent
2135a424c8cSRuslan Ermilov.Ar redirect_address 192.168.0.2 public_addr
2145a424c8cSRuslan Ermilov.Ar redirect_address 192.168.0.3 public_addr
2155a424c8cSRuslan Ermilov.Ar redirect_address 192.168.0.4 public_addr
2165a424c8cSRuslan Ermilov.Ed
2175a424c8cSRuslan Ermilov.Pp
21824084f9bSBrian Somersthe incoming traffic will be directed to the last
2197731ee5aSAlexander Langertranslated local address (192.168.0.4), but outgoing
2205a424c8cSRuslan Ermilovtraffic from the first two addresses will still be aliased
2215a424c8cSRuslan Ermilovto appear from the specified
2225a424c8cSRuslan Ermilov.Ar public_addr .
223bd690510SRuslan Ermilov.It Fl redirect_port Ar proto Xo
224bd690510SRuslan Ermilov.Ar targetIP Ns : Ns Xo
225bd690510SRuslan Ermilov.Ar targetPORT Ns Oo , Ns
226bd690510SRuslan Ermilov.Ar targetIP Ns : Ns Xo
227bd690510SRuslan Ermilov.Ar targetPORT Ns Oo , Ns
228d0353b83SRuslan Ermilov.Ar ...\&
229bd690510SRuslan Ermilov.Oc Oc
230bd690510SRuslan Ermilov.Xc
231bd690510SRuslan Ermilov.Xc
232bd690510SRuslan Ermilov.Op Ar aliasIP Ns : Ns Xo
233bd690510SRuslan Ermilov.Ar aliasPORT
234bd690510SRuslan Ermilov.Xc
235bd690510SRuslan Ermilov.Oo Ar remoteIP Ns
236bd690510SRuslan Ermilov.Op : Ns Ar remotePORT
237bd690510SRuslan Ermilov.Oc
238bd690510SRuslan Ermilov.Xc
239bd690510SRuslan Ermilov.It Fl redirect_address Xo
240bd690510SRuslan Ermilov.Ar localIP Ns Oo , Ns
241bd690510SRuslan Ermilov.Ar localIP Ns Oo , Ns
242d0353b83SRuslan Ermilov.Ar ...\&
243bd690510SRuslan Ermilov.Oc Oc
244bd690510SRuslan Ermilov.Ar publicIP
245bd690510SRuslan Ermilov.Xc
246bd690510SRuslan ErmilovThese forms of
247bd690510SRuslan Ermilov.Fl redirect_port
248bd690510SRuslan Ermilovand
249bd690510SRuslan Ermilov.Fl redirect_address
250bd690510SRuslan Ermilovare used to transparently offload network load on a single server and
251bd690510SRuslan Ermilovdistribute the load across a pool of servers.
252bd690510SRuslan ErmilovThis function is known as
253bd690510SRuslan Ermilov.Em LSNAT
254bd690510SRuslan Ermilov(RFC 2391).
2557731ee5aSAlexander LangerFor example, the argument
256bd690510SRuslan Ermilov.Pp
257bd690510SRuslan Ermilov.Dl Ar tcp www1:http,www2:http,www3:http www:http
258bd690510SRuslan Ermilov.Pp
259bd690510SRuslan Ermilovmeans that incoming HTTP requests for host www will be transparently
2607731ee5aSAlexander Langerredirected to one of the www1, www2 or www3, where a host is selected
2617731ee5aSAlexander Langersimply on a round-robin basis, without regard to load on the net.
26224084f9bSBrian Somers.It Fl dynamic
26324084f9bSBrian SomersIf the
26424084f9bSBrian Somers.Fl n
26524084f9bSBrian Somersor
26624084f9bSBrian Somers.Fl interface
26724084f9bSBrian Somersoption is used,
2680fc81af1SPhilippe Charnier.Nm
26924084f9bSBrian Somerswill monitor the routing socket for alterations to the
27024084f9bSBrian Somers.Ar interface
2715a424c8cSRuslan Ermilovpassed.
2725a424c8cSRuslan ErmilovIf the interface's IP number is changed,
2730fc81af1SPhilippe Charnier.Nm
27424084f9bSBrian Somerswill dynamically alter its concept of the alias address.
2755a424c8cSRuslan Ermilov.It Fl in_port | i Ar port
27624084f9bSBrian SomersRead from and write to
277d2a46bc9SRuslan Ermilov.Xr divert 4
278d2a46bc9SRuslan Ermilovport
27924084f9bSBrian Somers.Ar port ,
280d2a46bc9SRuslan Ermilovtreating all packets as
281d2a46bc9SRuslan Ermilov.Dq incoming .
2825a424c8cSRuslan Ermilov.It Fl out_port | o Ar port
2835a424c8cSRuslan ErmilovRead from and write to
284d2a46bc9SRuslan Ermilov.Xr divert 4
285d2a46bc9SRuslan Ermilovport
2865a424c8cSRuslan Ermilov.Ar port ,
287d2a46bc9SRuslan Ermilovtreating all packets as
288d2a46bc9SRuslan Ermilov.Dq outgoing .
2895a424c8cSRuslan Ermilov.It Fl port | p Ar port
2905a424c8cSRuslan ErmilovRead from and write to
291d2a46bc9SRuslan Ermilov.Xr divert 4
292d2a46bc9SRuslan Ermilovport
2935a424c8cSRuslan Ermilov.Ar port ,
294d2a46bc9SRuslan Ermilovdistinguishing packets as
295d2a46bc9SRuslan Ermilov.Dq incoming
296d2a46bc9SRuslan Ermilovor
297d2a46bc9SRuslan Ermilov.Dq outgoing
298d2a46bc9SRuslan Ermilovusing the rules specified in
29924084f9bSBrian Somers.Xr divert 4 .
30024084f9bSBrian SomersIf
30124084f9bSBrian Somers.Ar port
30224084f9bSBrian Somersis not numeric, it is searched for in the
30324084f9bSBrian Somers.Xr services 5
3045a424c8cSRuslan Ermilovdatabase.
3055a424c8cSRuslan ErmilovIf this option is not specified, the divert port named
306d2a46bc9SRuslan Ermilov.Ar natd
3075a424c8cSRuslan Ermilovwill be used as a default.
3085a424c8cSRuslan Ermilov.It Fl alias_address | a Ar address
30924084f9bSBrian SomersUse
31024084f9bSBrian Somers.Ar address
3115a424c8cSRuslan Ermilovas the aliasing address.
3125a424c8cSRuslan ErmilovIf this option is not specified, the
31324084f9bSBrian Somers.Fl interface
3145a424c8cSRuslan Ermilovoption must be used.
3155a424c8cSRuslan ErmilovThe specified address is usually the address assigned to the
316d2a46bc9SRuslan Ermilov.Dq public
317d2a46bc9SRuslan Ermilovnetwork interface.
318f7d1db72SBrian Somers.Pp
3195a424c8cSRuslan ErmilovAll data passing
3205a424c8cSRuslan Ermilov.Em out
3215a424c8cSRuslan Ermilovwill be rewritten with a source address equal to
322f7d1db72SBrian Somers.Ar address .
3235a424c8cSRuslan ErmilovAll data coming
3245a424c8cSRuslan Ermilov.Em in
3255a424c8cSRuslan Ermilovwill be checked to see if it matches any already-aliased outgoing
3265a424c8cSRuslan Ermilovconnection.
3275a424c8cSRuslan ErmilovIf it does, the packet is altered accordingly.
3285a424c8cSRuslan ErmilovIf not, all
3295a424c8cSRuslan Ermilov.Fl redirect_port ,
3305a424c8cSRuslan Ermilov.Fl redirect_proto
331f7d1db72SBrian Somersand
332f7d1db72SBrian Somers.Fl redirect_address
3335a424c8cSRuslan Ermilovassignments are checked and actioned.
3345a424c8cSRuslan ErmilovIf no other action can be made and if
335f7d1db72SBrian Somers.Fl deny_incoming
336d2a46bc9SRuslan Ermilovis not specified, the packet is delivered to the local machine
337d2a46bc9SRuslan Ermilovusing the rules specified in
3385a424c8cSRuslan Ermilov.Fl target_address
3395a424c8cSRuslan Ermilovoption below.
34011c2b3bfSRuslan Ermilov.It Fl t | target_address Ar address
34111c2b3bfSRuslan ErmilovSet the target address.
34211c2b3bfSRuslan ErmilovWhen an incoming packet not associated with any pre-existing link
3437731ee5aSAlexander Langerarrives at the host machine, it will be sent to the specified
34411c2b3bfSRuslan Ermilov.Ar address .
34511c2b3bfSRuslan Ermilov.Pp
34611c2b3bfSRuslan ErmilovThe target address may be set to
3475a424c8cSRuslan Ermilov.Ar 255.255.255.255 ,
34811c2b3bfSRuslan Ermilovin which case all new incoming packets go to the alias address set by
34911c2b3bfSRuslan Ermilov.Fl alias_address
35011c2b3bfSRuslan Ermilovor
35111c2b3bfSRuslan Ermilov.Fl interface .
35211c2b3bfSRuslan Ermilov.Pp
3537731ee5aSAlexander LangerIf this option is not used, or called with the argument
3545a424c8cSRuslan Ermilov.Ar 0.0.0.0 ,
3557731ee5aSAlexander Langerthen all new incoming packets go to the address specified in
3567731ee5aSAlexander Langerthe packet.
35711c2b3bfSRuslan ErmilovThis allows external machines to talk directly to internal machines if
35811c2b3bfSRuslan Ermilovthey can route packets to the machine in question.
3595a424c8cSRuslan Ermilov.It Fl interface | n Ar interface
36024084f9bSBrian SomersUse
36124084f9bSBrian Somers.Ar interface
3625a424c8cSRuslan Ermilovto determine the aliasing address.
3635a424c8cSRuslan ErmilovIf there is a possibility that the IP number associated with
36424084f9bSBrian Somers.Ar interface
36524084f9bSBrian Somersmay change, the
36624084f9bSBrian Somers.Fl dynamic
3675a424c8cSRuslan Ermilovoption should also be used.
3685a424c8cSRuslan ErmilovIf this option is not specified, the
36924084f9bSBrian Somers.Fl alias_address
3705a424c8cSRuslan Ermilovoption must be used.
371f7d1db72SBrian Somers.Pp
372f7d1db72SBrian SomersThe specified
373f7d1db72SBrian Somers.Ar interface
374d2a46bc9SRuslan Ermilovis usually the
375d2a46bc9SRuslan Ermilov.Dq public
376d2a46bc9SRuslan Ermilov(or
377d2a46bc9SRuslan Ermilov.Dq external )
378d2a46bc9SRuslan Ermilovnetwork interface.
3795a424c8cSRuslan Ermilov.It Fl config | f Ar file
38024084f9bSBrian SomersRead configuration from
3815a424c8cSRuslan Ermilov.Ar file .
3825a424c8cSRuslan ErmilovA
3835a424c8cSRuslan Ermilov.Ar file
3845a424c8cSRuslan Ermilovshould contain a list of options, one per line, in the same form
3855a424c8cSRuslan Ermilovas the long form of the above command line options.
3865a424c8cSRuslan ErmilovFor example, the line
3875a424c8cSRuslan Ermilov.Pp
3885a424c8cSRuslan Ermilov.Dl alias_address 158.152.17.1
3895a424c8cSRuslan Ermilov.Pp
3905a424c8cSRuslan Ermilovwould specify an alias address of 158.152.17.1.
391d2a46bc9SRuslan ErmilovOptions that do not take an argument are specified with an argument of
39224084f9bSBrian Somers.Ar yes
39324084f9bSBrian Somersor
39424084f9bSBrian Somers.Ar no
3955a424c8cSRuslan Ermilovin the configuration file.
3965a424c8cSRuslan ErmilovFor example, the line
3975a424c8cSRuslan Ermilov.Pp
3985a424c8cSRuslan Ermilov.Dl log yes
3995a424c8cSRuslan Ermilov.Pp
4005a424c8cSRuslan Ermilovis synonymous with
40124084f9bSBrian Somers.Fl log .
4022e7e7c71SRuslan Ermilov.Pp
4032e7e7c71SRuslan ErmilovTrailing spaces and empty lines are ignored.
4042e7e7c71SRuslan ErmilovA
4052e7e7c71SRuslan Ermilov.Ql \&#
4062522beceSMike Pritchardsign will mark the rest of the line as a comment.
40759a7c613SBrian Somers.It Fl reverse
4085a424c8cSRuslan ErmilovThis option makes
4095a424c8cSRuslan Ermilov.Nm
410d2a46bc9SRuslan Ermilovreverse the way it handles
411d2a46bc9SRuslan Ermilov.Dq incoming
412d2a46bc9SRuslan Ermilovand
413d2a46bc9SRuslan Ermilov.Dq outgoing
414d2a46bc9SRuslan Ermilovpackets, allowing it to operate on the
415d2a46bc9SRuslan Ermilov.Dq internal
416d2a46bc9SRuslan Ermilovnetwork interface rather than the
417d2a46bc9SRuslan Ermilov.Dq external
418d2a46bc9SRuslan Ermilovone.
4195a424c8cSRuslan Ermilov.Pp
4205a424c8cSRuslan ErmilovThis can be useful in some transparent proxying situations
4215a424c8cSRuslan Ermilovwhen outgoing traffic is redirected to the local machine
4225a424c8cSRuslan Ermilovand
4235a424c8cSRuslan Ermilov.Nm
4245a424c8cSRuslan Ermilovis running on the internal interface (it usually runs on the
4255a424c8cSRuslan Ermilovexternal interface).
42659a7c613SBrian Somers.It Fl proxy_only
4275a424c8cSRuslan ErmilovForce
4285a424c8cSRuslan Ermilov.Nm
4295a424c8cSRuslan Ermilovto perform transparent proxying only.
430ef8f7ac9SSheldon HearnNormal address translation is not performed.
4315a424c8cSRuslan Ermilov.It Fl proxy_rule Xo
4325a424c8cSRuslan Ermilov.Op Ar type encode_ip_hdr | encode_tcp_stream
4335a424c8cSRuslan Ermilov.Ar port xxxx
4345a424c8cSRuslan Ermilov.Ar server a.b.c.d:yyyy
4355a424c8cSRuslan Ermilov.Xc
436ef8f7ac9SSheldon HearnEnable transparent proxying.
4375a424c8cSRuslan ErmilovOutgoing TCP packets with the given port going through this
4387731ee5aSAlexander Langerhost to any other host are redirected to the given server and port.
439ef8f7ac9SSheldon HearnOptionally, the original target address can be encoded into the packet.
440ef8f7ac9SSheldon HearnUse
4415a424c8cSRuslan Ermilov.Ar encode_ip_hdr
44259a7c613SBrian Somersto put this information into the IP option field or
4435a424c8cSRuslan Ermilov.Ar encode_tcp_stream
44459a7c613SBrian Somersto inject the data into the beginning of the TCP stream.
445bc4ebb98SRuslan Ermilov.It Fl punch_fw Xo
446bc4ebb98SRuslan Ermilov.Ar basenumber Ns : Ns Ar count
447bc4ebb98SRuslan Ermilov.Xc
448f685a909SRuslan ErmilovThis option directs
449bc4ebb98SRuslan Ermilov.Nm
450f685a909SRuslan Ermilovto
451f685a909SRuslan Ermilov.Dq punch holes
452bc4ebb98SRuslan Ermilovin an
453bc4ebb98SRuslan Ermilov.Xr ipfirewall 4
454bc4ebb98SRuslan Ermilovbased firewall for FTP/IRC DCC connections.
455f685a909SRuslan ErmilovThis is done dynamically by installing temporary firewall rules which
456f685a909SRuslan Ermilovallow a particular connection (and only that connection) to go through
457f685a909SRuslan Ermilovthe firewall.
458f685a909SRuslan ErmilovThe rules are removed once the corresponding connection terminates.
459bc4ebb98SRuslan Ermilov.Pp
460f685a909SRuslan ErmilovA maximum of
461bc4ebb98SRuslan Ermilov.Ar count
462f685a909SRuslan Ermilovrules starting from the rule number
463f685a909SRuslan Ermilov.Ar basenumber
464f685a909SRuslan Ermilovwill be used for punching firewall holes.
465bc4ebb98SRuslan ErmilovThe range will be cleared for all rules on startup.
46624084f9bSBrian Somers.El
46724084f9bSBrian Somers.Sh RUNNING NATD
46824084f9bSBrian SomersThe following steps are necessary before attempting to run
4697c7fb079SRuslan Ermilov.Nm :
47024084f9bSBrian Somers.Bl -enum
47124084f9bSBrian Somers.It
47224084f9bSBrian SomersBuild a custom kernel with the following options:
4735a424c8cSRuslan Ermilov.Bd -literal -offset indent
47424084f9bSBrian Somersoptions IPFIREWALL
47524084f9bSBrian Somersoptions IPDIVERT
4765a424c8cSRuslan Ermilov.Ed
4775a424c8cSRuslan Ermilov.Pp
47824084f9bSBrian SomersRefer to the handbook for detailed instructions on building a custom
47924084f9bSBrian Somerskernel.
48024084f9bSBrian Somers.It
4815a424c8cSRuslan ErmilovEnsure that your machine is acting as a gateway.
4825a424c8cSRuslan ErmilovThis can be done by specifying the line
4835a424c8cSRuslan Ermilov.Pp
4845a424c8cSRuslan Ermilov.Dl gateway_enable=YES
4855a424c8cSRuslan Ermilov.Pp
4865a424c8cSRuslan Ermilovin the
4875a424c8cSRuslan Ermilov.Pa /etc/rc.conf
4885a424c8cSRuslan Ermilovfile or using the command
4895a424c8cSRuslan Ermilov.Pp
4905a424c8cSRuslan Ermilov.Dl sysctl -w net.inet.ip.forwarding=1
4915a424c8cSRuslan Ermilov.Pp
49224084f9bSBrian Somers.It
4935a424c8cSRuslan ErmilovIf you use the
49424084f9bSBrian Somers.Fl interface
4955a424c8cSRuslan Ermilovoption, make sure that your interface is already configured.
496d2a46bc9SRuslan ErmilovIf, for example, you wish to specify
497d2a46bc9SRuslan Ermilov.Ql tun0
498d2a46bc9SRuslan Ermilovas your
49924084f9bSBrian Somers.Ar interface ,
5005a424c8cSRuslan Ermilovand you are using
50124084f9bSBrian Somers.Xr ppp 8
5027731ee5aSAlexander Langeron that interface, you must make sure that you start
50324084f9bSBrian Somers.Nm ppp
50424084f9bSBrian Somersprior to starting
5057c7fb079SRuslan Ermilov.Nm .
50624084f9bSBrian Somers.El
50724084f9bSBrian Somers.Pp
50824084f9bSBrian SomersRunning
5090fc81af1SPhilippe Charnier.Nm
5105a424c8cSRuslan Ermilovis fairly straight forward.
5115a424c8cSRuslan ErmilovThe line
5125a424c8cSRuslan Ermilov.Pp
5135a424c8cSRuslan Ermilov.Dl natd -interface ed0
5145a424c8cSRuslan Ermilov.Pp
5155a424c8cSRuslan Ermilovshould suffice in most cases (substituting the correct interface name).
516ecd1fe62SRuslan ErmilovPlease check
517ecd1fe62SRuslan Ermilov.Xr rc.conf 5
518ecd1fe62SRuslan Ermilovon how to configure it to be started automatically during boot.
5195a424c8cSRuslan ErmilovOnce
5200fc81af1SPhilippe Charnier.Nm
5215a424c8cSRuslan Ermilovis running, you must ensure that traffic is diverted to
5227c7fb079SRuslan Ermilov.Nm :
52324084f9bSBrian Somers.Bl -enum
52424084f9bSBrian Somers.It
52524084f9bSBrian SomersYou will need to adjust the
52624084f9bSBrian Somers.Pa /etc/rc.firewall
5275a424c8cSRuslan Ermilovscript to taste.
5285a424c8cSRuslan ErmilovIf you are not interested in having a firewall, the
52924084f9bSBrian Somersfollowing lines will do:
5305a424c8cSRuslan Ermilov.Bd -literal -offset indent
53124084f9bSBrian Somers/sbin/ipfw -f flush
53246b2c559SBrian Somers/sbin/ipfw add divert natd all from any to any via ed0
53324084f9bSBrian Somers/sbin/ipfw add pass all from any to any
5345a424c8cSRuslan Ermilov.Ed
5355a424c8cSRuslan Ermilov.Pp
536d2a46bc9SRuslan ErmilovThe second line depends on your interface (change
537d2a46bc9SRuslan Ermilov.Ql ed0
538d2a46bc9SRuslan Ermilovas appropriate).
5395a424c8cSRuslan Ermilov.Pp
5405a424c8cSRuslan ErmilovYou should be aware of the fact that, with these firewall settings,
5415a424c8cSRuslan Ermiloveveryone on your local network can fake his source-address using your
5425a424c8cSRuslan Ermilovhost as gateway.
5435a424c8cSRuslan ErmilovIf there are other hosts on your local network, you are strongly
5445a424c8cSRuslan Ermilovencouraged to create firewall rules that only allow traffic to and
5455a424c8cSRuslan Ermilovfrom trusted hosts.
5465a424c8cSRuslan Ermilov.Pp
5475a424c8cSRuslan ErmilovIf you specify real firewall rules, it is best to specify line 2 at
5485a424c8cSRuslan Ermilovthe start of the script so that
5490fc81af1SPhilippe Charnier.Nm
55004bf7dcfSRuslan Ermilovsees all packets before they are dropped by the firewall.
55104bf7dcfSRuslan Ermilov.Pp
55204bf7dcfSRuslan ErmilovAfter translation by
5537c7fb079SRuslan Ermilov.Nm ,
55404bf7dcfSRuslan Ermilovpackets re-enter the firewall at the rule number following the rule number
5557731ee5aSAlexander Langerthat caused the diversion (not the next rule if there are several at the
5567731ee5aSAlexander Langersame number).
55724084f9bSBrian Somers.It
55824084f9bSBrian SomersEnable your firewall by setting
5595a424c8cSRuslan Ermilov.Pp
5605a424c8cSRuslan Ermilov.Dl firewall_enable=YES
5615a424c8cSRuslan Ermilov.Pp
56224084f9bSBrian Somersin
563c1b792b2SJordan K. Hubbard.Pa /etc/rc.conf .
56424084f9bSBrian SomersThis tells the system startup scripts to run the
56524084f9bSBrian Somers.Pa /etc/rc.firewall
5665a424c8cSRuslan Ermilovscript.
5675a424c8cSRuslan ErmilovIf you do not wish to reboot now, just run this by hand from the console.
5685a424c8cSRuslan ErmilovNEVER run this from a remote session unless you put it into the background.
5695a424c8cSRuslan ErmilovIf you do, you will lock yourself out after the flush takes place, and
5705a424c8cSRuslan Ermilovexecution of
57124084f9bSBrian Somers.Pa /etc/rc.firewall
5725a424c8cSRuslan Ermilovwill stop at this point - blocking all accesses permanently.
5735a424c8cSRuslan ErmilovRunning the script in the background should be enough to prevent this
5745a424c8cSRuslan Ermilovdisaster.
57524084f9bSBrian Somers.El
57624084f9bSBrian Somers.Sh SEE ALSO
57724084f9bSBrian Somers.Xr divert 4 ,
5785a424c8cSRuslan Ermilov.Xr protocols 5 ,
5795a424c8cSRuslan Ermilov.Xr rc.conf 5 ,
58024084f9bSBrian Somers.Xr services 5 ,
5815a424c8cSRuslan Ermilov.Xr syslog.conf 5 ,
5825a424c8cSRuslan Ermilov.Xr ipfw 8 ,
58332e5e4cfSBen Smithurst.Xr ppp 8
58424084f9bSBrian Somers.Sh AUTHORS
58524084f9bSBrian SomersThis program is the result of the efforts of many people at different
58624084f9bSBrian Somerstimes:
5875a424c8cSRuslan Ermilov.Pp
588f12a1471SPhilippe Charnier.An Archie Cobbs Aq archie@whistle.com
589f12a1471SPhilippe Charnier(divert sockets)
5907ffac027SBrian Somers.An Charles Mott Aq cmott@scientech.com
591f12a1471SPhilippe Charnier(packet aliasing)
592f12a1471SPhilippe Charnier.An Eivind Eklund Aq perhaps@yes.no
593f12a1471SPhilippe Charnier(IRC support & misc additions)
594f12a1471SPhilippe Charnier.An Ari Suutari Aq suutari@iki.fi
595f12a1471SPhilippe Charnier(natd)
59659a7c613SBrian Somers.An Dru Nelson Aq dnelson@redwoodsoft.com
597dc1a0225SRuslan Ermilov(early PPTP support)
598f12a1471SPhilippe Charnier.An Brian Somers Aq brian@awfulhak.org
599f12a1471SPhilippe Charnier(glue)
600d2a46bc9SRuslan Ermilov.An Ruslan Ermilov Aq ru@FreeBSD.org
601d2a46bc9SRuslan Ermilov(natd, packet aliasing, glue)
602