'\" t .\" Title: shorewall-masq .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.75.2 .\" Date: 06/28/2012 .\" Manual: [FIXME: manual] .\" Source: [FIXME: source] .\" Language: English .\" .TH "SHOREWALL\-MASQ" "5" "06/28/2012" "[FIXME: source]" "[FIXME: manual]" .\" ----------------------------------------------------------------- .\" * 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" masq \- Shorewall Masquerade/SNAT definition file .SH "SYNOPSIS" .HP \w'\fB/etc/shorewall/masq\fR\ 'u \fB/etc/shorewall/masq\fR .SH "DESCRIPTION" .PP Use this file to define dynamic NAT (Masquerading) and to define Source NAT (SNAT)\&. .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]\fBshorewall\-rtrules\fR\m[]\&\s-2\u[1]\d\s+2(5) or PREROUTING entries in \m[blue]\fBshorewall\-tcrules\fR\m[]\&\s-2\u[2]\d\s+2(5) to do that\&. .sp .5v .RE .PP The columns in the file are as follows\&. .PP \fBINTERFACE:DEST\fR \- {[\fB+\fR]\fIinterfacelist\fR[\fB:\fR[\fIdigit\fR]][\fB:\fR[\fIdest\-address\fR[\fB,\fR\fIdest\-address\fR]\&.\&.\&.[\fIexclusion\fR]]|COMMENT} .RS 4 Outgoing \fIinterfacelist\fR\&. This may be a comma\-separated list of interface names\&. This is usually your internet interface\&. If ADD_SNAT_ALIASES=Yes in \m[blue]\fBshorewall\&.conf\fR\m[]\&\s-2\u[3]\d\s+2(5), you may add ":" and a \fIdigit\fR to indicate that you want the alias added with that name (e\&.g\&., eth0:0)\&. This will allow the alias to be displayed with ifconfig\&. \fBThat is the only use for the alias name; it may not appear in any other place in your Shorewall configuratio\fRn\&. .sp Each interface must match an entry in \m[blue]\fBshorewall\-interfaces\fR\m[]\&\s-2\u[4]\d\s+2(5)\&. Shorewall allows loose matches to wildcard entries in \m[blue]\fBshorewall\-interfaces\fR\m[]\&\s-2\u[4]\d\s+2(5)\&. For example, ppp0 in this file will match a \m[blue]\fBshorewall\-interfaces\fR\m[]\&\s-2\u[4]\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[5]\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 interfaces\*(Aqs address for that provider in the ADDRESS column\&. .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]\fBshorewall\-exclusion\fR\m[]\&\s-2\u[6]\d\s+2(5)) as are ipset names preceded by a plus sign \*(Aq+\*(Aq; .sp If you wish to inhibit the action of ADD_SNAT_ALIASES for this entry then include the ":" but omit the digit: .sp .if n \{\ .RS 4 .\} .nf eth0(Avvanta): eth2::192\&.0\&.2\&.32/27 .fi .if n \{\ .RE .\} .sp Normally Masq/SNAT rules are evaluated after those for one\-to\-one NAT (defined in \m[blue]\fBshorewall\-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, prefix the interface name with "+": .sp .if n \{\ .RS 4 .\} .nf +eth0 +eth0:192\&.0\&.2\&.32/27 +eth0:2 .fi .if n \{\ .RE .\} .sp This feature should only be required if you need to insert rules in this file that preempt entries in \m[blue]\fBshorewall\-nat\fR\m[]\&\s-2\u[7]\d\s+2(5)\&. .sp Comments may be attached to Netfilter rules generated from entries in this file through the use of COMMENT lines\&. These lines begin with the word 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 with only the word COMMENT\&. .RE .PP \fBSOURCE\fR (Formerly called SUBNET) \- {\fIinterface\fR[:\fIexclusion\fR]|\fIaddress\fR[\fB,\fR\fIaddress\fR][\fIexclusion\fR]} .RS 4 Set of hosts that you wish to masquerade\&. You can specify this as an \fIaddress\fR (net or host) or as an \fIinterface\fR (use of an \fIinterface\fR is deprecated)\&. If you give the name of an interface, the interface must be up before you start the firewall and the Shorewall rules compiler will warn you of that fact\&. (Shorewall will use your main routing table to determine the appropriate addresses to masquerade)\&. .sp In order to exclude a address of the specified SOURCE, you may append an \fIexclusion\fR ("!" and a comma\-separated list of IP addresses (host or net) that you wish to exclude (see \m[blue]\fBshorewall\-exclusion\fR\m[]\&\s-2\u[6]\d\s+2(5)))\&. Note that a colon (":") must appear between an \fIinterface\fR name and the \fIexclusion\fR; .sp Example: eth1:!192\&.168\&.1\&.4,192\&.168\&.32\&.0/27 .sp In that example traffic from eth1 would be masqueraded unless it came from 192\&.168\&.1\&.4 or 196\&.168\&.32\&.0/27 .sp The preferred way to specify the SOURCE is to supply 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 \fBADDRESS\fR (Optional) \- [\fB\-\fR|\fBNONAT\fR|[\fIaddress\-or\-address\-range\fR[,\fIaddress\-or\-address\-range\fR]\&.\&.\&.][:\fIlowport\fR\fB\-\fR\fIhighport\fR][\fB:random\fR][:persistent]|\fBdetect\fR|\fBrandom\fR] .RS 4 If you specify an address here, SNAT will be used and this will be the source address\&. If ADD_SNAT_ALIASES is set to Yes or yes in \m[blue]\fBshorewall\&.conf\fR\m[]\&\s-2\u[3]\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\&. Unlike \fBrandom\fR, \fBpersistent\fR may not be used by itself\&. .sp You may also use the special value "detect" which causes Shorewall to determine the IP addresses configured on the interface named in the INTERFACES 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 This column may not contain DNS Names\&. .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" or "udp" in the PROTO column\&. .sp Examples: .sp .if n \{\ .RS 4 .\} .nf 192\&.0\&.2\&.4:5000\-6000 :4000\-5000 .fi .if n \{\ .RE .\} .sp If you simply place \fBNONAT\fR in this column, no rewriting of the source IP address or port number will be performed\&. This is useful if you want particular traffic to be exempt from the entries that follow in the file\&. .sp If you want to leave this column empty but you need to specify the next column then place a hyphen ("\-") here\&. .RE .PP \fBPROTO\fR (Optional) \- {\fB\-\fR|[!]\fIprotocol\-name\fR|[!]\fIprotocol\-number\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\&. .RE .PP \fBPORT(S)\fR (Optional) \- [[!]\fIport\-name\-or\-number\fR[,\fIport\-name\-or\-number\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\&. .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/GROUP\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 .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\&. \fIswitch\-name\fR 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\&. .RE .SH "EXAMPLES" .PP Example 1: .RS 4 You have a simple masquerading setup where eth0 connects to a DSL or cable modem and eth1 connects to your local network with subnet 192\&.168\&.0\&.0/24\&. .sp Your entry in the file will be: .sp .if n \{\ .RS 4 .\} .nf #INTERFACE SOURCE eth0 192\&.168\&.0\&.0/24 .fi .if n \{\ .RE .\} .RE .PP Example 2: .RS 4 You add a router to your local network to connect subnet 192\&.168\&.1\&.0/24 which you also want to masquerade\&. You then add a second entry for eth0 to this file: .sp .if n \{\ .RS 4 .\} .nf #INTERFACE SOURCE eth0 192\&.168\&.1\&.0/24 .fi .if n \{\ .RE .\} .RE .PP Example 3: .RS 4 You have an IPSEC tunnel through ipsec0 and you want to masquerade packets coming from 192\&.168\&.1\&.0/24 but only if these packets are destined for hosts in 10\&.1\&.1\&.0/24: .sp .if n \{\ .RS 4 .\} .nf #INTERFACE SOURCE ipsec0:10\&.1\&.1\&.0/24 196\&.168\&.1\&.0/24 .fi .if n \{\ .RE .\} .RE .PP Example 4: .RS 4 You want all outgoing traffic from 192\&.168\&.1\&.0/24 through eth0 to use source address 206\&.124\&.146\&.176 which is NOT the primary address of eth0\&. You want 206\&.124\&.146\&.176 to be added to eth0 with name eth0:0\&. .sp .if n \{\ .RS 4 .\} .nf #INTERFACE SOURCE ADDRESS eth0:0 192\&.168\&.1\&.0/24 206\&.124\&.146\&.176 .fi .if n \{\ .RE .\} .RE .PP Example 5: .RS 4 You want all outgoing SMTP traffic entering the firewall from 172\&.20\&.1\&.0/29 to be sent from eth0 with source IP address 206\&.124\&.146\&.177\&. You want all other outgoing traffic from 172\&.20\&.1\&.0/29 to be sent from eth0 with source IP address 206\&.124\&.146\&.176\&. .sp .if n \{\ .RS 4 .\} .nf #INTERFACE SOURCE ADDRESS PROTO PORT(S) eth0 172\&.20\&.1\&.0/29 206\&.124\&.146\&.177 tcp smtp eth0 172\&.20\&.1\&.0/29 206\&.124\&.146\&.176 .fi .if n \{\ .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 The order of the above two rules is significant! .sp .5v .RE .RE .PP Example 6: .RS 4 Connections leaving on eth0 and destined to any host defined in the ipset \fImyset\fR should have the source IP address changed to 206\&.124\&.146\&.177\&. .sp .if n \{\ .RS 4 .\} .nf #INTERFACE SOURCE ADDRESS eth0:+myset[dst] \- 206\&.124\&.146\&.177 .fi .if n \{\ .RE .\} .RE .SH "FILES" .PP /etc/shorewall/masq .SH "SEE ALSO" .PP \m[blue]\fBhttp://shorewall\&.net/configuration_file_basics\&.htm#Pairs\fR\m[] .PP shorewall(8), shorewall\-accounting(5), shorewall\-actions(5), shorewall\-blacklist(5), shorewall\-exclusion(5), shorewall\-hosts(5), shorewall_interfaces(5), shorewall\-ipsets(5), shorewall\-maclist(5), shorewall\-nat(5), shorewall\-netmap(5), shorewall\-params(5), shorewall\-policy(5), shorewall\-providers(5), shorewall\-proxyarp(5), shorewall\-rtrules(5), shorewall\-routestopped(5), shorewall\-rules(5), shorewall\&.conf(5), shorewall\-secmarks(5), shorewall\-tcclasses(5), shorewall\-tcdevices(5), shorewall\-tcrules(5), shorewall\-tos(5), shorewall\-tunnels(5), shorewall\-zones(5) .SH "NOTES" .IP " 1." 4 shorewall-rtrules .RS 4 \%http://www.shorewall.net/manpages/shorewall-rtrules.html .RE .IP " 2." 4 shorewall-tcrules .RS 4 \%http://www.shorewall.net/manpages/shorewall-tcrules.html .RE .IP " 3." 4 shorewall.conf .RS 4 \%http://www.shorewall.net/manpages/shorewall.conf.html .RE .IP " 4." 4 shorewall-interfaces .RS 4 \%http://www.shorewall.net/manpages/shorewall-interfaces.html .RE .IP " 5." 4 more that one internet provider share a single interface .RS 4 \%http://www.shorewall.net/4.4/MultiISP.html#Shared .RE .IP " 6." 4 shorewall-exclusion .RS 4 \%http://www.shorewall.net/manpages/shorewall-exclusion.html .RE .IP " 7." 4 shorewall-nat .RS 4 \%http://www.shorewall.net/manpages/shorewall-nat.html .RE