⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipnat.5

📁 NAT协议完整源代码
💻 5
字号:
.TH IPNAT 5.SH NAMEipnat, ipnat.conf \- IP NAT file format.SH DESCRIPTIONThe format for files accepted by ipnat is described by the following grammar:.LP.nfipmap :: = mapblock | redir | map .map ::= mapit ifname ipmask "->" ipmask [ mapport ] .map ::= mapit ifname fromto "->" ipmask [ mapport ] .mapblock ::= "map-block" ifname ipmask "->" ipmask [ ports ] .redir ::= "rdr" ifname ipmask dport "->" ip [ "," ip ] [ ports ] options .dport ::= "port" portnum [ "-" portnum ] .ports ::= "ports" numports | "auto" .mapit ::= "map" | "bimap" .fromto ::= "from" object "to" object .ipmask ::= ip "/" bits | ip "/" mask | ip "netmask" mask .mapport ::= "portmap" tcpudp portnumber ":" portnumber .options ::= [ tcpudp ] [ rr ] .object  = addr [ port-comp | port-range ] .addr    = "any" | nummask | host-name [ "mask" ipaddr | "mask" hexnumber ] .port-comp = "port" compare port-num .port-range = "port" port-num range port-num .rr ::= "round-robin" .tcpudp ::= "tcp" | "udp" | "tcp/udp" .portnumber ::= number { numbers } | "auto" .ifname ::= 'A' - 'Z' { 'A' - 'Z' } numbers .numbers ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ..fi.PPFor standard NAT functionality, a rule should start with \fBmap\fP and thenproceeds to specify the interface for which outgoing packets will have theirsource address rewritten..PPPackets which will be rewritten can only be selected by matching the originalsource address.  A netmask must be specified with the IP address..PPThe address selected for replacing the original is chosen from an IP#/netmaskpair.  A netmask of all 1's indicating a hostname is valid.  A netmask of31 1's (255.255.255.254) is considered invalid as there is no space forallocating host IP#'s after consideration for broadcast and networkaddresses..PPWhen remapping TCP and UDP packets, it is also possible to change the sourceport number.  Either TCP or UDP or both can be selected by each rule, with arange of port numbers to remap into given as \fBport-number:port-number\fP..SH COMMANDSThere are four commands recognised by IP Filter's NAT code:.TP.B mapthat is used for mapping one address or network to another in an unregulatedround robin fashion;.TP.B rdrthat is used for redirecting packets to one IP address and port pair toanother;.TP.B bimapfor setting up bidirectional NAT between an external IP address and an internalIP address and.TP.B map-blockwhich sets up static IP address based translation, based on a algorithm tosqueeze the addresses to be translated into the destination range..SH MATCHING.PPFor basic NAT and redirection of packets, the address subject to change is usedalong with its protocol to check if a packet should be altered.  The packet\fImatching\fP part of the rule is to the left of the "->" in each rule..PPMatching of packets has now been extended to allow more complex compares.In place of the address which is to be translated, an IP address and portnumber comparison can be made using the same expressions available with\fBipf\fP.  A simple NAT rule could be written as:.LP.nfmap de0 10.1.0.0/16 -> 201.2.3.4/32.fi.LPor as.LP.nfmap de0 from 10.1.0.0/16 to any -> 201.2.3.4/32.fi.LPOnly IP address and port numbers can be compared against.  This is availablewith all NAT rules..SH TRANSLATION.PPTo the right of the "->" is the address and port specificaton which will bewritten into the packet providing it has already successful matched theprior constraints.  The case of redirections (\fBrdr\fP) is the simpliest:the new destination address is that specified in the rule.  For \fBmap\fPrules, the destination address will be one for which the tuple combiningthe new source and destination is known to be unique.  If the packet iseither a TCP or UDP packet, the destination and source ports come into theequation too.  If the tuple already exists, IP Filter will increment theport number first, within the available range specified with \fBportmap\fPand if there exists no unique tuple, the source address will be incrementedwithin the specified netmask.  If a unique tuple cannot be determined, thenthe packet will not be translated.  The \fBmap-block\fP is more limited inhow it searches for a new, free and unique tuple, in that it will used analgorithm to determine what the new source address should be, along with therange of available ports - the IP address is never changed and nor does theport number ever exceed its alloted range..SH KERNEL PROXIES.PPIP Filter comes with a few, simple, proxies built into the code that is loadedinto the kernel to allow secondary channels to be opened without forcing thepackets through a user program..SH TRNSPARENT PROXIES.PPTrue transparent proxying should be performed using the redirect (\fBrdr\fP)rules directing ports to localhost (127.0.0.1) with the proxy program doinga lookup through \fB/dev/ipnat\fP to determine the real source and addressof the connection..SH LOAD-BALANCING.PPTwo options for use with \fBrdr\fP are available to support primitive,\fIround-robin\fP based load balancing.  The first option allows for a\fBrdr\fP to specify a second destination, as follows:.LP.nfrdr le0 203.1.2.3/32 port 80 -> 203.1.2.3,203.1.2.4 port 80 tcp.fi.LPThis would send alternate connections to either 203.1.2.3 or 203.1.2.4.In scenarios where the load is being spread amongst a larger set ofservers, you can use:.LP.nfrdr le0 203.1.2.3/32 port 80 -> 203.1.2.3,203.1.2.4 port 80 tcp round-robinrdr le0 203.1.2.3/32 port 80 -> 203.1.2.5 port 80 tcp round-robin.fi.LPIn this case, a connection will be redirected to 203.1.2.3, then 203.1.2.4and then 203.1.2.5 before going back to 203.1.2.3.  In accomplishing this,the rule is removed from the top of the list and added to the end,automatically, as required.  This will not effect the display of rulesusing "ipnat -l", only the internal application order..SH EXAMPLES.PPThis section deals with the \fBmap\fP command and it's variations..PPTo change IP#'s used internally from network 10 into an ISP provided 8 bitsubnet at 209.1.2.0 through the ppp0 interface, the following would be used:.LP.nfmap ppp0 10.0.0.0/8 -> 209.1.2.0/24.fi.PPThe obvious problem here is we're trying to squeeze over 16,000,000 IPaddresses into a 254 address space.  To increase the scope, remapping for TCPand/or UDP, port remapping can be used;.LP.nfmap ppp0 10.0.0.0/8 -> 209.1.2.0/24 portmap tcp/udp 1025:65000.fi.PPwhich falls only 527,566 `addresses' short of the space available in network10.  If we were to combine these rules, they would need to be specified asfollows:.LP.nfmap ppp0 10.0.0.0/8 -> 209.1.2.0/24 portmap tcp/udp 1025:65000map ppp0 10.0.0.0/8 -> 209.1.2.0/24.fi.PPso that all TCP/UDP packets were port mapped and only other protocols, such asICMP, only have their IP# changed.  In some instaces, it is more appropriateto use the keyword \fBauto\fP in place of an actual range of port numbers ifyou want to guarantee simultaneous access to all within the given range.However, in the above case, it would default to 1 port per IP address, sincewe need to squeeze 24 bits of address space into 8.  A good example of howthis is used might be:.LP.nfmap ppp0 172.192.0.0/16 -> 209.1.2.0/24 portmap tcp/udp auto.fi.PPwhich would result in each IP address being given a small range of ports touse (252).  The problem here is that the \fBmap\fP directive tells the NATcode to use the next address/port pair available for an outgoing connection,resulting in no easily discernable relation between external addresses/portsand internal ones.  This is overcome by using \fBmap-block\fP as follows:.LP.nfmap-block ppp0 172.192.0.0/16 -> 209.1.2.0/24 ports auto.fi.PPFor example, this would result in 172.192.0.0/24 being mapped to 209.1.2.0/32with each address, from 172.192.0.0 to 172.192.0.255 having 252 ports of itsown.  As opposed to the above use of \fBmap\fP, if for some reason the userof (say) 172.192.0.2 wanted 260 simultaneous connections going out, they wouldbe limited to 252 with \fBmap-block\fP but would just \fImove on\fP to the nextIP address with the \fBmap\fP command./dev/ipnat.br/etc/services.br/etc/hosts.SH SEE ALSOipnat(4), hosts(5), ipf(5), services(5), ipf(8), ipnat(8)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -