The entries in this file are order-sensitive. The first entry that matches a particular connection will be the one that is used.
If you have more than one ISP link, adding entries to this file will not force connections to go out through a particular link. You must use entries in m[blue]shorewall-rtrulesm[][2](5) or PREROUTING entries in m[blue]shorewall-manglem[][3](5) to do that.
The columns in the file are as follows.
ACTION
Choices for ACTION are:
action[+][(parameter,...)][:level]
CONTINUE[+]:level
LOG:level
MASQUERADE[+][([lowport[-highport]][random])][:level]
NFLOG[(nflog-parameters)]
The nflog-parameters are a comma-separated list of up to 3 numbers:
NFLOG is similar to LOG:NFLOG[(nflog-parameters)], except that the log level is not changed when this ACTION is used in an action or macro body and the invocation of that action or macro specifies a log level.
SNAT[+]([address-or-address-range][:lowport[-highport]][:random][:persistent]|detect)[:level]
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 first.ip.in.range-last.ip.in.range. You may follow the port range with :random in which case assignment of ports from the list will be random. random may also be specified by itself in this column in which case random local port assignments are made for the outgoing connections.
Example: 206.124.146.177-206.124.146.180
You may follow the port range (or :random) with :persistent. This is only useful when an address range is specified and causes a client to be given the same source/destination IP pair.
You may also use the special value detect which causes Shorewall to determine the IP addresses configured on the interface named in the DEST column and substitute them in this column.
Finally, you may also specify a comma-separated list of ranges and/or addresses in this column.
DNS Names names are not allowed.
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 lowport-highport. If this is done, you must specify "tcp", "udp", "dccp" or "stcp" in the PROTO column.
Examples:
192.0.2.4:5000-6000 :4000-5000
You may also specify a single port number, which will be assigned to the outgoing connection, if possible.
ULOG[(ulog-parameters)]
Similar to LOG:ULOG[(ulog-parameters)], except that the log level is not changed when this ACTION is used in an action or macro body and the invocation of that action or macro specifies a log level.
Normally Masq/SNAT rules are evaluated after those for one-to-one NAT (defined in m[blue]shorewall-natm[][8](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]shorewall-natm[][8](5).
SOURCE (Optional) - [interface|address[,address...][exclusion]]
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.
DEST - {interface[:digit][,interface[:digit]]...|$FW}[:[dest-address[,dest-address]...[exclusion]]
Beginning with Shorewall 5.1.12, SNAT may be performed in the nat table's INPUT chain by specifying $FW rather than one or more interfaces.
Each interface must match an entry in m[blue]shorewall-interfacesm[][9](5). Shorewall allows loose matches to wildcard entries in m[blue]shorewall-interfacesm[][9](5). For example, ppp0 in this file will match a m[blue]shorewall-interfacesm[][9](5) entry that defines ppp+.
Where m[blue]more that one internet provider share a single interfacem[][10], the provider is specified by including the provider name or number in parentheses:
eth0(Avvanta)
In that case, you will want to specify the interface's address for that provider as the SNAT parameter.
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]shorewall-exclusionm[][11](5)) as are ipset names preceded by a plus sign '+';
If you wish to inhibit the action of ADD_SNAT_ALIASES for this entry then include the ":" but omit the digit:
eth0(Avvanta): eth2::192.0.2.32/27
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.
PROTO (Optional) - {-|[!]{protocol-name|protocol-number}[,...]|+ipset}
Beginning with Shorewall 4.5.12, this column can accept a comma-separated list of protocols.
Beginning with Shorewall 4.6.0, an ipset name can be specified in this column. This is intended to be used with bitmap:port ipsets.
PORT (Optional) - {-|[!]port-name-or-number[,port-name-or-number]...|+ipset}
Port ranges are of the form lowport:highport.
Beginning with Shorewall 4.6.0, an ipset name can be specified in this column. This is intended to be used with bitmap:port ipsets.
IPSEC (Optional) - [option[,option]...]
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.
reqid=number
spi=<number>
proto=ah|esp|ipcomp
mss=number
mode=transport|tunnel
tunnel-src=address[/mask]
tunnel-dst=address[/mask]
strict
next
yes
MARK - [!]value[/mask][:C]
If you don't want to define a test but need to specify anything in the following columns, place a "-" in this field.
!
value
mask
:C
USER (Optional) - [!][user-name-or-number][:group-name-or-number][+program-name]
Only locally-generated connections will match if this column is non-empty.
When this column is non-empty, the rule matches only if the program generating the output is running under the effective user and/or group specified (or is NOT running under that id if "!" is given).
Examples:
joe
:kids
!:kids
+upnpd
SWITCH - [!]switch-name[={0|1}]
The rule is enabled if the value stored in /proc/net/nf_condition/switch-name is 1. The rule is disabled if that file contains 0 (the default). If '!' is supplied, the test is inverted such that the rule is enabled if the file contains 0.
Within the switch-name, '@0' and '@{0}' are replaced by the name of the chain to which the rule is a added. The switch-name (after '@...' 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.
Switches are normally off. To turn a switch on:
Beginning with Shorewall 4.5.10, when the switch-name is followed by =0 or =1, then the switch is initialized to off or on respectively by the start command. Other commands do not affect the switch setting.
ORIGDEST - [-|address[,address]...[exclusion]|exclusion]
This column was formerly labelled ORIGINAL DEST.
PROBABILITY - [probability]
IPv4 Example 1:
Your entry in the file will be:
#ACTION SOURCE DEST MASQUERADE 192.168.0.0/24 eth0
IPv4 Example 2:
#ACTION SOURCE DEST MASQUERADE 192.168.0.0/24 eth0 MASQUERADE 192.168.1.0/24 eth0
IPv4 Example 3:
#ACTION SOURCE DEST SNAT(206.124.146.176) 192.168.1.0/24 eth0:0
IPv4 Example 4:
#INTERFACE SOURCE ADDRESS PROTO DPORT eth0 172.20.1.0/29 206.124.146.177 tcp smtp eth0 172.20.1.0/29 206.124.146.176
#ACTION SOURCE DEST PROTO PORT SNAT(206.124.146.177) 172.20.1.0/29 eth0 tcp smtp SNAT(206.124.146.176) 172.20.1.0/29 eth0
IPv4 Example 5:
#ACTION SOURCE DEST SNAT(206.124.146.177) - eth0:+myset[dst]
IPv4 Example 6:
/etc/shorewall/tcrules: #ACTION SOURCE DEST PROTO DPORT SPORT USER TEST 1-3:CF 192.168.1.0/24 eth0 ; state=NEW /etc/shorewall/snat: #ACTION SOURCE DEST SNAT(1.1.1.1) 192.168.1.0/24 eth0 { mark=1:C } SNAT(1.1.1.3) 192.168.1.0/24 eth0 { mark=2:C } SNAT(1.1.1.9) 192.168.1.0/24 eth0 { mark=3:C }
IPv6 Example 1:
Your entry in the file will be:
#ACTION SOURCE DEST MASQUERADE 2001:470:b:787::0/64 eth0
IPv6 Example 2:
/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
/etc/shorewall/snat
m[blue]http://www.shorewall.net/configuration_file_basics.htm#Pairsm[][13]
shorewall(8)