'\" t .\" Title: shorewall6-masq .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.78.1 .\" Date: 03/16/2017 .\" Manual: Configuration Files .\" Source: Configuration Files .\" Language: English .\" .TH "SHOREWALL6\-MASQ" "5" "03/16/2017" "Configuration Files" "Configuration Files" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" snat \- Shorewall6 SNAT/Masquerade definition file .SH "SYNOPSIS" .HP \w'\fB/etc/shorewall6/snat\fR\ 'u \fB/etc/shorewall6/snat\fR .SH "DESCRIPTION" .PP This file is used to define dynamic NAT (Masquerading) and to define Source NAT (SNAT)\&. While still supported, its use is deprecated in favor of \m[blue]\fBshorewall6\-snat\fR\m[]\&\s-2\u[1]\d\s+2(5) which was introduced in Shorewall 5\&.0\&.14\&. .if n \{\ .sp .\} .RS 4 .it 1 an-trap .nr an-no-space-flag 1 .nr an-break-flag 1 .br .ps +1 \fBWarning\fR .ps -1 .br .PP The entries in this file are order\-sensitive\&. The first entry that matches a particular connection will be the one that is used\&. .sp .5v .RE .if n \{\ .sp .\} .RS 4 .it 1 an-trap .nr an-no-space-flag 1 .nr an-break-flag 1 .br .ps +1 \fBWarning\fR .ps -1 .br .PP If you have more than one ISP link, adding entries to this file will \fBnot\fR force connections to go out through a particular link\&. You must use entries in \m[blue]\fBshorewall6\-rtrules\fR\m[]\&\s-2\u[2]\d\s+2(5) or PREROUTING entries in \m[blue]\fBshorewall\-tcrules\fR\m[]\&\s-2\u[3]\d\s+2(5) to do that\&. .sp .5v .RE .PP The columns in the file are as follows\&. .PP \fBACTION\fR .RS 4 Defines the type of rule to generate\&. Choices are: .PP \fBMASQUERADE\fR[+][([\fIlowport\fR\-\fIhighport\fR][\fBrandom\fR])] .RS 4 Causes matching outgoing packages to have their source IP address set to the primary IP address of the interface specified in the DEST column\&. if \fIlowport\fR\-\fIhighport\fR is given, that port range will be used to assign a source port\&. If option \fBrandom\fR is used then port mapping will be randomized\&. MASQUERADE should only be used when the DEST interface has a dynamic IP address\&. Otherwise, SNAT should be used and should specify the interface\*(Aqs static address\&. .RE .PP \fBSNAT\fR[+]([\fIaddress\-or\-address\-range\fR][:\fIlowport\fR\fB\-\fR\fIhighport\fR][\fB:random\fR][:\fBpersistent\fR]|\fBdetect\fR| .RS 4 If you specify an address here, matching packets will have their source address set to that address\&. If ADD_SNAT_ALIASES is set to Yes or yes in \m[blue]\fBshorewall6\&.conf\fR\m[]\&\s-2\u[4]\d\s+2(5) then Shorewall will automatically add this address to the INTERFACE named in the first column\&. .sp You may also specify a range of up to 256 IP addresses if you want the SNAT address to be assigned from that range in a round\-robin fashion by connection\&. The range is specified by \fIfirst\&.ip\&.in\&.range\fR\-\fIlast\&.ip\&.in\&.range\fR\&. You may follow the port range with\fB :random\fR in which case assignment of ports from the list will be random\&. \fBrandom\fR may also be specified by itself in this column in which case random local port assignments are made for the outgoing connections\&. .sp Example: 206\&.124\&.146\&.177\-206\&.124\&.146\&.180 .sp You may follow the port range (or \fB:random\fR) with \fB:persistent\fR\&. This is only useful when an address range is specified and causes a client to be given the same source/destination IP pair\&. This feature replaces the SAME modifier which was removed from Shorewall in version 4\&.4\&.0\&. .sp You may also use the special value \fBdetect\fR which causes Shorewall to determine the IP addresses configured on the interface named in the DEST column and substitute them in this column\&. .sp Finally, you may also specify a comma\-separated list of ranges and/or addresses in this column\&. .sp DNS Names names are not allowed\&. .sp Normally, Netfilter will attempt to retain the source port number\&. You may cause netfilter to remap the source port by following an address or range (if any) by ":" and a port range with the format \fIlowport\fR\-\fIhighport\fR\&. If this is done, you must specify "tcp", "udp", "dccp" or "stcp" in the PROTO column\&. .sp Example: .sp .if n \{\ .RS 4 .\} .nf [2001:470:a:787::2]:5000\-6000 .fi .if n \{\ .RE .\} .RE .PP CONTINUE[+] .RS 4 Causes matching packets to be exempted from any following rules in the file\&. .RE .PP \fB\fIaction\fR\fR[+][(\fIparameter\fR,\&.\&.\&.)] .RS 4 where \fIaction\fR is an action declared in \m[blue]\fBshorewall6\-actions(5)\fR\m[]\&\s-2\u[5]\d\s+2 with the \fBnat\fR option\&. See \m[blue]\fBwww\&.shorewall\&.net/Actions\&.html\fR\m[]\&\s-2\u[6]\d\s+2 for further information\&. .RE .sp Normally Masq/SNAT rules are evaluated after those for one\-to\-one NAT (defined in \m[blue]\fBshorewall6\-nat\fR\m[]\&\s-2\u[7]\d\s+2(5))\&. If you want the rule to be applied before one\-to\-one NAT rules, follow the action name with "+": This feature should only be required if you need to insert rules in this file that preempt entries in \m[blue]\fBshorewall6\-nat\fR\m[]\&\s-2\u[7]\d\s+2(5)\&. .RE .PP \fBSOURCE\fR (Optional) \- [\fIinterface\fR|\fIaddress\fR[\fB,\fR\fIaddress\fR\&.\&.\&.][\fIexclusion\fR]] .RS 4 Set of hosts that you wish to SNAT; one or more host or network addresses separated by comma\&. You may use ipset names preceded by a plus sign (+) to specify a set of hosts\&. .RE .PP \fBDEST\fR \- {\fIinterface\fR|[\fB:\fR[\fIdest\-address\fR[\fB,\fR\fIdest\-address\fR]\&.\&.\&.[\fIexclusion\fR]]|?COMMENT} .RS 4 Outgoing \fIinterface\fR\&. This is usually your internet interface\&. .sp The \fIinterface\fR must match an entry in \m[blue]\fBshorewall6\-interfaces\fR\m[]\&\s-2\u[8]\d\s+2(5)\&. Shorewall allows loose matches to wildcard entries in \m[blue]\fBshorewall6\-interfaces\fR\m[]\&\s-2\u[8]\d\s+2(5)\&. For example, ppp0 in this file will match a \m[blue]\fBshorewall6\-interfaces\fR\m[]\&\s-2\u[8]\d\s+2(5) entry that defines ppp+\&. .sp Where \m[blue]\fBmore that one internet provider share a single interface\fR\m[]\&\s-2\u[9]\d\s+2, the provider is specified by including the provider name or number in parentheses: .sp .if n \{\ .RS 4 .\} .nf eth0(Avvanta) .fi .if n \{\ .RE .\} .sp In that case, you will want to specify the interface\*(Aqs address for that provider as the SNAT parameter\&. .sp The interface may be qualified by adding the character ":" followed by a comma\-separated list of destination host or subnet addresses to indicate that you only want to change the source IP address for packets being sent to those particular destinations\&. Exclusion is allowed (see \m[blue]\fBshorewall6\-exclusion\fR\m[]\&\s-2\u[10]\d\s+2(5)) as are ipset names preceded by a plus sign \*(Aq+\*(Aq\&. .sp Comments may be attached to Netfilter rules generated from entries in this file through the use of ?COMMENT lines\&. These lines begin with ?COMMENT; the remainder of the line is treated as a comment which is attached to subsequent rules until another ?COMMENT line is found or until the end of the file is reached\&. To stop adding comments to rules, use a line containing only ?COMMENT\&. .RE .PP \fBPROTO\fR (Optional) \- {\fB\-\fR|[!]{\fIprotocol\-name\fR|\fIprotocol\-number\fR}[,\&.\&.\&.]|+\fIipset\fR} .RS 4 If you wish to restrict this entry to a particular protocol then enter the protocol name (from protocols(5)) or number here\&. .sp Beginning with Shorewall 4\&.5\&.12, this column can accept a comma\-separated list of protocols\&. .sp Beginning with Shorewall 4\&.6\&.0, an \fIipset\fR name can be specified in this column\&. This is intended to be used with bitmap:port ipsets\&. .RE .PP \fBDPORT\fR (Optional) \- {\-|[!]\fIport\-name\-or\-number\fR[,\fIport\-name\-or\-number\fR]\&.\&.\&.|+\fIipset\fR} .RS 4 If the PROTO column specifies TCP (6), UDP (17), DCCP (33), SCTP (132) or UDPLITE (136) then you may list one or more port numbers (or names from services(5)) or port ranges separated by commas\&. .sp Port ranges are of the form \fIlowport\fR:\fIhighport\fR\&. .sp Beginning with Shorewall 4\&.6\&.0, an \fIipset\fR name can be specified in this column\&. This is intended to be used with bitmap:port ipsets\&. .RE .PP \fBIPSEC\fR (Optional) \- [\fIoption\fR[\fB,\fR\fIoption\fR]\&.\&.\&.] .RS 4 If you specify a value other than "\-" in this column, you must be running kernel 2\&.6 and your kernel and iptables must include policy match support\&. .sp Comma\-separated list of options from the following\&. Only packets that will be encrypted via an SA that matches these options will have their source address changed\&. .PP \fBreqid=\fR\fInumber\fR .RS 4 where \fInumber\fR is specified using setkey(8) using the \*(Aqunique:\fInumber\fR option for the SPD level\&. .RE .PP \fBspi=\fR .RS 4 where \fInumber\fR is the SPI of the SA used to encrypt/decrypt packets\&. .RE .PP \fBproto=\fR\fBah\fR|\fBesp\fR|\fBipcomp\fR .RS 4 IPSEC Encapsulation Protocol .RE .PP \fBmss=\fR\fInumber\fR .RS 4 sets the MSS field in TCP packets .RE .PP \fBmode=\fR\fBtransport\fR|\fBtunnel\fR .RS 4 IPSEC mode .RE .PP \fBtunnel\-src=\fR\fIaddress\fR[/\fImask\fR] .RS 4 only available with mode=tunnel .RE .PP \fBtunnel\-dst=\fR\fIaddress\fR[/\fImask\fR] .RS 4 only available with mode=tunnel .RE .PP \fBstrict\fR .RS 4 Means that packets must match all rules\&. .RE .PP \fBnext\fR .RS 4 Separates rules; can only be used with strict .RE .PP \fByes\fR .RS 4 When used by itself, causes all traffic that will be encrypted/encapsulated to match the rule\&. .RE .RE .PP \fBMARK\fR \- [\fB!\fR]\fIvalue\fR[/\fImask\fR][\fB:C\fR] .RS 4 Defines a test on the existing packet or connection mark\&. The rule will match only if the test returns true\&. .sp If you don\*(Aqt want to define a test but need to specify anything in the following columns, place a "\-" in this field\&. .PP ! .RS 4 Inverts the test (not equal) .RE .PP \fIvalue\fR .RS 4 Value of the packet or connection mark\&. .RE .PP \fImask\fR .RS 4 A mask to be applied to the mark before testing\&. .RE .PP \fB:C\fR .RS 4 Designates a connection mark\&. If omitted, the packet mark\*(Aqs value is tested\&. .RE .RE .PP \fBUSER\fR (Optional) \- [\fB!\fR][\fIuser\-name\-or\-number\fR][\fB:\fR\fIgroup\-name\-or\-number\fR][\fB+\fR\fIprogram\-name\fR] .RS 4 Only locally\-generated connections will match if this column is non\-empty\&. .sp When this column is non\-empty, the rule matches only if the program generating the output is running under the effective \fIuser\fR and/or \fIgroup\fR specified (or is NOT running under that id if "!" is given)\&. .sp Examples: .PP joe .RS 4 program must be run by joe .RE .PP :kids .RS 4 program must be run by a member of the \*(Aqkids\*(Aq group .RE .PP !:kids .RS 4 program must not be run by a member of the \*(Aqkids\*(Aq group .RE .PP +upnpd .RS 4 #program named upnpd .if n \{\ .sp .\} .RS 4 .it 1 an-trap .nr an-no-space-flag 1 .nr an-break-flag 1 .br .ps +1 \fBImportant\fR .ps -1 .br The ability to specify a program name was removed from Netfilter in kernel version 2\&.6\&.14\&. .sp .5v .RE .RE .RE .PP \fBSWITCH \- [!]\fR\fB\fIswitch\-name\fR\fR\fB[={0|1}]\fR .RS 4 Added in Shorewall 4\&.5\&.1 and allows enabling and disabling the rule without requiring \fBshorewall restart\fR\&. .sp The rule is enabled if the value stored in /proc/net/nf_condition/\fIswitch\-name\fR is 1\&. The rule is disabled if that file contains 0 (the default)\&. If \*(Aq!\*(Aq is supplied, the test is inverted such that the rule is enabled if the file contains 0\&. .sp Within the \fIswitch\-name\fR, \*(Aq@0\*(Aq and \*(Aq@{0}\*(Aq are replaced by the name of the chain to which the rule is a added\&. The \fIswitch\-name\fR (after \*(Aq@\&.\&.\&.\*(Aq expansion) must begin with a letter and be composed of letters, decimal digits, underscores or hyphens\&. Switch names must be 30 characters or less in length\&. .sp Switches are normally \fBoff\fR\&. To turn a switch \fBon\fR: .RS 4 \fBecho 1 > /proc/net/nf_condition/\fR\fB\fIswitch\-name\fR\fR .RE To turn it \fBoff\fR again: .RS 4 \fBecho 0 > /proc/net/nf_condition/\fR\fB\fIswitch\-name\fR\fR .RE Switch settings are retained over \fBshorewall restart\fR\&. .sp Beginning with Shorewall 4\&.5\&.10, when the \fIswitch\-name\fR is followed by \fB=0\fR or \fB=1\fR, then the switch is initialized to off or on respectively by the \fBstart\fR command\&. Other commands do not affect the switch setting\&. .RE .PP \fBORIGDEST\fR \- [\fB\-\fR|\fIaddress\fR[,\fIaddress\fR]\&.\&.\&.[\fIexclusion\fR]|\fIexclusion\fR] .RS 4 (Optional) This column may be included and may contain one or more addresses (host or network) separated by commas\&. Address ranges are not allowed\&. When this column is supplied, rules are generated that require that the original destination address matches one of the listed addresses\&. It is useful for specifying that SNAT should occur only for connections that were acted on by a DNAT when they entered the firewall\&. .sp This column was formerly labelled ORIGINAL DEST\&. .RE .PP \fBPROBABILITY\fR \- [\fIprobability\fR] .RS 4 Added in Shorewall 5\&.0\&.0\&. When non\-empty, requires the Statistics Match capability in your kernel and ip6tables and causes the rule to match randomly but with the given \fIprobability\fR\&. The \fIprobability\fR is a number 0 < \fIprobability\fR <= 1 and may be expressed at up to 8 decimal points of precision\&. .RE .SH "EXAMPLES" .PP Example 1: .RS 4 You have a simple \*(Aqmasquerading\*(Aq setup where eth0 connects to a DSL or cable modem and eth1 connects to your local network with subnet 2001:470:b:787::0/64 .sp Your entry in the file will be: .sp .if n \{\ .RS 4 .\} .nf #ACTION SOURCE DEST MASQUERADE 2001:470:b:787::0/64 eth0 .fi .if n \{\ .RE .\} .RE .PP Example 2: .RS 4 Your sit1 interface has two public IP addresses: 2001:470:a:227::1 and 2001:470:b:227::1\&. You want to use the iptables statistics match to masquerade outgoing connections evenly between these two addresses\&. .sp .if n \{\ .RS 4 .\} .nf /etc/shorewall/snat: #ACTION SOURCE DEST SNAT(2001:470:a:227::1) ::/0 sit1 { probability=0\&.50 } SNAT(2001:470:a:227::2) ::/0 sit .fi .if n \{\ .RE .\} .RE .SH "FILES" .PP /etc/shorewall6/snat .SH "NOTES" .IP " 1." 4 shorewall6-snat .RS 4 \%http://www.shorewall.netshorewall6-snat.html .RE .IP " 2." 4 shorewall6-rtrules .RS 4 \%http://www.shorewall.net/manpages6/shorewall6-rtrules.html .RE .IP " 3." 4 shorewall-tcrules .RS 4 \%http://www.shorewall.net/manpages6/shorewall6-tcrules.html .RE .IP " 4." 4 shorewall6.conf .RS 4 \%http://www.shorewall.netshorewall6.conf.html .RE .IP " 5." 4 shorewall6-actions(5) .RS 4 \%http://www.shorewall.netshorewall6-actions.html .RE .IP " 6." 4 www.shorewall.net/Actions.html .RS 4 \%http://www.shorewall.net/Actions.html .RE .IP " 7." 4 shorewall6-nat .RS 4 \%http://www.shorewall.net/manpages6/shorewall6-nat.html .RE .IP " 8." 4 shorewall6-interfaces .RS 4 \%http://www.shorewall.net/manpages6/shorewall6-interfaces.html .RE .IP " 9." 4 more that one internet provider share a single interface .RS 4 \%http://www.shorewall.net/4.4/MultiISP.html#Shared .RE .IP "10." 4 shorewall6-exclusion .RS 4 \%http://www.shorewall.net/manpages6/shorewall6-exclusion.html .RE