]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/man/ipnat.5
This commit was generated by cvs2svn to compensate for changes in r98247,
[FreeBSD/FreeBSD.git] / contrib / ipfilter / man / ipnat.5
1 .TH IPNAT 5
2 .SH NAME
3 ipnat, ipnat.conf \- IP NAT file format
4 .SH DESCRIPTION
5 The format for files accepted by ipnat is described by the following grammar:
6 .LP
7 .nf
8 ipmap :: = mapblock | redir | map .
9
10 map ::= mapit ifname ipmask "->" dstipmask [ mapport ] .
11 map ::= mapit ifname fromto "->" dstipmask [ mapport ] .
12 mapblock ::= "map-block" ifname ipmask "->" ipmask [ ports ] .
13 redir ::= "rdr" ifname ipmask dport "->" ip [ "," ip ] rdrport options .
14
15 dport ::= "port" portnum [ "-" portnum ] .
16 ports ::= "ports" numports | "auto" .
17 rdrport ::= "port" portnum .
18 mapit ::= "map" | "bimap" .
19 fromto ::= "from" object "to" object .
20 ipmask ::= ip "/" bits | ip "/" mask | ip "netmask" mask .
21 dstipmask ::= ipmask | "range" ip "-" ip .
22 mapport ::= "portmap" tcpudp portspec .
23 options ::= [ tcpudp ] [ rr ] .
24
25 object  :: = addr [ port-comp | port-range ] .
26 addr    :: = "any" | nummask | host-name [ "mask" ipaddr | "mask" hexnumber ] .
27 port-comp :: = "port" compare port-num .
28 port-range :: = "port" port-num range port-num .
29
30 rr ::= "round-robin" .
31 nummask = host-name [ "/" decnumber ] .
32 tcpudp ::= "tcp" | "udp" | "tcp/udp" .
33 portspec ::= "auto" | portnumber ":" portnumber .
34 portnumber ::= number { numbers } .
35 ifname ::= 'A' - 'Z' { 'A' - 'Z' } numbers .
36
37 numbers ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' .
38 .fi
39 .PP
40 In addition to this, # is used to mark the start of a comment and may
41 appear at the end of a line with a NAT rule (as described above) or on its
42 own lines.  Blank lines are ignored.
43 .PP
44 For standard NAT functionality, a rule should start with \fBmap\fP and then
45 proceeds to specify the interface for which outgoing packets will have their
46 source address rewritten.
47 .PP
48 Packets which will be rewritten can only be selected by matching the original
49 source address.  A netmask must be specified with the IP address.
50 .PP
51 The address selected for replacing the original is chosen from an IP#/netmask
52 pair.  A netmask of all 1's indicating a hostname is valid.  A netmask of
53 31 1's (255.255.255.254) is considered invalid as there is no space for
54 allocating host IP#'s after consideration for broadcast and network
55 addresses.
56 .PP
57 When remapping TCP and UDP packets, it is also possible to change the source
58 port number.  Either TCP or UDP or both can be selected by each rule, with a
59 range of port numbers to remap into given as \fBport-number:port-number\fP.
60 .SH COMMANDS
61 There are four commands recognised by IP Filter's NAT code:
62 .TP
63 .B map
64 that is used for mapping one address or network to another in an unregulated
65 round robin fashion;
66 .TP
67 .B rdr
68 that is used for redirecting packets to one IP address and port pair to
69 another;
70 .TP
71 .B bimap
72 for setting up bidirectional NAT between an external IP address and an internal
73 IP address and
74 .TP
75 .B map-block
76 which sets up static IP address based translation, based on a algorithm to
77 squeeze the addresses to be translated into the destination range.
78 .SH MATCHING
79 .PP
80 For basic NAT and redirection of packets, the address subject to change is used
81 along with its protocol to check if a packet should be altered.  The packet
82 \fImatching\fP part of the rule is to the left of the "->" in each rule.
83 .PP
84 Matching of packets has now been extended to allow more complex compares.
85 In place of the address which is to be translated, an IP address and port
86 number comparison can be made using the same expressions available with
87 \fBipf\fP.  A simple NAT rule could be written as:
88 .LP
89 .nf
90 map de0 10.1.0.0/16 -> 201.2.3.4/32
91 .fi
92 .LP
93 or as
94 .LP
95 .nf
96 map de0 from 10.1.0.0/16 to any -> 201.2.3.4/32
97 .fi
98 .LP
99 Only IP address and port numbers can be compared against.  This is available
100 with all NAT rules.
101 .SH TRANSLATION
102 .PP
103 To the right of the "->" is the address and port specificaton which will be
104 written into the packet providing it has already successful matched the
105 prior constraints.  The case of redirections (\fBrdr\fP) is the simpliest:
106 the new destination address is that specified in the rule.  For \fBmap\fP
107 rules, the destination address will be one for which the tuple combining
108 the new source and destination is known to be unique.  If the packet is
109 either a TCP or UDP packet, the destination and source ports come into the
110 equation too.  If the tuple already exists, IP Filter will increment the
111 port number first, within the available range specified with \fBportmap\fP
112 and if there exists no unique tuple, the source address will be incremented
113 within the specified netmask.  If a unique tuple cannot be determined, then
114 the packet will not be translated.  The \fBmap-block\fP is more limited in
115 how it searches for a new, free and unique tuple, in that it will used an
116 algorithm to determine what the new source address should be, along with the
117 range of available ports - the IP address is never changed and nor does the
118 port number ever exceed its alloted range.
119 .SH KERNEL PROXIES
120 .PP
121 IP Filter comes with a few, simple, proxies built into the code that is loaded
122 into the kernel to allow secondary channels to be opened without forcing the
123 packets through a user program.
124 .SH TRNSPARENT PROXIES
125 .PP
126 True transparent proxying should be performed using the redirect (\fBrdr\fP)
127 rules directing ports to localhost (127.0.0.1) with the proxy program doing
128 a lookup through \fB/dev/ipnat\fP to determine the real source and address
129 of the connection.
130 .SH LOAD-BALANCING
131 .PP
132 Two options for use with \fBrdr\fP are available to support primitive,
133 \fIround-robin\fP based load balancing.  The first option allows for a
134 \fBrdr\fP to specify a second destination, as follows:
135 .LP
136 .nf
137 rdr le0 203.1.2.3/32 port 80 -> 203.1.2.3,203.1.2.4 port 80 tcp
138 .fi
139 .LP
140 This would send alternate connections to either 203.1.2.3 or 203.1.2.4.
141 In scenarios where the load is being spread amongst a larger set of
142 servers, you can use:
143 .LP
144 .nf
145 rdr le0 203.1.2.3/32 port 80 -> 203.1.2.3,203.1.2.4 port 80 tcp round-robin
146 rdr le0 203.1.2.3/32 port 80 -> 203.1.2.5 port 80 tcp round-robin
147 .fi
148 .LP
149 In this case, a connection will be redirected to 203.1.2.3, then 203.1.2.4
150 and then 203.1.2.5 before going back to 203.1.2.3.  In accomplishing this,
151 the rule is removed from the top of the list and added to the end,
152 automatically, as required.  This will not effect the display of rules
153 using "ipnat -l", only the internal application order.
154 .SH EXAMPLES
155 .PP
156 This section deals with the \fBmap\fP command and it's variations.
157 .PP
158 To change IP#'s used internally from network 10 into an ISP provided 8 bit
159 subnet at 209.1.2.0 through the ppp0 interface, the following would be used:
160 .LP
161 .nf
162 map ppp0 10.0.0.0/8 -> 209.1.2.0/24
163 .fi
164 .PP
165 The obvious problem here is we're trying to squeeze over 16,000,000 IP
166 addresses into a 254 address space.  To increase the scope, remapping for TCP
167 and/or UDP, port remapping can be used;
168 .LP
169 .nf
170 map ppp0 10.0.0.0/8 -> 209.1.2.0/24 portmap tcp/udp 1025:65000
171 .fi
172 .PP
173 which falls only 527,566 `addresses' short of the space available in network
174 10.  If we were to combine these rules, they would need to be specified as
175 follows:
176 .LP
177 .nf
178 map ppp0 10.0.0.0/8 -> 209.1.2.0/24 portmap tcp/udp 1025:65000
179 map ppp0 10.0.0.0/8 -> 209.1.2.0/24
180 .fi
181 .PP
182 so that all TCP/UDP packets were port mapped and only other protocols, such as
183 ICMP, only have their IP# changed.  In some instaces, it is more appropriate
184 to use the keyword \fBauto\fP in place of an actual range of port numbers if
185 you want to guarantee simultaneous access to all within the given range.
186 However, in the above case, it would default to 1 port per IP address, since
187 we need to squeeze 24 bits of address space into 8.  A good example of how
188 this is used might be:
189 .LP
190 .nf
191 map ppp0 172.192.0.0/16 -> 209.1.2.0/24 portmap tcp/udp auto
192 .fi
193 .PP
194 which would result in each IP address being given a small range of ports to
195 use (252).  The problem here is that the \fBmap\fP directive tells the NAT
196 code to use the next address/port pair available for an outgoing connection,
197 resulting in no easily discernable relation between external addresses/ports
198 and internal ones.  This is overcome by using \fBmap-block\fP as follows:
199 .LP
200 .nf
201 map-block ppp0 172.192.0.0/16 -> 209.1.2.0/24 ports auto
202 .fi
203 .PP
204 For example, this would result in 172.192.0.0/24 being mapped to 209.1.2.0/32
205 with each address, from 172.192.0.0 to 172.192.0.255 having 252 ports of its
206 own.  As opposed to the above use of \fBmap\fP, if for some reason the user
207 of (say) 172.192.0.2 wanted 260 simultaneous connections going out, they would
208 be limited to 252 with \fBmap-block\fP but would just \fImove on\fP to the next
209 IP address with the \fBmap\fP command.
210 .SH FILES
211 /dev/ipnat
212 .br
213 /etc/services
214 .br
215 /etc/hosts
216 .SH SEE ALSO
217 ipnat(4), hosts(5), ipf(5), services(5), ipf(8), ipnat(8)