xref: /freebsd/sbin/natd/natd.8 (revision 72cbe4adf3ff8cd984d4edb39cde3bb468bb7299)
17f3dea24SPeter Wemm.\" $FreeBSD$
272cbe4adSAlexander Motin.Dd June 23, 2008
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
3198439aafSRuslan Ermilov.Op Fl instance Ar instancename
3298439aafSRuslan Ermilov.Op Fl globalport Ar port
335a424c8cSRuslan Ermilov.Op Fl log_denied
345a424c8cSRuslan Ermilov.Op Fl log_facility Ar facility_name
35bc4ebb98SRuslan Ermilov.Op Fl punch_fw Ar firewall_range
36b07fbc17SJoe Marcus Clarke.Op Fl skinny_port Ar port
3784ef95bdSPoul-Henning Kamp.Op Fl log_ipfw_denied
38b79840a6SRuslan Ermilov.Op Fl pid_file | P Ar pidfile
3972cbe4adSAlexander Motin.Op Fl exit_delay | P Ar ms
40d2a46bc9SRuslan Ermilov.Ek
4124084f9bSBrian Somers.Sh DESCRIPTION
42e1205e80SPhilippe CharnierThe
43e1205e80SPhilippe Charnier.Nm
44e1205e80SPhilippe Charnierutility provides a Network Address Translation facility for use
4524084f9bSBrian Somerswith
4624084f9bSBrian Somers.Xr divert 4
475a424c8cSRuslan Ermilovsockets under
485a424c8cSRuslan Ermilov.Fx .
4901ba618fSRuslan Ermilov.Pp
5001ba618fSRuslan Ermilov(If you need NAT on a PPP link,
5101ba618fSRuslan Ermilov.Xr ppp 8
5201ba618fSRuslan Ermilovprovides the
535a424c8cSRuslan Ermilov.Fl nat
5401ba618fSRuslan Ermilovoption that gives most of the
5501ba618fSRuslan Ermilov.Nm
5601ba618fSRuslan Ermilovfunctionality, and uses the same
5701ba618fSRuslan Ermilov.Xr libalias 3
5801ba618fSRuslan Ermilovlibrary.)
5924084f9bSBrian Somers.Pp
605a424c8cSRuslan ErmilovThe
615a424c8cSRuslan Ermilov.Nm
62e1205e80SPhilippe Charnierutility normally runs in the background as a daemon.
635a424c8cSRuslan ErmilovIt is passed raw IP packets as they travel into and out of the machine,
645a424c8cSRuslan Ermilovand will possibly change these before re-injecting them back into the
655a424c8cSRuslan ErmilovIP packet stream.
6624084f9bSBrian Somers.Pp
675a424c8cSRuslan ErmilovIt changes all packets destined for another host so that their source
685105f991SRuslan ErmilovIP address is that of the current machine.
695a424c8cSRuslan ErmilovFor each packet changed in this manner, an internal table entry is
705a424c8cSRuslan Ermilovcreated to record this fact.
715a424c8cSRuslan ErmilovThe source port number is also changed to indicate the table entry
725a424c8cSRuslan Ermilovapplying to the packet.
735a424c8cSRuslan ErmilovPackets that are received with a target IP of the current host are
745a424c8cSRuslan Ermilovchecked against this internal table.
755a424c8cSRuslan ErmilovIf an entry is found, it is used to determine the correct target IP
765105f991SRuslan Ermilovaddress and port to place in the packet.
7724084f9bSBrian Somers.Pp
78d2a46bc9SRuslan ErmilovThe following command line options are available:
7924084f9bSBrian Somers.Bl -tag -width Fl
8024084f9bSBrian Somers.It Fl log | l
8124084f9bSBrian SomersLog various aliasing statistics and information to the file
8224084f9bSBrian Somers.Pa /var/log/alias.log .
835a424c8cSRuslan ErmilovThis file is truncated each time
845a424c8cSRuslan Ermilov.Nm
855a424c8cSRuslan Ermilovis started.
8624084f9bSBrian Somers.It Fl deny_incoming | d
87d2a46bc9SRuslan ErmilovDo not pass incoming packets that have no
885a424c8cSRuslan Ermiloventry in the internal translation table.
89d2a46bc9SRuslan Ermilov.Pp
90d2a46bc9SRuslan ErmilovIf this option is not used, then such a packet will be altered
91d2a46bc9SRuslan Ermilovusing the rules in
92d2a46bc9SRuslan Ermilov.Fl target_address
93d2a46bc9SRuslan Ermilovbelow, and the entry will be made in the internal translation table.
9459a7c613SBrian Somers.It Fl log_denied
955a424c8cSRuslan ErmilovLog denied incoming packets via
965a424c8cSRuslan Ermilov.Xr syslog 3
97c4d9468eSRuslan Ermilov(see also
98c4d9468eSRuslan Ermilov.Fl log_facility ) .
9959a7c613SBrian Somers.It Fl log_facility Ar facility_name
1005a424c8cSRuslan ErmilovUse specified log facility when logging information via
1015a424c8cSRuslan Ermilov.Xr syslog 3 .
1025a424c8cSRuslan ErmilovArgument
1035a424c8cSRuslan Ermilov.Ar facility_name
1045a424c8cSRuslan Ermilovis one of the keywords specified in
1055a424c8cSRuslan Ermilov.Xr syslog.conf 5 .
10624084f9bSBrian Somers.It Fl use_sockets | s
10724084f9bSBrian SomersAllocate a
10824084f9bSBrian Somers.Xr socket 2
1095a424c8cSRuslan Ermilovin order to establish an FTP data or IRC DCC send connection.
1105a424c8cSRuslan ErmilovThis option uses more system resources, but guarantees successful
1115a424c8cSRuslan Ermilovconnections when port numbers conflict.
11224084f9bSBrian Somers.It Fl same_ports | m
11324084f9bSBrian SomersTry to keep the same port number when altering outgoing packets.
1147731ee5aSAlexander LangerWith this option, protocols such as RPC will have a better chance
1155a424c8cSRuslan Ermilovof working.
1165a424c8cSRuslan ErmilovIf it is not possible to maintain the port number, it will be silently
1175a424c8cSRuslan Ermilovchanged as per normal.
11824084f9bSBrian Somers.It Fl verbose | v
1195a424c8cSRuslan ErmilovDo not call
12024084f9bSBrian Somers.Xr daemon 3
1215a424c8cSRuslan Ermilovon startup.
122d2a46bc9SRuslan ErmilovInstead, stay attached to the controlling terminal and display all packet
1235a424c8cSRuslan Ermilovalterations to the standard output.
1245a424c8cSRuslan ErmilovThis option should only be used for debugging purposes.
12524084f9bSBrian Somers.It Fl unregistered_only | u
1265a424c8cSRuslan ErmilovOnly alter outgoing packets with an
1275a424c8cSRuslan Ermilov.Em unregistered
1285a424c8cSRuslan Ermilovsource address.
1295a424c8cSRuslan ErmilovAccording to RFC 1918, unregistered source addresses are 10.0.0.0/8,
1307731ee5aSAlexander Langer172.16.0.0/12 and 192.168.0.0/16.
1315a424c8cSRuslan Ermilov.It Fl redirect_port Ar proto Xo
1325a424c8cSRuslan Ermilov.Ar targetIP Ns : Ns Xo
1335a424c8cSRuslan Ermilov.Ar targetPORT Ns Op - Ns Ar targetPORT Xc
1345a424c8cSRuslan Ermilov.Op Ar aliasIP Ns : Ns Xo
1355a424c8cSRuslan Ermilov.Ar aliasPORT Ns Op - Ns Ar aliasPORT Xc
1365a424c8cSRuslan Ermilov.Oo Ar remoteIP Ns Oo : Ns
1375a424c8cSRuslan Ermilov.Ar remotePORT Ns Op - Ns Ar remotePORT
1385a424c8cSRuslan Ermilov.Oc Oc
1395a424c8cSRuslan Ermilov.Xc
1409c501140SBrian SomersRedirect incoming connections arriving to given port(s) to another host
1419c501140SBrian Somersand port(s).
1425a424c8cSRuslan ErmilovArgument
1435a424c8cSRuslan Ermilov.Ar proto
1445a424c8cSRuslan Ermilovis either
1455a424c8cSRuslan Ermilov.Ar tcp
1465a424c8cSRuslan Ermilovor
1475a424c8cSRuslan Ermilov.Ar udp ,
1485a424c8cSRuslan Ermilov.Ar targetIP
1495105f991SRuslan Ermilovis the desired target IP address,
1505a424c8cSRuslan Ermilov.Ar targetPORT
1515a424c8cSRuslan Ermilovis the desired target port number or range,
1525a424c8cSRuslan Ermilov.Ar aliasPORT
1535a424c8cSRuslan Ermilovis the requested port number or range, and
1545a424c8cSRuslan Ermilov.Ar aliasIP
1555a424c8cSRuslan Ermilovis the aliasing address.
1565a424c8cSRuslan ErmilovArguments
1575a424c8cSRuslan Ermilov.Ar remoteIP
1585a424c8cSRuslan Ermilovand
1595a424c8cSRuslan Ermilov.Ar remotePORT
1605a424c8cSRuslan Ermilovcan be used to specify the connection more accurately if necessary.
1615a424c8cSRuslan ErmilovIf
1625a424c8cSRuslan Ermilov.Ar remotePORT
1635a424c8cSRuslan Ermilovis not specified, it is assumed to be all ports.
1645105f991SRuslan Ermilov.Pp
1655105f991SRuslan ErmilovArguments
1665105f991SRuslan Ermilov.Ar targetIP , aliasIP
1675105f991SRuslan Ermilovand
1685105f991SRuslan Ermilov.Ar remoteIP
1695105f991SRuslan Ermilovcan be given as IP addresses or as hostnames.
1705105f991SRuslan ErmilovThe
1715105f991SRuslan Ermilov.Ar targetPORT , aliasPORT
1725105f991SRuslan Ermilovand
1735a424c8cSRuslan Ermilov.Ar remotePORT
1745105f991SRuslan Ermilovranges need not be the same numerically, but must have the same size.
1755105f991SRuslan ErmilovWhen
1765105f991SRuslan Ermilov.Ar targetPORT , aliasPORT
1775105f991SRuslan Ermilovor
1785105f991SRuslan Ermilov.Ar remotePORT
1795105f991SRuslan Ermilovspecifies a singular value (not a range), it can be given as a service
1805105f991SRuslan Ermilovname that is searched for in the
1815105f991SRuslan Ermilov.Xr services 5
1825105f991SRuslan Ermilovdatabase.
1835105f991SRuslan Ermilov.Pp
1847731ee5aSAlexander LangerFor example, the argument
1855a424c8cSRuslan Ermilov.Pp
18666648838SBrian Somers.Dl Ar tcp inside1:telnet 6666
1875a424c8cSRuslan Ermilov.Pp
1885a424c8cSRuslan Ermilovmeans that incoming TCP packets destined for port 6666 on this machine
1895a424c8cSRuslan Ermilovwill be sent to the telnet port on the inside1 machine.
1905a424c8cSRuslan Ermilov.Pp
19166648838SBrian Somers.Dl Ar tcp inside2:2300-2399 3300-3399
1925a424c8cSRuslan Ermilov.Pp
1939c501140SBrian Somerswill redirect incoming connections on ports 3300-3399 to host
1949c501140SBrian Somersinside2, ports 2300-2399.
1959c501140SBrian SomersThe mapping is 1:1 meaning port 3300 maps to 2300, 3301 maps to 2301, etc.
1965a424c8cSRuslan Ermilov.It Fl redirect_proto Ar proto localIP Oo
1975a424c8cSRuslan Ermilov.Ar publicIP Op Ar remoteIP
1985a424c8cSRuslan Ermilov.Oc
1994330006dSRuslan ErmilovRedirect incoming IP packets of protocol
2004330006dSRuslan Ermilov.Ar proto
201c4d9468eSRuslan Ermilov(see
202c4d9468eSRuslan Ermilov.Xr protocols 5 )
2034330006dSRuslan Ermilovdestined for
2044330006dSRuslan Ermilov.Ar publicIP
2054330006dSRuslan Ermilovaddress to a
2064330006dSRuslan Ermilov.Ar localIP
2074330006dSRuslan Ermilovaddress and vice versa.
2084330006dSRuslan Ermilov.Pp
2094330006dSRuslan ErmilovIf
2104330006dSRuslan Ermilov.Ar publicIP
2117731ee5aSAlexander Langeris not specified, then the default aliasing address is used.
2124330006dSRuslan ErmilovIf
2134330006dSRuslan Ermilov.Ar remoteIP
2147731ee5aSAlexander Langeris specified, then only packets coming from/to
2154330006dSRuslan Ermilov.Ar remoteIP
2164330006dSRuslan Ermilovwill match the rule.
21724084f9bSBrian Somers.It Fl redirect_address Ar localIP publicIP
2187731ee5aSAlexander LangerRedirect traffic for public IP address to a machine on the local
2197731ee5aSAlexander Langernetwork.
2205a424c8cSRuslan ErmilovThis function is known as
2215a424c8cSRuslan Ermilov.Em static NAT .
2225a424c8cSRuslan ErmilovNormally static NAT is useful if your ISP has allocated a small block
2235a424c8cSRuslan Ermilovof IP addresses to you, but it can even be used in the case of single
2245a424c8cSRuslan Ermilovaddress:
2255a424c8cSRuslan Ermilov.Pp
2265a424c8cSRuslan Ermilov.Dl Ar redirect_address 10.0.0.8 0.0.0.0
2275a424c8cSRuslan Ermilov.Pp
2287731ee5aSAlexander LangerThe above command would redirect all incoming traffic
2297731ee5aSAlexander Langerto machine 10.0.0.8.
2305a424c8cSRuslan Ermilov.Pp
2317731ee5aSAlexander LangerIf several address aliases specify the same public address
2327731ee5aSAlexander Langeras follows
2335a424c8cSRuslan Ermilov.Bd -literal -offset indent
2346a5796e7SRuslan Ermilovredirect_address 192.168.0.2 public_addr
2356a5796e7SRuslan Ermilovredirect_address 192.168.0.3 public_addr
2366a5796e7SRuslan Ermilovredirect_address 192.168.0.4 public_addr
2375a424c8cSRuslan Ermilov.Ed
2385a424c8cSRuslan Ermilov.Pp
23924084f9bSBrian Somersthe incoming traffic will be directed to the last
2407731ee5aSAlexander Langertranslated local address (192.168.0.4), but outgoing
2415a424c8cSRuslan Ermilovtraffic from the first two addresses will still be aliased
2425a424c8cSRuslan Ermilovto appear from the specified
2435a424c8cSRuslan Ermilov.Ar public_addr .
244bd690510SRuslan Ermilov.It Fl redirect_port Ar proto Xo
245bd690510SRuslan Ermilov.Ar targetIP Ns : Ns Xo
246bd690510SRuslan Ermilov.Ar targetPORT Ns Oo , Ns
247bd690510SRuslan Ermilov.Ar targetIP Ns : Ns Xo
248bd690510SRuslan Ermilov.Ar targetPORT Ns Oo , Ns
249d0353b83SRuslan Ermilov.Ar ...\&
250bd690510SRuslan Ermilov.Oc Oc
251bd690510SRuslan Ermilov.Xc
252bd690510SRuslan Ermilov.Xc
253bd690510SRuslan Ermilov.Op Ar aliasIP Ns : Ns Xo
254bd690510SRuslan Ermilov.Ar aliasPORT
255bd690510SRuslan Ermilov.Xc
256bd690510SRuslan Ermilov.Oo Ar remoteIP Ns
257bd690510SRuslan Ermilov.Op : Ns Ar remotePORT
258bd690510SRuslan Ermilov.Oc
259bd690510SRuslan Ermilov.Xc
260bd690510SRuslan Ermilov.It Fl redirect_address Xo
261bd690510SRuslan Ermilov.Ar localIP Ns Oo , Ns
262bd690510SRuslan Ermilov.Ar localIP Ns Oo , Ns
263d0353b83SRuslan Ermilov.Ar ...\&
264bd690510SRuslan Ermilov.Oc Oc
265bd690510SRuslan Ermilov.Ar publicIP
266bd690510SRuslan Ermilov.Xc
267bd690510SRuslan ErmilovThese forms of
268bd690510SRuslan Ermilov.Fl redirect_port
269bd690510SRuslan Ermilovand
270bd690510SRuslan Ermilov.Fl redirect_address
271bd690510SRuslan Ermilovare used to transparently offload network load on a single server and
272bd690510SRuslan Ermilovdistribute the load across a pool of servers.
273bd690510SRuslan ErmilovThis function is known as
274bd690510SRuslan Ermilov.Em LSNAT
275bd690510SRuslan Ermilov(RFC 2391).
2767731ee5aSAlexander LangerFor example, the argument
277bd690510SRuslan Ermilov.Pp
278bd690510SRuslan Ermilov.Dl Ar tcp www1:http,www2:http,www3:http www:http
279bd690510SRuslan Ermilov.Pp
280bd690510SRuslan Ermilovmeans that incoming HTTP requests for host www will be transparently
2817731ee5aSAlexander Langerredirected to one of the www1, www2 or www3, where a host is selected
2827731ee5aSAlexander Langersimply on a round-robin basis, without regard to load on the net.
28324084f9bSBrian Somers.It Fl dynamic
28424084f9bSBrian SomersIf the
28524084f9bSBrian Somers.Fl n
28624084f9bSBrian Somersor
28724084f9bSBrian Somers.Fl interface
28824084f9bSBrian Somersoption is used,
2890fc81af1SPhilippe Charnier.Nm
29024084f9bSBrian Somerswill monitor the routing socket for alterations to the
29124084f9bSBrian Somers.Ar interface
2925a424c8cSRuslan Ermilovpassed.
2935105f991SRuslan ErmilovIf the interface's IP address is changed,
2940fc81af1SPhilippe Charnier.Nm
29524084f9bSBrian Somerswill dynamically alter its concept of the alias address.
2965a424c8cSRuslan Ermilov.It Fl in_port | i Ar port
29724084f9bSBrian SomersRead from and write to
298d2a46bc9SRuslan Ermilov.Xr divert 4
299d2a46bc9SRuslan Ermilovport
30024084f9bSBrian Somers.Ar port ,
301d2a46bc9SRuslan Ermilovtreating all packets as
302d2a46bc9SRuslan Ermilov.Dq incoming .
3035a424c8cSRuslan Ermilov.It Fl out_port | o Ar port
3045a424c8cSRuslan ErmilovRead from and write to
305d2a46bc9SRuslan Ermilov.Xr divert 4
306d2a46bc9SRuslan Ermilovport
3075a424c8cSRuslan Ermilov.Ar port ,
308d2a46bc9SRuslan Ermilovtreating all packets as
309d2a46bc9SRuslan Ermilov.Dq outgoing .
3105a424c8cSRuslan Ermilov.It Fl port | p Ar port
3115a424c8cSRuslan ErmilovRead from and write to
312d2a46bc9SRuslan Ermilov.Xr divert 4
313d2a46bc9SRuslan Ermilovport
3145a424c8cSRuslan Ermilov.Ar port ,
315d2a46bc9SRuslan Ermilovdistinguishing packets as
316d2a46bc9SRuslan Ermilov.Dq incoming
317d2a46bc9SRuslan Ermilovor
318d2a46bc9SRuslan Ermilov.Dq outgoing
319d2a46bc9SRuslan Ermilovusing the rules specified in
32024084f9bSBrian Somers.Xr divert 4 .
32124084f9bSBrian SomersIf
32224084f9bSBrian Somers.Ar port
32324084f9bSBrian Somersis not numeric, it is searched for in the
32424084f9bSBrian Somers.Xr services 5
3255a424c8cSRuslan Ermilovdatabase.
3265a424c8cSRuslan ErmilovIf this option is not specified, the divert port named
327d2a46bc9SRuslan Ermilov.Ar natd
3285a424c8cSRuslan Ermilovwill be used as a default.
3295a424c8cSRuslan Ermilov.It Fl alias_address | a Ar address
33024084f9bSBrian SomersUse
33124084f9bSBrian Somers.Ar address
3325a424c8cSRuslan Ermilovas the aliasing address.
3333d23e8b8SRuslan ErmilovEither this or the
33424084f9bSBrian Somers.Fl interface
3353d23e8b8SRuslan Ermilovoption must be used (but not both),
3363d23e8b8SRuslan Ermilovif the
3373d23e8b8SRuslan Ermilov.Fl proxy_only
3383d23e8b8SRuslan Ermilovoption is not specified.
3395a424c8cSRuslan ErmilovThe specified address is usually the address assigned to the
340d2a46bc9SRuslan Ermilov.Dq public
341d2a46bc9SRuslan Ermilovnetwork interface.
342f7d1db72SBrian Somers.Pp
3435a424c8cSRuslan ErmilovAll data passing
3445a424c8cSRuslan Ermilov.Em out
3455a424c8cSRuslan Ermilovwill be rewritten with a source address equal to
346f7d1db72SBrian Somers.Ar address .
3475a424c8cSRuslan ErmilovAll data coming
3485a424c8cSRuslan Ermilov.Em in
3495a424c8cSRuslan Ermilovwill be checked to see if it matches any already-aliased outgoing
3505a424c8cSRuslan Ermilovconnection.
3515a424c8cSRuslan ErmilovIf it does, the packet is altered accordingly.
3525a424c8cSRuslan ErmilovIf not, all
3535a424c8cSRuslan Ermilov.Fl redirect_port ,
3545a424c8cSRuslan Ermilov.Fl redirect_proto
355f7d1db72SBrian Somersand
356f7d1db72SBrian Somers.Fl redirect_address
3575a424c8cSRuslan Ermilovassignments are checked and actioned.
3585a424c8cSRuslan ErmilovIf no other action can be made and if
359f7d1db72SBrian Somers.Fl deny_incoming
360d2a46bc9SRuslan Ermilovis not specified, the packet is delivered to the local machine
361d2a46bc9SRuslan Ermilovusing the rules specified in
3625a424c8cSRuslan Ermilov.Fl target_address
3635a424c8cSRuslan Ermilovoption below.
36411c2b3bfSRuslan Ermilov.It Fl t | target_address Ar address
36511c2b3bfSRuslan ErmilovSet the target address.
36611c2b3bfSRuslan ErmilovWhen an incoming packet not associated with any pre-existing link
3677731ee5aSAlexander Langerarrives at the host machine, it will be sent to the specified
36811c2b3bfSRuslan Ermilov.Ar address .
36911c2b3bfSRuslan Ermilov.Pp
37011c2b3bfSRuslan ErmilovThe target address may be set to
3715a424c8cSRuslan Ermilov.Ar 255.255.255.255 ,
37211c2b3bfSRuslan Ermilovin which case all new incoming packets go to the alias address set by
37311c2b3bfSRuslan Ermilov.Fl alias_address
37411c2b3bfSRuslan Ermilovor
37511c2b3bfSRuslan Ermilov.Fl interface .
37611c2b3bfSRuslan Ermilov.Pp
3777731ee5aSAlexander LangerIf this option is not used, or called with the argument
3785a424c8cSRuslan Ermilov.Ar 0.0.0.0 ,
3797731ee5aSAlexander Langerthen all new incoming packets go to the address specified in
3807731ee5aSAlexander Langerthe packet.
38111c2b3bfSRuslan ErmilovThis allows external machines to talk directly to internal machines if
38211c2b3bfSRuslan Ermilovthey can route packets to the machine in question.
3835a424c8cSRuslan Ermilov.It Fl interface | n Ar interface
38424084f9bSBrian SomersUse
38524084f9bSBrian Somers.Ar interface
3865a424c8cSRuslan Ermilovto determine the aliasing address.
3875105f991SRuslan ErmilovIf there is a possibility that the IP address associated with
38824084f9bSBrian Somers.Ar interface
38924084f9bSBrian Somersmay change, the
39024084f9bSBrian Somers.Fl dynamic
3915a424c8cSRuslan Ermilovoption should also be used.
3925a424c8cSRuslan ErmilovIf this option is not specified, the
39324084f9bSBrian Somers.Fl alias_address
3945a424c8cSRuslan Ermilovoption must be used.
395f7d1db72SBrian Somers.Pp
396f7d1db72SBrian SomersThe specified
397f7d1db72SBrian Somers.Ar interface
398d2a46bc9SRuslan Ermilovis usually the
399d2a46bc9SRuslan Ermilov.Dq public
400d2a46bc9SRuslan Ermilov(or
401d2a46bc9SRuslan Ermilov.Dq external )
402d2a46bc9SRuslan Ermilovnetwork interface.
4035a424c8cSRuslan Ermilov.It Fl config | f Ar file
40424084f9bSBrian SomersRead configuration from
4055a424c8cSRuslan Ermilov.Ar file .
4065a424c8cSRuslan ErmilovA
4075a424c8cSRuslan Ermilov.Ar file
4085a424c8cSRuslan Ermilovshould contain a list of options, one per line, in the same form
4095a424c8cSRuslan Ermilovas the long form of the above command line options.
4105a424c8cSRuslan ErmilovFor example, the line
4115a424c8cSRuslan Ermilov.Pp
4125a424c8cSRuslan Ermilov.Dl alias_address 158.152.17.1
4135a424c8cSRuslan Ermilov.Pp
4145a424c8cSRuslan Ermilovwould specify an alias address of 158.152.17.1.
415d2a46bc9SRuslan ErmilovOptions that do not take an argument are specified with an argument of
41624084f9bSBrian Somers.Ar yes
41724084f9bSBrian Somersor
41824084f9bSBrian Somers.Ar no
4195a424c8cSRuslan Ermilovin the configuration file.
4205a424c8cSRuslan ErmilovFor example, the line
4215a424c8cSRuslan Ermilov.Pp
4225a424c8cSRuslan Ermilov.Dl log yes
4235a424c8cSRuslan Ermilov.Pp
4245a424c8cSRuslan Ermilovis synonymous with
42524084f9bSBrian Somers.Fl log .
4262e7e7c71SRuslan Ermilov.Pp
427057c6548SMaxim KonovalovOptions can be divided to several sections.
428057c6548SMaxim KonovalovEach section applies to own
429c80d9b59SPoul-Henning Kamp.Nm
430057c6548SMaxim Konovalovinstance.
431057c6548SMaxim KonovalovThis ability allows to configure one
432c80d9b59SPoul-Henning Kamp.Nm
433057c6548SMaxim Konovalovprocess for several NAT instances.
434057c6548SMaxim KonovalovThe first instance that always exists is a "default" instance.
435057c6548SMaxim KonovalovEach another instance should begin with
436c80d9b59SPoul-Henning Kamp.Pp
437c80d9b59SPoul-Henning Kamp.Dl instance Ar instance_name
438c80d9b59SPoul-Henning Kamp.Pp
439057c6548SMaxim KonovalovAt the next should be placed a configuration option.
440057c6548SMaxim KonovalovExample:
441c80d9b59SPoul-Henning Kamp.Pp
442c80d9b59SPoul-Henning Kamp.Dl \&# default instance
443c80d9b59SPoul-Henning Kamp.Dl port 8668
444c80d9b59SPoul-Henning Kamp.Dl alias_address 158.152.17.1
445c80d9b59SPoul-Henning Kamp.Pp
446c80d9b59SPoul-Henning Kamp.Dl \&# second instance
447c80d9b59SPoul-Henning Kamp.Dl instance dsl1
448c80d9b59SPoul-Henning Kamp.Dl port 8888
449c80d9b59SPoul-Henning Kamp.Dl alias_address 192.168.0.1
450c80d9b59SPoul-Henning Kamp.Pp
4512e7e7c71SRuslan ErmilovTrailing spaces and empty lines are ignored.
4522e7e7c71SRuslan ErmilovA
4532e7e7c71SRuslan Ermilov.Ql \&#
4542522beceSMike Pritchardsign will mark the rest of the line as a comment.
45598439aafSRuslan Ermilov.It Fl instance Ar instancename
45698439aafSRuslan ErmilovThis option switches command line options processing to configure instance
45798439aafSRuslan Ermilov.Ar instancename
45898439aafSRuslan Ermilov(creating it if necessary) till the next
45998439aafSRuslan Ermilov.Fl instance
46098439aafSRuslan Ermilovoption or end of command line.
46198439aafSRuslan ErmilovIt is easier to set up multiple instances in the configuration file
46298439aafSRuslan Ermilovspecified with the
46398439aafSRuslan Ermilov.Fl config
46498439aafSRuslan Ermilovoption rather than on a command line.
46598439aafSRuslan Ermilov.It Fl globalport Ar port
46698439aafSRuslan ErmilovRead from and write to
46798439aafSRuslan Ermilov.Xr divert 4
46898439aafSRuslan Ermilovport
46998439aafSRuslan Ermilov.Ar port ,
47098439aafSRuslan Ermilovtreating all packets as
47198439aafSRuslan Ermilov.Dq outgoing .
47298439aafSRuslan ErmilovThis option is intended to be used with multiple instances:
47398439aafSRuslan Ermilovpackets received on this port are checked against
47498439aafSRuslan Ermilovinternal translation tables of every configured instance.
47598439aafSRuslan ErmilovIf an entry is found, packet is aliased according to that entry.
47698439aafSRuslan ErmilovIn no entry was found in any of the instances, packet is passed
47798439aafSRuslan Ermilovunchanged, and no new entry will be created.
47898439aafSRuslan ErmilovSee the section
47998439aafSRuslan Ermilov.Sx MULTIPLE INSTANCES
48098439aafSRuslan Ermilovfor more details.
48159a7c613SBrian Somers.It Fl reverse
4825a424c8cSRuslan ErmilovThis option makes
4835a424c8cSRuslan Ermilov.Nm
484d2a46bc9SRuslan Ermilovreverse the way it handles
485d2a46bc9SRuslan Ermilov.Dq incoming
486d2a46bc9SRuslan Ermilovand
487d2a46bc9SRuslan Ermilov.Dq outgoing
488d2a46bc9SRuslan Ermilovpackets, allowing it to operate on the
489d2a46bc9SRuslan Ermilov.Dq internal
490d2a46bc9SRuslan Ermilovnetwork interface rather than the
491d2a46bc9SRuslan Ermilov.Dq external
492d2a46bc9SRuslan Ermilovone.
4935a424c8cSRuslan Ermilov.Pp
4945a424c8cSRuslan ErmilovThis can be useful in some transparent proxying situations
4955a424c8cSRuslan Ermilovwhen outgoing traffic is redirected to the local machine
4965a424c8cSRuslan Ermilovand
4975a424c8cSRuslan Ermilov.Nm
4985a424c8cSRuslan Ermilovis running on the internal interface (it usually runs on the
4995a424c8cSRuslan Ermilovexternal interface).
50059a7c613SBrian Somers.It Fl proxy_only
5015a424c8cSRuslan ErmilovForce
5025a424c8cSRuslan Ermilov.Nm
5035a424c8cSRuslan Ermilovto perform transparent proxying only.
504ef8f7ac9SSheldon HearnNormal address translation is not performed.
5055a424c8cSRuslan Ermilov.It Fl proxy_rule Xo
5065a424c8cSRuslan Ermilov.Op Ar type encode_ip_hdr | encode_tcp_stream
5075a424c8cSRuslan Ermilov.Ar port xxxx
5085a424c8cSRuslan Ermilov.Ar server a.b.c.d:yyyy
5095a424c8cSRuslan Ermilov.Xc
510ef8f7ac9SSheldon HearnEnable transparent proxying.
5115a424c8cSRuslan ErmilovOutgoing TCP packets with the given port going through this
5127731ee5aSAlexander Langerhost to any other host are redirected to the given server and port.
513ef8f7ac9SSheldon HearnOptionally, the original target address can be encoded into the packet.
514ef8f7ac9SSheldon HearnUse
5155a424c8cSRuslan Ermilov.Ar encode_ip_hdr
51659a7c613SBrian Somersto put this information into the IP option field or
5175a424c8cSRuslan Ermilov.Ar encode_tcp_stream
51859a7c613SBrian Somersto inject the data into the beginning of the TCP stream.
519bc4ebb98SRuslan Ermilov.It Fl punch_fw Xo
520bc4ebb98SRuslan Ermilov.Ar basenumber Ns : Ns Ar count
521bc4ebb98SRuslan Ermilov.Xc
522f685a909SRuslan ErmilovThis option directs
523bc4ebb98SRuslan Ermilov.Nm
524f685a909SRuslan Ermilovto
525f685a909SRuslan Ermilov.Dq punch holes
526bc4ebb98SRuslan Ermilovin an
527bc4ebb98SRuslan Ermilov.Xr ipfirewall 4
528bc4ebb98SRuslan Ermilovbased firewall for FTP/IRC DCC connections.
529f685a909SRuslan ErmilovThis is done dynamically by installing temporary firewall rules which
530f685a909SRuslan Ermilovallow a particular connection (and only that connection) to go through
531f685a909SRuslan Ermilovthe firewall.
532f685a909SRuslan ErmilovThe rules are removed once the corresponding connection terminates.
533bc4ebb98SRuslan Ermilov.Pp
534f685a909SRuslan ErmilovA maximum of
535bc4ebb98SRuslan Ermilov.Ar count
536f685a909SRuslan Ermilovrules starting from the rule number
537f685a909SRuslan Ermilov.Ar basenumber
538f685a909SRuslan Ermilovwill be used for punching firewall holes.
539bc4ebb98SRuslan ErmilovThe range will be cleared for all rules on startup.
540e30ba475STom RhodesThis option has no effect when the kernel is in security
541e30ba475STom Rhodeslevel 3, see
542e30ba475STom Rhodes.Xr init 8
543e30ba475STom Rhodesfor more information.
544b07fbc17SJoe Marcus Clarke.It Fl skinny_port Ar port
545b07fbc17SJoe Marcus ClarkeThis option allows you to specify the TCP port used for
546b07fbc17SJoe Marcus Clarkethe Skinny Station protocol.
547b07fbc17SJoe Marcus ClarkeSkinny is used by Cisco IP phones to communicate with
548b07fbc17SJoe Marcus ClarkeCisco Call Managers to set up voice over IP calls.
549b07fbc17SJoe Marcus ClarkeBy default, Skinny aliasing is not performed.
550b07fbc17SJoe Marcus ClarkeThe typical port value for Skinny is 2000.
55184ef95bdSPoul-Henning Kamp.It Fl log_ipfw_denied
5523843533eSRuslan ErmilovLog when a packet cannot be re-injected because an
5533843533eSRuslan Ermilov.Xr ipfw 8
5543843533eSRuslan Ermilovrule blocks it.
555c0956cf8SRuslan ErmilovThis is the default with
556c0956cf8SRuslan Ermilov.Fl verbose .
557b79840a6SRuslan Ermilov.It Fl pid_file | P Ar file
558b79840a6SRuslan ErmilovSpecify an alternate file in which to store the process ID.
559b79840a6SRuslan ErmilovThe default is
560b79840a6SRuslan Ermilov.Pa /var/run/natd.pid .
56172cbe4adSAlexander Motin.It Fl exit_delay Ar ms
56272cbe4adSAlexander MotinSpecify delay in ms before daemon exit after signal.
56372cbe4adSAlexander MotinThe default is
56472cbe4adSAlexander Motin.Pa 10000 .
56524084f9bSBrian Somers.El
56624084f9bSBrian Somers.Sh RUNNING NATD
56724084f9bSBrian SomersThe following steps are necessary before attempting to run
5687c7fb079SRuslan Ermilov.Nm :
56924084f9bSBrian Somers.Bl -enum
57024084f9bSBrian Somers.It
57124084f9bSBrian SomersBuild a custom kernel with the following options:
5725a424c8cSRuslan Ermilov.Bd -literal -offset indent
57324084f9bSBrian Somersoptions IPFIREWALL
57424084f9bSBrian Somersoptions IPDIVERT
5755a424c8cSRuslan Ermilov.Ed
5765a424c8cSRuslan Ermilov.Pp
57724084f9bSBrian SomersRefer to the handbook for detailed instructions on building a custom
57824084f9bSBrian Somerskernel.
57924084f9bSBrian Somers.It
5805a424c8cSRuslan ErmilovEnsure that your machine is acting as a gateway.
5815a424c8cSRuslan ErmilovThis can be done by specifying the line
5825a424c8cSRuslan Ermilov.Pp
5835a424c8cSRuslan Ermilov.Dl gateway_enable=YES
5845a424c8cSRuslan Ermilov.Pp
5855a424c8cSRuslan Ermilovin the
5865a424c8cSRuslan Ermilov.Pa /etc/rc.conf
5875a424c8cSRuslan Ermilovfile or using the command
5885a424c8cSRuslan Ermilov.Pp
589e21a315eSRuslan Ermilov.Dl "sysctl net.inet.ip.forwarding=1"
5905a424c8cSRuslan Ermilov.Pp
59124084f9bSBrian Somers.It
5925a424c8cSRuslan ErmilovIf you use the
59324084f9bSBrian Somers.Fl interface
5945a424c8cSRuslan Ermilovoption, make sure that your interface is already configured.
595d2a46bc9SRuslan ErmilovIf, for example, you wish to specify
596d2a46bc9SRuslan Ermilov.Ql tun0
597d2a46bc9SRuslan Ermilovas your
59824084f9bSBrian Somers.Ar interface ,
5995a424c8cSRuslan Ermilovand you are using
60024084f9bSBrian Somers.Xr ppp 8
6017731ee5aSAlexander Langeron that interface, you must make sure that you start
60224084f9bSBrian Somers.Nm ppp
60324084f9bSBrian Somersprior to starting
6047c7fb079SRuslan Ermilov.Nm .
60524084f9bSBrian Somers.El
60624084f9bSBrian Somers.Pp
60724084f9bSBrian SomersRunning
6080fc81af1SPhilippe Charnier.Nm
6095a424c8cSRuslan Ermilovis fairly straight forward.
6105a424c8cSRuslan ErmilovThe line
6115a424c8cSRuslan Ermilov.Pp
6125a424c8cSRuslan Ermilov.Dl natd -interface ed0
6135a424c8cSRuslan Ermilov.Pp
6145a424c8cSRuslan Ermilovshould suffice in most cases (substituting the correct interface name).
615ecd1fe62SRuslan ErmilovPlease check
616ecd1fe62SRuslan Ermilov.Xr rc.conf 5
617ecd1fe62SRuslan Ermilovon how to configure it to be started automatically during boot.
6185a424c8cSRuslan ErmilovOnce
6190fc81af1SPhilippe Charnier.Nm
6205a424c8cSRuslan Ermilovis running, you must ensure that traffic is diverted to
6217c7fb079SRuslan Ermilov.Nm :
62224084f9bSBrian Somers.Bl -enum
62324084f9bSBrian Somers.It
62424084f9bSBrian SomersYou will need to adjust the
62524084f9bSBrian Somers.Pa /etc/rc.firewall
6265a424c8cSRuslan Ermilovscript to taste.
6275a424c8cSRuslan ErmilovIf you are not interested in having a firewall, the
62824084f9bSBrian Somersfollowing lines will do:
6295a424c8cSRuslan Ermilov.Bd -literal -offset indent
63024084f9bSBrian Somers/sbin/ipfw -f flush
63146b2c559SBrian Somers/sbin/ipfw add divert natd all from any to any via ed0
63224084f9bSBrian Somers/sbin/ipfw add pass all from any to any
6335a424c8cSRuslan Ermilov.Ed
6345a424c8cSRuslan Ermilov.Pp
635d2a46bc9SRuslan ErmilovThe second line depends on your interface (change
636d2a46bc9SRuslan Ermilov.Ql ed0
637d2a46bc9SRuslan Ermilovas appropriate).
6385a424c8cSRuslan Ermilov.Pp
6395a424c8cSRuslan ErmilovYou should be aware of the fact that, with these firewall settings,
6405a424c8cSRuslan Ermiloveveryone on your local network can fake his source-address using your
6415a424c8cSRuslan Ermilovhost as gateway.
6425a424c8cSRuslan ErmilovIf there are other hosts on your local network, you are strongly
6435a424c8cSRuslan Ermilovencouraged to create firewall rules that only allow traffic to and
6445a424c8cSRuslan Ermilovfrom trusted hosts.
6455a424c8cSRuslan Ermilov.Pp
6465a424c8cSRuslan ErmilovIf you specify real firewall rules, it is best to specify line 2 at
6475a424c8cSRuslan Ermilovthe start of the script so that
6480fc81af1SPhilippe Charnier.Nm
64904bf7dcfSRuslan Ermilovsees all packets before they are dropped by the firewall.
65004bf7dcfSRuslan Ermilov.Pp
65104bf7dcfSRuslan ErmilovAfter translation by
6527c7fb079SRuslan Ermilov.Nm ,
65304bf7dcfSRuslan Ermilovpackets re-enter the firewall at the rule number following the rule number
6547731ee5aSAlexander Langerthat caused the diversion (not the next rule if there are several at the
6557731ee5aSAlexander Langersame number).
65624084f9bSBrian Somers.It
65724084f9bSBrian SomersEnable your firewall by setting
6585a424c8cSRuslan Ermilov.Pp
6595a424c8cSRuslan Ermilov.Dl firewall_enable=YES
6605a424c8cSRuslan Ermilov.Pp
66124084f9bSBrian Somersin
662c1b792b2SJordan K. Hubbard.Pa /etc/rc.conf .
66324084f9bSBrian SomersThis tells the system startup scripts to run the
66424084f9bSBrian Somers.Pa /etc/rc.firewall
6655a424c8cSRuslan Ermilovscript.
6665a424c8cSRuslan ErmilovIf you do not wish to reboot now, just run this by hand from the console.
6675a424c8cSRuslan ErmilovNEVER run this from a remote session unless you put it into the background.
6685a424c8cSRuslan ErmilovIf you do, you will lock yourself out after the flush takes place, and
6695a424c8cSRuslan Ermilovexecution of
67024084f9bSBrian Somers.Pa /etc/rc.firewall
6715a424c8cSRuslan Ermilovwill stop at this point - blocking all accesses permanently.
6725a424c8cSRuslan ErmilovRunning the script in the background should be enough to prevent this
6735a424c8cSRuslan Ermilovdisaster.
67424084f9bSBrian Somers.El
67598439aafSRuslan Ermilov.Sh MULTIPLE INSTANCES
67698439aafSRuslan ErmilovIt is not so uncommon to have a need of aliasing to several external IP
67798439aafSRuslan Ermilovaddresses.
67898439aafSRuslan ErmilovWhile this traditionally was achieved by running several
67998439aafSRuslan Ermilov.Nm
68098439aafSRuslan Ermilovprocesses with independent configurations,
68198439aafSRuslan Ermilov.Nm
68298439aafSRuslan Ermilovcan have multiple aliasing instances in a single process,
68398439aafSRuslan Ermilovalso allowing them to be not so independent of each other.
68498439aafSRuslan ErmilovFor example, let us see a common task of load balancing two
68598439aafSRuslan Ermilovchannels to different providers on a machine with two external
68698439aafSRuslan Ermilovinterfaces
68798439aafSRuslan Ermilov.Ql sis0
68898439aafSRuslan Ermilov(with IP 1.2.3.4) and
68998439aafSRuslan Ermilov.Ql sis2
69098439aafSRuslan Ermilov(with IP 2.3.4.5):
69198439aafSRuslan Ermilov.Bd -literal -offset indent
69298439aafSRuslan Ermilov          net 1.2.3.0/24
69398439aafSRuslan Ermilov1.2.3.1 ------------------ sis0
69498439aafSRuslan Ermilov(router)                (1.2.3.4)
69598439aafSRuslan Ermilov                                         net 10.0.0.0/24
69698439aafSRuslan Ermilov                                  sis1 ------------------- 10.0.0.2
69798439aafSRuslan Ermilov                               (10.0.0.1)
69898439aafSRuslan Ermilov          net 2.3.4.0/24
69998439aafSRuslan Ermilov2.3.4.1 ------------------ sis2
70098439aafSRuslan Ermilov(router)                (2.3.4.5)
70198439aafSRuslan Ermilov.Ed
70298439aafSRuslan Ermilov.Pp
70398439aafSRuslan ErmilovDefault route is out via
70498439aafSRuslan Ermilov.Ql sis0 .
70598439aafSRuslan Ermilov.Pp
70698439aafSRuslan ErmilovInterior machine (10.0.0.2) is accessible on TCP port 122 through
70798439aafSRuslan Ermilovboth exterior IPs, and outgoing connections choose a path randomly
70898439aafSRuslan Ermilovbetween
70998439aafSRuslan Ermilov.Ql sis0
71098439aafSRuslan Ermilovand
71198439aafSRuslan Ermilov.Ql sis2 .
71298439aafSRuslan Ermilov.Pp
71398439aafSRuslan ErmilovThe way this works is that
71498439aafSRuslan Ermilov.Pa natd.conf
71598439aafSRuslan Ermilovbuilds two instances of the aliasing engine.
71698439aafSRuslan Ermilov.Pp
71798439aafSRuslan ErmilovIn addition to these instances' private
71898439aafSRuslan Ermilov.Xr divert 4
71998439aafSRuslan Ermilovsockets, a third socket called the
72098439aafSRuslan Ermilov.Dq globalport
72198439aafSRuslan Ermilovis created; packets sent to
72298439aafSRuslan Ermilov.Nm
72398439aafSRuslan Ermilovvia this one will be matched against all instances and translated
72498439aafSRuslan Ermilovif an existing entry is found, and unchanged if no entry is found.
72598439aafSRuslan ErmilovThe following lines are placed into
72698439aafSRuslan Ermilov.Pa /etc/natd.conf :
72798439aafSRuslan Ermilov.Bd -literal -offset indent
72898439aafSRuslan Ermilovlog
72998439aafSRuslan Ermilovdeny_incoming
73098439aafSRuslan Ermilovverbose
73198439aafSRuslan Ermilov
73298439aafSRuslan Ermilovinstance default
73398439aafSRuslan Ermilovinterface sis0
73498439aafSRuslan Ermilovport 1000
73598439aafSRuslan Ermilovredirect_port tcp 10.0.0.2:122 122
73698439aafSRuslan Ermilov
73798439aafSRuslan Ermilovinstance sis2
73898439aafSRuslan Ermilovinterface sis2
73998439aafSRuslan Ermilovport 2000
74098439aafSRuslan Ermilovredirect_port tcp 10.0.0.2:122 122
74198439aafSRuslan Ermilov
74298439aafSRuslan Ermilovglobalport 3000
74398439aafSRuslan Ermilov.Ed
74498439aafSRuslan Ermilov.Pp
74598439aafSRuslan ErmilovAnd the following
74698439aafSRuslan Ermilov.Xr ipfw 8
74798439aafSRuslan Ermilovrules are used:
74898439aafSRuslan Ermilov.Bd -literal -offset indent
74998439aafSRuslan Ermilovipfw -f flush
75098439aafSRuslan Ermilov
75198439aafSRuslan Ermilovipfw add      allow ip from any to any via sis1
75298439aafSRuslan Ermilov
75398439aafSRuslan Ermilovipfw add      skipto 1000 ip from any to any in via sis0
75498439aafSRuslan Ermilovipfw add      skipto 2000 ip from any to any out via sis0
75598439aafSRuslan Ermilovipfw add      skipto 3000 ip from any to any in via sis2
75698439aafSRuslan Ermilovipfw add      skipto 4000 ip from any to any out via sis2
75798439aafSRuslan Ermilov
75898439aafSRuslan Ermilovipfw add 1000 count ip from any to any
75998439aafSRuslan Ermilov
76098439aafSRuslan Ermilovipfw add      divert 1000 ip from any to any
76198439aafSRuslan Ermilovipfw add      allow ip from any to any
76298439aafSRuslan Ermilov
76398439aafSRuslan Ermilovipfw add 2000 count ip from any to any
76498439aafSRuslan Ermilov
76598439aafSRuslan Ermilovipfw add      divert 3000 ip from any to any
76698439aafSRuslan Ermilov
76798439aafSRuslan Ermilovipfw add      allow ip from 1.2.3.4 to any
76898439aafSRuslan Ermilovipfw add      skipto 5000 ip from 2.3.4.5 to any
76998439aafSRuslan Ermilov
77098439aafSRuslan Ermilovipfw add      prob .5 skipto 4000 ip from any to any
77198439aafSRuslan Ermilov
77298439aafSRuslan Ermilovipfw add      divert 1000 ip from any to any
77398439aafSRuslan Ermilovipfw add      allow ip from any to any
77498439aafSRuslan Ermilov
77598439aafSRuslan Ermilovipfw add 3000 count ip from any to any
77698439aafSRuslan Ermilov
77798439aafSRuslan Ermilovipfw add      divert 2000 ip from any to any
77898439aafSRuslan Ermilovipfw add      allow ip from any to any
77998439aafSRuslan Ermilov
78098439aafSRuslan Ermilovipfw add 4000 count ip from any to any
78198439aafSRuslan Ermilov
78298439aafSRuslan Ermilovipfw add      divert 2000 ip from any to any
78398439aafSRuslan Ermilov
78498439aafSRuslan Ermilovipfw add 5000 fwd 2.3.4.1 ip from 2.3.4.5 to not 2.3.4.0/24
78598439aafSRuslan Ermilovipfw add      allow ip from any to any
78698439aafSRuslan Ermilov.Ed
78798439aafSRuslan Ermilov.Pp
78898439aafSRuslan ErmilovHere the packet from internal network to Internet goes out via
78998439aafSRuslan Ermilov.Ql sis0
79098439aafSRuslan Ermilov(rule number 2000) and gets catched by the
79198439aafSRuslan Ermilov.Ic globalport
79298439aafSRuslan Ermilovsocket (3000).
79398439aafSRuslan ErmilovAfter that, either a match is found in a translation table
79498439aafSRuslan Ermilovof one of the two instances, or the packet is passed to one
79598439aafSRuslan Ermilovof the two other
79698439aafSRuslan Ermilov.Xr divert 4
79798439aafSRuslan Ermilovports (1000 or 2000), with equal probability.
79898439aafSRuslan ErmilovThis ensures that load balancing is done on a per-flow basis
79998439aafSRuslan Ermilov(i.e., packets from a single TCP connection always flow through the
80098439aafSRuslan Ermilovsame interface).
80198439aafSRuslan ErmilovTranslated packets with source IP of a non-default interface
80298439aafSRuslan Ermilov.Pq Ql sis2
80398439aafSRuslan Ermilovare forwarded to the appropriate router on that interface.
80424084f9bSBrian Somers.Sh SEE ALSO
80501ba618fSRuslan Ermilov.Xr libalias 3 ,
80624084f9bSBrian Somers.Xr divert 4 ,
8075a424c8cSRuslan Ermilov.Xr protocols 5 ,
8085a424c8cSRuslan Ermilov.Xr rc.conf 5 ,
80924084f9bSBrian Somers.Xr services 5 ,
8105a424c8cSRuslan Ermilov.Xr syslog.conf 5 ,
811e30ba475STom Rhodes.Xr init 8 ,
8125a424c8cSRuslan Ermilov.Xr ipfw 8 ,
81332e5e4cfSBen Smithurst.Xr ppp 8
81424084f9bSBrian Somers.Sh AUTHORS
81524084f9bSBrian SomersThis program is the result of the efforts of many people at different
81624084f9bSBrian Somerstimes:
8175a424c8cSRuslan Ermilov.Pp
818aa7998d4SRuslan Ermilov.An Archie Cobbs Aq archie@FreeBSD.org
819f12a1471SPhilippe Charnier(divert sockets)
820496f81e0SRuslan Ermilov.An Charles Mott Aq cm@linktel.net
821f12a1471SPhilippe Charnier(packet aliasing)
822f12a1471SPhilippe Charnier.An Eivind Eklund Aq perhaps@yes.no
823f12a1471SPhilippe Charnier(IRC support & misc additions)
824f12a1471SPhilippe Charnier.An Ari Suutari Aq suutari@iki.fi
825f12a1471SPhilippe Charnier(natd)
82659a7c613SBrian Somers.An Dru Nelson Aq dnelson@redwoodsoft.com
827dc1a0225SRuslan Ermilov(early PPTP support)
828f12a1471SPhilippe Charnier.An Brian Somers Aq brian@awfulhak.org
829f12a1471SPhilippe Charnier(glue)
830d2a46bc9SRuslan Ermilov.An Ruslan Ermilov Aq ru@FreeBSD.org
831d2a46bc9SRuslan Ermilov(natd, packet aliasing, glue)
83298439aafSRuslan Ermilov.An Poul-Henning Kamp Aq phk@FreeBSD.org
83398439aafSRuslan Ermilov(multiple instances)
834