xref: /freebsd/sbin/natd/natd.8 (revision ef18594985c0d569650b44b0ba0171a6fd8703a5)
1*ef185949SDamjan Jovanovic.Dd December 6, 2024
224084f9bSBrian Somers.Dt NATD 8
39fe48c6eSRuslan Ermilov.Os
424084f9bSBrian Somers.Sh NAME
524084f9bSBrian Somers.Nm natd
6eb083802SRuslan Ermilov.Nd Network Address Translation daemon
724084f9bSBrian Somers.Sh SYNOPSIS
87c7fb079SRuslan Ermilov.Nm
9d2a46bc9SRuslan Ermilov.Bk -words
105a424c8cSRuslan Ermilov.Op Fl unregistered_only | u
115a424c8cSRuslan Ermilov.Op Fl log | l
125a424c8cSRuslan Ermilov.Op Fl proxy_only
135a424c8cSRuslan Ermilov.Op Fl reverse
145a424c8cSRuslan Ermilov.Op Fl deny_incoming | d
155a424c8cSRuslan Ermilov.Op Fl use_sockets | s
165a424c8cSRuslan Ermilov.Op Fl same_ports | m
17*ef185949SDamjan Jovanovic.Op Fl udp_eim
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.
118*ef185949SDamjan Jovanovic.It Fl udp_eim
119*ef185949SDamjan JovanovicWhen enabled, UDP packets use endpoint-independent mapping (EIM) from RFC 4787
120*ef185949SDamjan Jovanovic("full cone" NAT of RFC 3489).
121*ef185949SDamjan JovanovicAll packets from the same internal address:port are mapped to the same NAT
122*ef185949SDamjan Jovanovicaddress:port, regardless of their destination address:port.
123*ef185949SDamjan JovanovicIf filtering rules allow, and if
124*ef185949SDamjan Jovanovic.Em deny_incoming
125*ef185949SDamjan Jovanovicis disabled, any other external address:port can
126*ef185949SDamjan Jovanovicalso send to the internal address:port through its mapped NAT address:port.
127*ef185949SDamjan JovanovicThis is more compatible with applications, and can reduce the need for port
128*ef185949SDamjan Jovanovicforwarding, but less scalable as each NAT address:port can only be
129*ef185949SDamjan Jovanovicconcurrently used by at most one internal address:port.
130*ef185949SDamjan Jovanovic.Pp
131*ef185949SDamjan JovanovicWhen disabled, UDP packets use endpoint-dependent mapping (EDM) ("symmetric"
132*ef185949SDamjan JovanovicNAT).
133*ef185949SDamjan JovanovicEach connection from a particular internal address:port to different
134*ef185949SDamjan Jovanovicexternal addresses:ports is mapped to a random and unpredictable NAT
135*ef185949SDamjan Jovanovicaddress:port.
136*ef185949SDamjan JovanovicTwo appplications behind EDM NATs can only connect to each other
137*ef185949SDamjan Jovanovicby port forwarding on the NAT, or tunnelling through an in-between server.
13824084f9bSBrian Somers.It Fl verbose | v
1395a424c8cSRuslan ErmilovDo not call
14024084f9bSBrian Somers.Xr daemon 3
1415a424c8cSRuslan Ermilovon startup.
142d2a46bc9SRuslan ErmilovInstead, stay attached to the controlling terminal and display all packet
1435a424c8cSRuslan Ermilovalterations to the standard output.
1445a424c8cSRuslan ErmilovThis option should only be used for debugging purposes.
14524084f9bSBrian Somers.It Fl unregistered_only | u
1465a424c8cSRuslan ErmilovOnly alter outgoing packets with an
1475a424c8cSRuslan Ermilov.Em unregistered
1485a424c8cSRuslan Ermilovsource address.
1495a424c8cSRuslan ErmilovAccording to RFC 1918, unregistered source addresses are 10.0.0.0/8,
1507731ee5aSAlexander Langer172.16.0.0/12 and 192.168.0.0/16.
1515a424c8cSRuslan Ermilov.It Fl redirect_port Ar proto Xo
1525a424c8cSRuslan Ermilov.Ar targetIP Ns : Ns Xo
1539760b0e0SJoel Dahl.Ar targetPORT Ns Oo - Ns Ar targetPORT Oc Xc
1549760b0e0SJoel Dahl.Oo Ar aliasIP Ns : Oc Ns Xo
1559760b0e0SJoel Dahl.Ar aliasPORT Ns Oo - Ns Ar aliasPORT Oc Xc
1565a424c8cSRuslan Ermilov.Oo Ar remoteIP Ns Oo : Ns
1575a424c8cSRuslan Ermilov.Ar remotePORT Ns Op - Ns Ar remotePORT
1585a424c8cSRuslan Ermilov.Oc Oc
1595a424c8cSRuslan Ermilov.Xc
1609c501140SBrian SomersRedirect incoming connections arriving to given port(s) to another host
1619c501140SBrian Somersand port(s).
1625a424c8cSRuslan ErmilovArgument
1635a424c8cSRuslan Ermilov.Ar proto
1645a424c8cSRuslan Ermilovis either
1655a424c8cSRuslan Ermilov.Ar tcp
1665a424c8cSRuslan Ermilovor
1675a424c8cSRuslan Ermilov.Ar udp ,
1685a424c8cSRuslan Ermilov.Ar targetIP
1695105f991SRuslan Ermilovis the desired target IP address,
1705a424c8cSRuslan Ermilov.Ar targetPORT
1715a424c8cSRuslan Ermilovis the desired target port number or range,
1725a424c8cSRuslan Ermilov.Ar aliasPORT
1735a424c8cSRuslan Ermilovis the requested port number or range, and
1745a424c8cSRuslan Ermilov.Ar aliasIP
1755a424c8cSRuslan Ermilovis the aliasing address.
1765a424c8cSRuslan ErmilovArguments
1775a424c8cSRuslan Ermilov.Ar remoteIP
1785a424c8cSRuslan Ermilovand
1795a424c8cSRuslan Ermilov.Ar remotePORT
1805a424c8cSRuslan Ermilovcan be used to specify the connection more accurately if necessary.
1815a424c8cSRuslan ErmilovIf
1825a424c8cSRuslan Ermilov.Ar remotePORT
1835a424c8cSRuslan Ermilovis not specified, it is assumed to be all ports.
1845105f991SRuslan Ermilov.Pp
1855105f991SRuslan ErmilovArguments
1865105f991SRuslan Ermilov.Ar targetIP , aliasIP
1875105f991SRuslan Ermilovand
1885105f991SRuslan Ermilov.Ar remoteIP
1895105f991SRuslan Ermilovcan be given as IP addresses or as hostnames.
1905105f991SRuslan ErmilovThe
1915105f991SRuslan Ermilov.Ar targetPORT , aliasPORT
1925105f991SRuslan Ermilovand
1935a424c8cSRuslan Ermilov.Ar remotePORT
1945105f991SRuslan Ermilovranges need not be the same numerically, but must have the same size.
1955105f991SRuslan ErmilovWhen
1965105f991SRuslan Ermilov.Ar targetPORT , aliasPORT
1975105f991SRuslan Ermilovor
1985105f991SRuslan Ermilov.Ar remotePORT
1995105f991SRuslan Ermilovspecifies a singular value (not a range), it can be given as a service
2005105f991SRuslan Ermilovname that is searched for in the
2015105f991SRuslan Ermilov.Xr services 5
2025105f991SRuslan Ermilovdatabase.
2035105f991SRuslan Ermilov.Pp
2047731ee5aSAlexander LangerFor example, the argument
2055a424c8cSRuslan Ermilov.Pp
20666648838SBrian Somers.Dl Ar tcp inside1:telnet 6666
2075a424c8cSRuslan Ermilov.Pp
2085a424c8cSRuslan Ermilovmeans that incoming TCP packets destined for port 6666 on this machine
2095a424c8cSRuslan Ermilovwill be sent to the telnet port on the inside1 machine.
2105a424c8cSRuslan Ermilov.Pp
21166648838SBrian Somers.Dl Ar tcp inside2:2300-2399 3300-3399
2125a424c8cSRuslan Ermilov.Pp
2139c501140SBrian Somerswill redirect incoming connections on ports 3300-3399 to host
2149c501140SBrian Somersinside2, ports 2300-2399.
2159c501140SBrian SomersThe mapping is 1:1 meaning port 3300 maps to 2300, 3301 maps to 2301, etc.
2165a424c8cSRuslan Ermilov.It Fl redirect_proto Ar proto localIP Oo
2175a424c8cSRuslan Ermilov.Ar publicIP Op Ar remoteIP
2185a424c8cSRuslan Ermilov.Oc
2194330006dSRuslan ErmilovRedirect incoming IP packets of protocol
2204330006dSRuslan Ermilov.Ar proto
221c4d9468eSRuslan Ermilov(see
222c4d9468eSRuslan Ermilov.Xr protocols 5 )
2234330006dSRuslan Ermilovdestined for
2244330006dSRuslan Ermilov.Ar publicIP
2254330006dSRuslan Ermilovaddress to a
2264330006dSRuslan Ermilov.Ar localIP
2274330006dSRuslan Ermilovaddress and vice versa.
2284330006dSRuslan Ermilov.Pp
2294330006dSRuslan ErmilovIf
2304330006dSRuslan Ermilov.Ar publicIP
2317731ee5aSAlexander Langeris not specified, then the default aliasing address is used.
2324330006dSRuslan ErmilovIf
2334330006dSRuslan Ermilov.Ar remoteIP
2347731ee5aSAlexander Langeris specified, then only packets coming from/to
2354330006dSRuslan Ermilov.Ar remoteIP
2364330006dSRuslan Ermilovwill match the rule.
23724084f9bSBrian Somers.It Fl redirect_address Ar localIP publicIP
2387731ee5aSAlexander LangerRedirect traffic for public IP address to a machine on the local
2397731ee5aSAlexander Langernetwork.
2405a424c8cSRuslan ErmilovThis function is known as
2415a424c8cSRuslan Ermilov.Em static NAT .
2425a424c8cSRuslan ErmilovNormally static NAT is useful if your ISP has allocated a small block
2435a424c8cSRuslan Ermilovof IP addresses to you, but it can even be used in the case of single
2445a424c8cSRuslan Ermilovaddress:
2455a424c8cSRuslan Ermilov.Pp
2465a424c8cSRuslan Ermilov.Dl Ar redirect_address 10.0.0.8 0.0.0.0
2475a424c8cSRuslan Ermilov.Pp
2487731ee5aSAlexander LangerThe above command would redirect all incoming traffic
2497731ee5aSAlexander Langerto machine 10.0.0.8.
2505a424c8cSRuslan Ermilov.Pp
2517731ee5aSAlexander LangerIf several address aliases specify the same public address
2527731ee5aSAlexander Langeras follows
2535a424c8cSRuslan Ermilov.Bd -literal -offset indent
2546a5796e7SRuslan Ermilovredirect_address 192.168.0.2 public_addr
2556a5796e7SRuslan Ermilovredirect_address 192.168.0.3 public_addr
2566a5796e7SRuslan Ermilovredirect_address 192.168.0.4 public_addr
2575a424c8cSRuslan Ermilov.Ed
2585a424c8cSRuslan Ermilov.Pp
25924084f9bSBrian Somersthe incoming traffic will be directed to the last
2607731ee5aSAlexander Langertranslated local address (192.168.0.4), but outgoing
2615a424c8cSRuslan Ermilovtraffic from the first two addresses will still be aliased
2625a424c8cSRuslan Ermilovto appear from the specified
2635a424c8cSRuslan Ermilov.Ar public_addr .
264bd690510SRuslan Ermilov.It Fl redirect_port Ar proto Xo
265bd690510SRuslan Ermilov.Ar targetIP Ns : Ns Xo
266bd690510SRuslan Ermilov.Ar targetPORT Ns Oo , Ns
267bd690510SRuslan Ermilov.Ar targetIP Ns : Ns Xo
268bd690510SRuslan Ermilov.Ar targetPORT Ns Oo , Ns
269d0353b83SRuslan Ermilov.Ar ...\&
2709760b0e0SJoel Dahl.Oc Xc Oc Xc
2719760b0e0SJoel Dahl.Oo Ar aliasIP Ns : Oc Ns Xo
272bd690510SRuslan Ermilov.Ar aliasPORT
273bd690510SRuslan Ermilov.Xc
274bd690510SRuslan Ermilov.Oo Ar remoteIP Ns
275bd690510SRuslan Ermilov.Op : Ns Ar remotePORT
276bd690510SRuslan Ermilov.Oc
277bd690510SRuslan Ermilov.Xc
278bd690510SRuslan Ermilov.It Fl redirect_address Xo
279bd690510SRuslan Ermilov.Ar localIP Ns Oo , Ns
280bd690510SRuslan Ermilov.Ar localIP Ns Oo , Ns
281d0353b83SRuslan Ermilov.Ar ...\&
282bd690510SRuslan Ermilov.Oc Oc
283bd690510SRuslan Ermilov.Ar publicIP
284bd690510SRuslan Ermilov.Xc
285bd690510SRuslan ErmilovThese forms of
286bd690510SRuslan Ermilov.Fl redirect_port
287bd690510SRuslan Ermilovand
288bd690510SRuslan Ermilov.Fl redirect_address
289bd690510SRuslan Ermilovare used to transparently offload network load on a single server and
290bd690510SRuslan Ermilovdistribute the load across a pool of servers.
291bd690510SRuslan ErmilovThis function is known as
292bd690510SRuslan Ermilov.Em LSNAT
293bd690510SRuslan Ermilov(RFC 2391).
2947731ee5aSAlexander LangerFor example, the argument
295bd690510SRuslan Ermilov.Pp
296bd690510SRuslan Ermilov.Dl Ar tcp www1:http,www2:http,www3:http www:http
297bd690510SRuslan Ermilov.Pp
298bd690510SRuslan Ermilovmeans that incoming HTTP requests for host www will be transparently
2997731ee5aSAlexander Langerredirected to one of the www1, www2 or www3, where a host is selected
3007731ee5aSAlexander Langersimply on a round-robin basis, without regard to load on the net.
30124084f9bSBrian Somers.It Fl dynamic
30224084f9bSBrian SomersIf the
30324084f9bSBrian Somers.Fl n
30424084f9bSBrian Somersor
30524084f9bSBrian Somers.Fl interface
30624084f9bSBrian Somersoption is used,
3070fc81af1SPhilippe Charnier.Nm
30824084f9bSBrian Somerswill monitor the routing socket for alterations to the
30924084f9bSBrian Somers.Ar interface
3105a424c8cSRuslan Ermilovpassed.
3115105f991SRuslan ErmilovIf the interface's IP address is changed,
3120fc81af1SPhilippe Charnier.Nm
31324084f9bSBrian Somerswill dynamically alter its concept of the alias address.
3145a424c8cSRuslan Ermilov.It Fl in_port | i Ar port
31524084f9bSBrian SomersRead from and write to
316d2a46bc9SRuslan Ermilov.Xr divert 4
317d2a46bc9SRuslan Ermilovport
31824084f9bSBrian Somers.Ar port ,
319d2a46bc9SRuslan Ermilovtreating all packets as
320d2a46bc9SRuslan Ermilov.Dq incoming .
3215a424c8cSRuslan Ermilov.It Fl out_port | o Ar port
3225a424c8cSRuslan ErmilovRead from and write to
323d2a46bc9SRuslan Ermilov.Xr divert 4
324d2a46bc9SRuslan Ermilovport
3255a424c8cSRuslan Ermilov.Ar port ,
326d2a46bc9SRuslan Ermilovtreating all packets as
327d2a46bc9SRuslan Ermilov.Dq outgoing .
3285a424c8cSRuslan Ermilov.It Fl port | p Ar port
3295a424c8cSRuslan ErmilovRead from and write to
330d2a46bc9SRuslan Ermilov.Xr divert 4
331d2a46bc9SRuslan Ermilovport
3325a424c8cSRuslan Ermilov.Ar port ,
333d2a46bc9SRuslan Ermilovdistinguishing packets as
334d2a46bc9SRuslan Ermilov.Dq incoming
335d2a46bc9SRuslan Ermilovor
336d2a46bc9SRuslan Ermilov.Dq outgoing
337d2a46bc9SRuslan Ermilovusing the rules specified in
33824084f9bSBrian Somers.Xr divert 4 .
33924084f9bSBrian SomersIf
34024084f9bSBrian Somers.Ar port
34124084f9bSBrian Somersis not numeric, it is searched for in the
34224084f9bSBrian Somers.Xr services 5
3435a424c8cSRuslan Ermilovdatabase.
3445a424c8cSRuslan ErmilovIf this option is not specified, the divert port named
345d2a46bc9SRuslan Ermilov.Ar natd
3465a424c8cSRuslan Ermilovwill be used as a default.
3475a424c8cSRuslan Ermilov.It Fl alias_address | a Ar address
34824084f9bSBrian SomersUse
34924084f9bSBrian Somers.Ar address
3505a424c8cSRuslan Ermilovas the aliasing address.
3513d23e8b8SRuslan ErmilovEither this or the
35224084f9bSBrian Somers.Fl interface
3533d23e8b8SRuslan Ermilovoption must be used (but not both),
3543d23e8b8SRuslan Ermilovif the
3553d23e8b8SRuslan Ermilov.Fl proxy_only
3563d23e8b8SRuslan Ermilovoption is not specified.
3575a424c8cSRuslan ErmilovThe specified address is usually the address assigned to the
358d2a46bc9SRuslan Ermilov.Dq public
359d2a46bc9SRuslan Ermilovnetwork interface.
360f7d1db72SBrian Somers.Pp
3615a424c8cSRuslan ErmilovAll data passing
3625a424c8cSRuslan Ermilov.Em out
3635a424c8cSRuslan Ermilovwill be rewritten with a source address equal to
364f7d1db72SBrian Somers.Ar address .
3655a424c8cSRuslan ErmilovAll data coming
3665a424c8cSRuslan Ermilov.Em in
3675a424c8cSRuslan Ermilovwill be checked to see if it matches any already-aliased outgoing
3685a424c8cSRuslan Ermilovconnection.
3695a424c8cSRuslan ErmilovIf it does, the packet is altered accordingly.
3705a424c8cSRuslan ErmilovIf not, all
3715a424c8cSRuslan Ermilov.Fl redirect_port ,
3725a424c8cSRuslan Ermilov.Fl redirect_proto
373f7d1db72SBrian Somersand
374f7d1db72SBrian Somers.Fl redirect_address
3755a424c8cSRuslan Ermilovassignments are checked and actioned.
3765a424c8cSRuslan ErmilovIf no other action can be made and if
377f7d1db72SBrian Somers.Fl deny_incoming
378d2a46bc9SRuslan Ermilovis not specified, the packet is delivered to the local machine
379d2a46bc9SRuslan Ermilovusing the rules specified in
3805a424c8cSRuslan Ermilov.Fl target_address
3815a424c8cSRuslan Ermilovoption below.
38211c2b3bfSRuslan Ermilov.It Fl t | target_address Ar address
38311c2b3bfSRuslan ErmilovSet the target address.
38411c2b3bfSRuslan ErmilovWhen an incoming packet not associated with any pre-existing link
3857731ee5aSAlexander Langerarrives at the host machine, it will be sent to the specified
38611c2b3bfSRuslan Ermilov.Ar address .
38711c2b3bfSRuslan Ermilov.Pp
38811c2b3bfSRuslan ErmilovThe target address may be set to
3895a424c8cSRuslan Ermilov.Ar 255.255.255.255 ,
39011c2b3bfSRuslan Ermilovin which case all new incoming packets go to the alias address set by
39111c2b3bfSRuslan Ermilov.Fl alias_address
39211c2b3bfSRuslan Ermilovor
39311c2b3bfSRuslan Ermilov.Fl interface .
39411c2b3bfSRuslan Ermilov.Pp
3957731ee5aSAlexander LangerIf this option is not used, or called with the argument
3965a424c8cSRuslan Ermilov.Ar 0.0.0.0 ,
3977731ee5aSAlexander Langerthen all new incoming packets go to the address specified in
3987731ee5aSAlexander Langerthe packet.
39911c2b3bfSRuslan ErmilovThis allows external machines to talk directly to internal machines if
40011c2b3bfSRuslan Ermilovthey can route packets to the machine in question.
4015a424c8cSRuslan Ermilov.It Fl interface | n Ar interface
40224084f9bSBrian SomersUse
40324084f9bSBrian Somers.Ar interface
4045a424c8cSRuslan Ermilovto determine the aliasing address.
4055105f991SRuslan ErmilovIf there is a possibility that the IP address associated with
40624084f9bSBrian Somers.Ar interface
40724084f9bSBrian Somersmay change, the
40824084f9bSBrian Somers.Fl dynamic
4095a424c8cSRuslan Ermilovoption should also be used.
4105a424c8cSRuslan ErmilovIf this option is not specified, the
41124084f9bSBrian Somers.Fl alias_address
4125a424c8cSRuslan Ermilovoption must be used.
413f7d1db72SBrian Somers.Pp
414f7d1db72SBrian SomersThe specified
415f7d1db72SBrian Somers.Ar interface
416d2a46bc9SRuslan Ermilovis usually the
417d2a46bc9SRuslan Ermilov.Dq public
418d2a46bc9SRuslan Ermilov(or
419d2a46bc9SRuslan Ermilov.Dq external )
420d2a46bc9SRuslan Ermilovnetwork interface.
4215a424c8cSRuslan Ermilov.It Fl config | f Ar file
42224084f9bSBrian SomersRead configuration from
4235a424c8cSRuslan Ermilov.Ar file .
4245a424c8cSRuslan ErmilovA
4255a424c8cSRuslan Ermilov.Ar file
4265a424c8cSRuslan Ermilovshould contain a list of options, one per line, in the same form
4275a424c8cSRuslan Ermilovas the long form of the above command line options.
4285a424c8cSRuslan ErmilovFor example, the line
4295a424c8cSRuslan Ermilov.Pp
4305a424c8cSRuslan Ermilov.Dl alias_address 158.152.17.1
4315a424c8cSRuslan Ermilov.Pp
4325a424c8cSRuslan Ermilovwould specify an alias address of 158.152.17.1.
433d2a46bc9SRuslan ErmilovOptions that do not take an argument are specified with an argument of
43424084f9bSBrian Somers.Ar yes
43524084f9bSBrian Somersor
43624084f9bSBrian Somers.Ar no
4375a424c8cSRuslan Ermilovin the configuration file.
4385a424c8cSRuslan ErmilovFor example, the line
4395a424c8cSRuslan Ermilov.Pp
4405a424c8cSRuslan Ermilov.Dl log yes
4415a424c8cSRuslan Ermilov.Pp
4425a424c8cSRuslan Ermilovis synonymous with
44324084f9bSBrian Somers.Fl log .
4442e7e7c71SRuslan Ermilov.Pp
445057c6548SMaxim KonovalovOptions can be divided to several sections.
446057c6548SMaxim KonovalovEach section applies to own
447c80d9b59SPoul-Henning Kamp.Nm
448057c6548SMaxim Konovalovinstance.
4499084fdf8SSevan JaniyanThis ability allows the configuration of one
450c80d9b59SPoul-Henning Kamp.Nm
451057c6548SMaxim Konovalovprocess for several NAT instances.
452057c6548SMaxim KonovalovThe first instance that always exists is a "default" instance.
453057c6548SMaxim KonovalovEach another instance should begin with
454c80d9b59SPoul-Henning Kamp.Pp
455c80d9b59SPoul-Henning Kamp.Dl instance Ar instance_name
456c80d9b59SPoul-Henning Kamp.Pp
457057c6548SMaxim KonovalovAt the next should be placed a configuration option.
458057c6548SMaxim KonovalovExample:
459c80d9b59SPoul-Henning Kamp.Pp
460c80d9b59SPoul-Henning Kamp.Dl \&# default instance
461c80d9b59SPoul-Henning Kamp.Dl port 8668
462c80d9b59SPoul-Henning Kamp.Dl alias_address 158.152.17.1
463c80d9b59SPoul-Henning Kamp.Pp
464c80d9b59SPoul-Henning Kamp.Dl \&# second instance
465c80d9b59SPoul-Henning Kamp.Dl instance dsl1
466c80d9b59SPoul-Henning Kamp.Dl port 8888
467c80d9b59SPoul-Henning Kamp.Dl alias_address 192.168.0.1
468c80d9b59SPoul-Henning Kamp.Pp
4692e7e7c71SRuslan ErmilovTrailing spaces and empty lines are ignored.
4702e7e7c71SRuslan ErmilovA
4712e7e7c71SRuslan Ermilov.Ql \&#
4722522beceSMike Pritchardsign will mark the rest of the line as a comment.
47398439aafSRuslan Ermilov.It Fl instance Ar instancename
47498439aafSRuslan ErmilovThis option switches command line options processing to configure instance
47598439aafSRuslan Ermilov.Ar instancename
47698439aafSRuslan Ermilov(creating it if necessary) till the next
47798439aafSRuslan Ermilov.Fl instance
47898439aafSRuslan Ermilovoption or end of command line.
47998439aafSRuslan ErmilovIt is easier to set up multiple instances in the configuration file
48098439aafSRuslan Ermilovspecified with the
48198439aafSRuslan Ermilov.Fl config
48298439aafSRuslan Ermilovoption rather than on a command line.
48398439aafSRuslan Ermilov.It Fl globalport Ar port
48498439aafSRuslan ErmilovRead from and write to
48598439aafSRuslan Ermilov.Xr divert 4
48698439aafSRuslan Ermilovport
48798439aafSRuslan Ermilov.Ar port ,
48898439aafSRuslan Ermilovtreating all packets as
48998439aafSRuslan Ermilov.Dq outgoing .
49098439aafSRuslan ErmilovThis option is intended to be used with multiple instances:
49198439aafSRuslan Ermilovpackets received on this port are checked against
49298439aafSRuslan Ermilovinternal translation tables of every configured instance.
49398439aafSRuslan ErmilovIf an entry is found, packet is aliased according to that entry.
494606b32f6SSergey MatveychukIf no entry was found in any of the instances, packet is passed
49598439aafSRuslan Ermilovunchanged, and no new entry will be created.
49698439aafSRuslan ErmilovSee the section
49798439aafSRuslan Ermilov.Sx MULTIPLE INSTANCES
49898439aafSRuslan Ermilovfor more details.
49959a7c613SBrian Somers.It Fl reverse
5005a424c8cSRuslan ErmilovThis option makes
5015a424c8cSRuslan Ermilov.Nm
502d2a46bc9SRuslan Ermilovreverse the way it handles
503d2a46bc9SRuslan Ermilov.Dq incoming
504d2a46bc9SRuslan Ermilovand
505d2a46bc9SRuslan Ermilov.Dq outgoing
506d2a46bc9SRuslan Ermilovpackets, allowing it to operate on the
507d2a46bc9SRuslan Ermilov.Dq internal
508d2a46bc9SRuslan Ermilovnetwork interface rather than the
509d2a46bc9SRuslan Ermilov.Dq external
510d2a46bc9SRuslan Ermilovone.
5115a424c8cSRuslan Ermilov.Pp
5125a424c8cSRuslan ErmilovThis can be useful in some transparent proxying situations
5135a424c8cSRuslan Ermilovwhen outgoing traffic is redirected to the local machine
5145a424c8cSRuslan Ermilovand
5155a424c8cSRuslan Ermilov.Nm
5165a424c8cSRuslan Ermilovis running on the internal interface (it usually runs on the
5175a424c8cSRuslan Ermilovexternal interface).
51859a7c613SBrian Somers.It Fl proxy_only
5195a424c8cSRuslan ErmilovForce
5205a424c8cSRuslan Ermilov.Nm
5215a424c8cSRuslan Ermilovto perform transparent proxying only.
522ef8f7ac9SSheldon HearnNormal address translation is not performed.
5235a424c8cSRuslan Ermilov.It Fl proxy_rule Xo
5245a424c8cSRuslan Ermilov.Op Ar type encode_ip_hdr | encode_tcp_stream
5255a424c8cSRuslan Ermilov.Ar port xxxx
5265a424c8cSRuslan Ermilov.Ar server a.b.c.d:yyyy
5275a424c8cSRuslan Ermilov.Xc
528ef8f7ac9SSheldon HearnEnable transparent proxying.
5295a424c8cSRuslan ErmilovOutgoing TCP packets with the given port going through this
5307731ee5aSAlexander Langerhost to any other host are redirected to the given server and port.
531ef8f7ac9SSheldon HearnOptionally, the original target address can be encoded into the packet.
532ef8f7ac9SSheldon HearnUse
5335a424c8cSRuslan Ermilov.Ar encode_ip_hdr
53459a7c613SBrian Somersto put this information into the IP option field or
5355a424c8cSRuslan Ermilov.Ar encode_tcp_stream
53659a7c613SBrian Somersto inject the data into the beginning of the TCP stream.
537bc4ebb98SRuslan Ermilov.It Fl punch_fw Xo
538bc4ebb98SRuslan Ermilov.Ar basenumber Ns : Ns Ar count
539bc4ebb98SRuslan Ermilov.Xc
540f685a909SRuslan ErmilovThis option directs
541bc4ebb98SRuslan Ermilov.Nm
542f685a909SRuslan Ermilovto
543f685a909SRuslan Ermilov.Dq punch holes
544bc4ebb98SRuslan Ermilovin an
545bc4ebb98SRuslan Ermilov.Xr ipfirewall 4
546bc4ebb98SRuslan Ermilovbased firewall for FTP/IRC DCC connections.
547f685a909SRuslan ErmilovThis is done dynamically by installing temporary firewall rules which
548f685a909SRuslan Ermilovallow a particular connection (and only that connection) to go through
549f685a909SRuslan Ermilovthe firewall.
550f685a909SRuslan ErmilovThe rules are removed once the corresponding connection terminates.
551bc4ebb98SRuslan Ermilov.Pp
552f685a909SRuslan ErmilovA maximum of
553bc4ebb98SRuslan Ermilov.Ar count
554f685a909SRuslan Ermilovrules starting from the rule number
555f685a909SRuslan Ermilov.Ar basenumber
556f685a909SRuslan Ermilovwill be used for punching firewall holes.
557bc4ebb98SRuslan ErmilovThe range will be cleared for all rules on startup.
558e30ba475STom RhodesThis option has no effect when the kernel is in security
559e30ba475STom Rhodeslevel 3, see
560e30ba475STom Rhodes.Xr init 8
561e30ba475STom Rhodesfor more information.
562b07fbc17SJoe Marcus Clarke.It Fl skinny_port Ar port
563b07fbc17SJoe Marcus ClarkeThis option allows you to specify the TCP port used for
564b07fbc17SJoe Marcus Clarkethe Skinny Station protocol.
565b07fbc17SJoe Marcus ClarkeSkinny is used by Cisco IP phones to communicate with
566b07fbc17SJoe Marcus ClarkeCisco Call Managers to set up voice over IP calls.
567b07fbc17SJoe Marcus ClarkeBy default, Skinny aliasing is not performed.
568b07fbc17SJoe Marcus ClarkeThe typical port value for Skinny is 2000.
56984ef95bdSPoul-Henning Kamp.It Fl log_ipfw_denied
5703843533eSRuslan ErmilovLog when a packet cannot be re-injected because an
5713843533eSRuslan Ermilov.Xr ipfw 8
5723843533eSRuslan Ermilovrule blocks it.
573c0956cf8SRuslan ErmilovThis is the default with
574c0956cf8SRuslan Ermilov.Fl verbose .
575b79840a6SRuslan Ermilov.It Fl pid_file | P Ar file
576b79840a6SRuslan ErmilovSpecify an alternate file in which to store the process ID.
577b79840a6SRuslan ErmilovThe default is
578b79840a6SRuslan Ermilov.Pa /var/run/natd.pid .
57972cbe4adSAlexander Motin.It Fl exit_delay Ar ms
58072cbe4adSAlexander MotinSpecify delay in ms before daemon exit after signal.
58172cbe4adSAlexander MotinThe default is
58272cbe4adSAlexander Motin.Pa 10000 .
58324084f9bSBrian Somers.El
58424084f9bSBrian Somers.Sh RUNNING NATD
58524084f9bSBrian SomersThe following steps are necessary before attempting to run
5867c7fb079SRuslan Ermilov.Nm :
58724084f9bSBrian Somers.Bl -enum
58824084f9bSBrian Somers.It
58924084f9bSBrian SomersBuild a custom kernel with the following options:
5905a424c8cSRuslan Ermilov.Bd -literal -offset indent
59124084f9bSBrian Somersoptions IPFIREWALL
59224084f9bSBrian Somersoptions IPDIVERT
5935a424c8cSRuslan Ermilov.Ed
5945a424c8cSRuslan Ermilov.Pp
59524084f9bSBrian SomersRefer to the handbook for detailed instructions on building a custom
59624084f9bSBrian Somerskernel.
59724084f9bSBrian Somers.It
5985a424c8cSRuslan ErmilovEnsure that your machine is acting as a gateway.
5995a424c8cSRuslan ErmilovThis can be done by specifying the line
6005a424c8cSRuslan Ermilov.Pp
6015a424c8cSRuslan Ermilov.Dl gateway_enable=YES
6025a424c8cSRuslan Ermilov.Pp
6035a424c8cSRuslan Ermilovin the
6045a424c8cSRuslan Ermilov.Pa /etc/rc.conf
6055a424c8cSRuslan Ermilovfile or using the command
6065a424c8cSRuslan Ermilov.Pp
607e21a315eSRuslan Ermilov.Dl "sysctl net.inet.ip.forwarding=1"
60824084f9bSBrian Somers.It
6095a424c8cSRuslan ErmilovIf you use the
61024084f9bSBrian Somers.Fl interface
6115a424c8cSRuslan Ermilovoption, make sure that your interface is already configured.
612d2a46bc9SRuslan ErmilovIf, for example, you wish to specify
613d2a46bc9SRuslan Ermilov.Ql tun0
614d2a46bc9SRuslan Ermilovas your
61524084f9bSBrian Somers.Ar interface ,
6165a424c8cSRuslan Ermilovand you are using
61724084f9bSBrian Somers.Xr ppp 8
6187731ee5aSAlexander Langeron that interface, you must make sure that you start
61924084f9bSBrian Somers.Nm ppp
62024084f9bSBrian Somersprior to starting
6217c7fb079SRuslan Ermilov.Nm .
62224084f9bSBrian Somers.El
62324084f9bSBrian Somers.Pp
62424084f9bSBrian SomersRunning
6250fc81af1SPhilippe Charnier.Nm
6265a424c8cSRuslan Ermilovis fairly straight forward.
6275a424c8cSRuslan ErmilovThe line
6285a424c8cSRuslan Ermilov.Pp
6295a424c8cSRuslan Ermilov.Dl natd -interface ed0
6305a424c8cSRuslan Ermilov.Pp
6315a424c8cSRuslan Ermilovshould suffice in most cases (substituting the correct interface name).
632ecd1fe62SRuslan ErmilovPlease check
633ecd1fe62SRuslan Ermilov.Xr rc.conf 5
634ecd1fe62SRuslan Ermilovon how to configure it to be started automatically during boot.
6355a424c8cSRuslan ErmilovOnce
6360fc81af1SPhilippe Charnier.Nm
6375a424c8cSRuslan Ermilovis running, you must ensure that traffic is diverted to
6387c7fb079SRuslan Ermilov.Nm :
63924084f9bSBrian Somers.Bl -enum
64024084f9bSBrian Somers.It
64124084f9bSBrian SomersYou will need to adjust the
64224084f9bSBrian Somers.Pa /etc/rc.firewall
6435a424c8cSRuslan Ermilovscript to taste.
6445a424c8cSRuslan ErmilovIf you are not interested in having a firewall, the
64524084f9bSBrian Somersfollowing lines will do:
6465a424c8cSRuslan Ermilov.Bd -literal -offset indent
64724084f9bSBrian Somers/sbin/ipfw -f flush
64846b2c559SBrian Somers/sbin/ipfw add divert natd all from any to any via ed0
64924084f9bSBrian Somers/sbin/ipfw add pass all from any to any
6505a424c8cSRuslan Ermilov.Ed
6515a424c8cSRuslan Ermilov.Pp
652d2a46bc9SRuslan ErmilovThe second line depends on your interface (change
653d2a46bc9SRuslan Ermilov.Ql ed0
654d2a46bc9SRuslan Ermilovas appropriate).
6555a424c8cSRuslan Ermilov.Pp
6565a424c8cSRuslan ErmilovYou should be aware of the fact that, with these firewall settings,
6575a424c8cSRuslan Ermiloveveryone on your local network can fake his source-address using your
6585a424c8cSRuslan Ermilovhost as gateway.
6595a424c8cSRuslan ErmilovIf there are other hosts on your local network, you are strongly
6605a424c8cSRuslan Ermilovencouraged to create firewall rules that only allow traffic to and
6615a424c8cSRuslan Ermilovfrom trusted hosts.
6625a424c8cSRuslan Ermilov.Pp
6635a424c8cSRuslan ErmilovIf you specify real firewall rules, it is best to specify line 2 at
6645a424c8cSRuslan Ermilovthe start of the script so that
6650fc81af1SPhilippe Charnier.Nm
66604bf7dcfSRuslan Ermilovsees all packets before they are dropped by the firewall.
66704bf7dcfSRuslan Ermilov.Pp
66804bf7dcfSRuslan ErmilovAfter translation by
6697c7fb079SRuslan Ermilov.Nm ,
67004bf7dcfSRuslan Ermilovpackets re-enter the firewall at the rule number following the rule number
6717731ee5aSAlexander Langerthat caused the diversion (not the next rule if there are several at the
6727731ee5aSAlexander Langersame number).
67324084f9bSBrian Somers.It
67424084f9bSBrian SomersEnable your firewall by setting
6755a424c8cSRuslan Ermilov.Pp
6765a424c8cSRuslan Ermilov.Dl firewall_enable=YES
6775a424c8cSRuslan Ermilov.Pp
67824084f9bSBrian Somersin
679c1b792b2SJordan K. Hubbard.Pa /etc/rc.conf .
68024084f9bSBrian SomersThis tells the system startup scripts to run the
68124084f9bSBrian Somers.Pa /etc/rc.firewall
6825a424c8cSRuslan Ermilovscript.
6835a424c8cSRuslan ErmilovIf you do not wish to reboot now, just run this by hand from the console.
6845a424c8cSRuslan ErmilovNEVER run this from a remote session unless you put it into the background.
6855a424c8cSRuslan ErmilovIf you do, you will lock yourself out after the flush takes place, and
6865a424c8cSRuslan Ermilovexecution of
68724084f9bSBrian Somers.Pa /etc/rc.firewall
6885a424c8cSRuslan Ermilovwill stop at this point - blocking all accesses permanently.
6895a424c8cSRuslan ErmilovRunning the script in the background should be enough to prevent this
6905a424c8cSRuslan Ermilovdisaster.
69124084f9bSBrian Somers.El
69298439aafSRuslan Ermilov.Sh MULTIPLE INSTANCES
69398439aafSRuslan ErmilovIt is not so uncommon to have a need of aliasing to several external IP
69498439aafSRuslan Ermilovaddresses.
69598439aafSRuslan ErmilovWhile this traditionally was achieved by running several
69698439aafSRuslan Ermilov.Nm
69798439aafSRuslan Ermilovprocesses with independent configurations,
69898439aafSRuslan Ermilov.Nm
69998439aafSRuslan Ermilovcan have multiple aliasing instances in a single process,
70098439aafSRuslan Ermilovalso allowing them to be not so independent of each other.
70198439aafSRuslan ErmilovFor example, let us see a common task of load balancing two
70298439aafSRuslan Ermilovchannels to different providers on a machine with two external
70398439aafSRuslan Ermilovinterfaces
70498439aafSRuslan Ermilov.Ql sis0
70598439aafSRuslan Ermilov(with IP 1.2.3.4) and
70698439aafSRuslan Ermilov.Ql sis2
70798439aafSRuslan Ermilov(with IP 2.3.4.5):
70898439aafSRuslan Ermilov.Bd -literal -offset indent
70998439aafSRuslan Ermilov          net 1.2.3.0/24
71098439aafSRuslan Ermilov1.2.3.1 ------------------ sis0
71198439aafSRuslan Ermilov(router)                (1.2.3.4)
71298439aafSRuslan Ermilov                                         net 10.0.0.0/24
71398439aafSRuslan Ermilov                                  sis1 ------------------- 10.0.0.2
71498439aafSRuslan Ermilov                               (10.0.0.1)
71598439aafSRuslan Ermilov          net 2.3.4.0/24
71698439aafSRuslan Ermilov2.3.4.1 ------------------ sis2
71798439aafSRuslan Ermilov(router)                (2.3.4.5)
71898439aafSRuslan Ermilov.Ed
71998439aafSRuslan Ermilov.Pp
72098439aafSRuslan ErmilovDefault route is out via
72198439aafSRuslan Ermilov.Ql sis0 .
72298439aafSRuslan Ermilov.Pp
72398439aafSRuslan ErmilovInterior machine (10.0.0.2) is accessible on TCP port 122 through
72498439aafSRuslan Ermilovboth exterior IPs, and outgoing connections choose a path randomly
72598439aafSRuslan Ermilovbetween
72698439aafSRuslan Ermilov.Ql sis0
72798439aafSRuslan Ermilovand
72898439aafSRuslan Ermilov.Ql sis2 .
72998439aafSRuslan Ermilov.Pp
73098439aafSRuslan ErmilovThe way this works is that
73198439aafSRuslan Ermilov.Pa natd.conf
73298439aafSRuslan Ermilovbuilds two instances of the aliasing engine.
73398439aafSRuslan Ermilov.Pp
73498439aafSRuslan ErmilovIn addition to these instances' private
73598439aafSRuslan Ermilov.Xr divert 4
73698439aafSRuslan Ermilovsockets, a third socket called the
73798439aafSRuslan Ermilov.Dq globalport
73898439aafSRuslan Ermilovis created; packets sent to
73998439aafSRuslan Ermilov.Nm
74098439aafSRuslan Ermilovvia this one will be matched against all instances and translated
74198439aafSRuslan Ermilovif an existing entry is found, and unchanged if no entry is found.
74298439aafSRuslan ErmilovThe following lines are placed into
74398439aafSRuslan Ermilov.Pa /etc/natd.conf :
74498439aafSRuslan Ermilov.Bd -literal -offset indent
74598439aafSRuslan Ermilovlog
74698439aafSRuslan Ermilovdeny_incoming
74798439aafSRuslan Ermilovverbose
74898439aafSRuslan Ermilov
74998439aafSRuslan Ermilovinstance default
75098439aafSRuslan Ermilovinterface sis0
75198439aafSRuslan Ermilovport 1000
75298439aafSRuslan Ermilovredirect_port tcp 10.0.0.2:122 122
75398439aafSRuslan Ermilov
75498439aafSRuslan Ermilovinstance sis2
75598439aafSRuslan Ermilovinterface sis2
75698439aafSRuslan Ermilovport 2000
75798439aafSRuslan Ermilovredirect_port tcp 10.0.0.2:122 122
75898439aafSRuslan Ermilov
75998439aafSRuslan Ermilovglobalport 3000
76098439aafSRuslan Ermilov.Ed
76198439aafSRuslan Ermilov.Pp
76298439aafSRuslan ErmilovAnd the following
76398439aafSRuslan Ermilov.Xr ipfw 8
76498439aafSRuslan Ermilovrules are used:
76598439aafSRuslan Ermilov.Bd -literal -offset indent
76698439aafSRuslan Ermilovipfw -f flush
76798439aafSRuslan Ermilov
76898439aafSRuslan Ermilovipfw add      allow ip from any to any via sis1
76998439aafSRuslan Ermilov
77098439aafSRuslan Ermilovipfw add      skipto 1000 ip from any to any in via sis0
77198439aafSRuslan Ermilovipfw add      skipto 2000 ip from any to any out via sis0
77298439aafSRuslan Ermilovipfw add      skipto 3000 ip from any to any in via sis2
77398439aafSRuslan Ermilovipfw add      skipto 4000 ip from any to any out via sis2
77498439aafSRuslan Ermilov
77598439aafSRuslan Ermilovipfw add 1000 count ip from any to any
77698439aafSRuslan Ermilov
77798439aafSRuslan Ermilovipfw add      divert 1000 ip from any to any
77898439aafSRuslan Ermilovipfw add      allow ip from any to any
77998439aafSRuslan Ermilov
78098439aafSRuslan Ermilovipfw add 2000 count ip from any to any
78198439aafSRuslan Ermilov
78298439aafSRuslan Ermilovipfw add      divert 3000 ip from any to any
78398439aafSRuslan Ermilov
78498439aafSRuslan Ermilovipfw add      allow ip from 1.2.3.4 to any
78598439aafSRuslan Ermilovipfw add      skipto 5000 ip from 2.3.4.5 to any
78698439aafSRuslan Ermilov
78798439aafSRuslan Ermilovipfw add      prob .5 skipto 4000 ip from any to any
78898439aafSRuslan Ermilov
78998439aafSRuslan Ermilovipfw add      divert 1000 ip from any to any
79098439aafSRuslan Ermilovipfw add      allow ip from any to any
79198439aafSRuslan Ermilov
79298439aafSRuslan Ermilovipfw add 3000 count ip from any to any
79398439aafSRuslan Ermilov
79498439aafSRuslan Ermilovipfw add      divert 2000 ip from any to any
79598439aafSRuslan Ermilovipfw add      allow ip from any to any
79698439aafSRuslan Ermilov
79798439aafSRuslan Ermilovipfw add 4000 count ip from any to any
79898439aafSRuslan Ermilov
79998439aafSRuslan Ermilovipfw add      divert 2000 ip from any to any
80098439aafSRuslan Ermilov
80198439aafSRuslan Ermilovipfw add 5000 fwd 2.3.4.1 ip from 2.3.4.5 to not 2.3.4.0/24
80298439aafSRuslan Ermilovipfw add      allow ip from any to any
80398439aafSRuslan Ermilov.Ed
80498439aafSRuslan Ermilov.Pp
80598439aafSRuslan ErmilovHere the packet from internal network to Internet goes out via
80698439aafSRuslan Ermilov.Ql sis0
807344c81a1SWarren Block(rule number 2000) and gets caught by the
80898439aafSRuslan Ermilov.Ic globalport
80998439aafSRuslan Ermilovsocket (3000).
81098439aafSRuslan ErmilovAfter that, either a match is found in a translation table
81198439aafSRuslan Ermilovof one of the two instances, or the packet is passed to one
81298439aafSRuslan Ermilovof the two other
81398439aafSRuslan Ermilov.Xr divert 4
81498439aafSRuslan Ermilovports (1000 or 2000), with equal probability.
81598439aafSRuslan ErmilovThis ensures that load balancing is done on a per-flow basis
81698439aafSRuslan Ermilov(i.e., packets from a single TCP connection always flow through the
81798439aafSRuslan Ermilovsame interface).
81898439aafSRuslan ErmilovTranslated packets with source IP of a non-default interface
81998439aafSRuslan Ermilov.Pq Ql sis2
82098439aafSRuslan Ermilovare forwarded to the appropriate router on that interface.
82124084f9bSBrian Somers.Sh SEE ALSO
82201ba618fSRuslan Ermilov.Xr libalias 3 ,
82324084f9bSBrian Somers.Xr divert 4 ,
8245a424c8cSRuslan Ermilov.Xr protocols 5 ,
8255a424c8cSRuslan Ermilov.Xr rc.conf 5 ,
82624084f9bSBrian Somers.Xr services 5 ,
8275a424c8cSRuslan Ermilov.Xr syslog.conf 5 ,
828e30ba475STom Rhodes.Xr init 8 ,
8295a424c8cSRuslan Ermilov.Xr ipfw 8 ,
83032e5e4cfSBen Smithurst.Xr ppp 8
8319084fdf8SSevan Janiyan.Sh HISTORY
8329084fdf8SSevan JaniyanThe
8339084fdf8SSevan Janiyan.Nm
8349084fdf8SSevan Janiyanutility appeared in
8359084fdf8SSevan Janiyan.Fx 3.0 .
83624084f9bSBrian Somers.Sh AUTHORS
83724084f9bSBrian SomersThis program is the result of the efforts of many people at different
83824084f9bSBrian Somerstimes:
8395a424c8cSRuslan Ermilov.Pp
840bd0891ceSBaptiste Daroussin.An Archie Cobbs Aq Mt archie@FreeBSD.org
841f12a1471SPhilippe Charnier(divert sockets)
842bd0891ceSBaptiste Daroussin.An Charles Mott Aq Mt cm@linktel.net
843f12a1471SPhilippe Charnier(packet aliasing)
844bd0891ceSBaptiste Daroussin.An Eivind Eklund Aq Mt perhaps@yes.no
845f12a1471SPhilippe Charnier(IRC support & misc additions)
846bd0891ceSBaptiste Daroussin.An Ari Suutari Aq Mt suutari@iki.fi
847f12a1471SPhilippe Charnier(natd)
848bd0891ceSBaptiste Daroussin.An Dru Nelson Aq Mt dnelson@redwoodsoft.com
849dc1a0225SRuslan Ermilov(early PPTP support)
850bd0891ceSBaptiste Daroussin.An Brian Somers Aq Mt brian@awfulhak.org
851f12a1471SPhilippe Charnier(glue)
852bd0891ceSBaptiste Daroussin.An Ruslan Ermilov Aq Mt ru@FreeBSD.org
853d2a46bc9SRuslan Ermilov(natd, packet aliasing, glue)
854bd0891ceSBaptiste Daroussin.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org
85598439aafSRuslan Ermilov(multiple instances)
856