The CONFIG_PATH option in m[blue]shorewall[6].conf(5)m[][20] determines where the compiler searches for configuration files. The default setting is CONFIG_PATH=/etc/shorewall:/usr/share/shorewall which means that the compiler first looks in /etc/shorewall and if it doesn't find the file, it then looks in /usr/share/shorewall.
You can change this setting to have the compiler look in different places. For example, if you want to put your own versions of standard macros in /etc/shorewall/Macros, then you could set CONFIG_PATH=/etc/shorewall:/etc/shorewall/Macros:/usr/share/shorewall and the compiler will use your versions rather than the standard ones.
You may place comments in configuration files by making the first non-whitespace character a pound sign ("#"). You may also place comments at the end of any line, again by delimiting the comment from the rest of the line with a pound sign.
Example 1. Comments in a Configuration File
# This is a comment ACCEPT net $FW tcp www #This is an end-of-line comment
Except in m[blue]shorewall.conf(5)m[][1] and m[blue]params(5)m[][2], if a comment ends with a backslash ("\"), the next line will also be treated as a comment. See Line Continuation below.
Most of the configuration files are organized into space-separated columns. If you don't want to supply a value in a column but want to supply a value in a following column, simply enter '-' to make the column appear empty.
Example:
#INTERFACE BROADCAST OPTIONS br0 - routeback
Lines may be continued using the usual backslash ("\") followed immediately by a new line character (Enter key).
ACCEPT net $FW tcp \␍ smtp,www,pop3,imap #Services running on the firewall
What follows does NOT apply to m[blue]shorewall-params(5)m[][31] and m[blue]shorewall.conf(5)m[][1].
In certain cases, leading white space is ignored in continuation lines:
Example (/etc/shorewall/rules):
#ACTION SOURCE DEST PROTO DPORT ACCEPT net:\ 206.124.146.177,\ 206.124.146.178,\ 206.124.146.180\ dmz tcp 873
The leading white space on the first through third continuation lines is ignored so the SOURCE column effectively contains "net:206.124.146.177,206.124.147.178,206.124.146.180". Because the third continuation line does not end with a comma or colon, the leading white space in the last line is not ignored.
A trailing backslash is not ignored in a comment. So the continued rule above can be commented out with a single '#' as follows:
#ACTION SOURCE DEST PROTO DPORT #ACCEPT net:\ 206.124.146.177,\ 206.124.146.178,\ 206.124.146.180\ dmz tcp 873
Some of the configuration files now have a large number of columns. That makes it awkward to specify a value for one of the right-most columns as you must have the correct number of intervening '-' columns.
This problem is addressed by allowing column values to be specified as column-name/value pairs.
There is considerable flexibility in how you specify the pairs:
The value may optionally be enclosed in double quotes.
The pairs must be separated by white space, but you can add a comma adjacent to the values for readability as in:
In Shorewall 5.0.3, the sample configuration files and the man pages were updated to use the same column names in both the column headings and in the alternate specification format. The following table shows the column names for each of the table-oriented configuration files.
Column names are case-insensitive.
File |
Column names
|
accounting |
action,chain, source, dest, proto, dport, sport, user,
mark, ipsec, headers |
conntrack |
action,source,dest,proto,dport,sport,user,switch
|
blacklist |
networks,proto,port,options
|
blrules |
action,source,dest,proto,dport,sport,origdest,rate,user,mark,connlimit,time,headers,switch,helper
|
ecn |
interface,hosts. Beginning with Shorewall 4.5.4, 'host' is
a synonym for 'hosts'. |
hosts |
zone,hosts,options. Beginning with Shorewall 4.5.4, 'host'
is a synonym for 'hosts'. |
interfaces |
zone,interface,broadcast,options
|
maclist |
disposition,interface,mac,addresses
|
mangle |
action,source,dest,proto,dport,sport,user,test,length,tos,connbytes,helper,headers
|
masq |
interface,source,address,proto,port,ipsec,mark,user,switch
|
nat |
external,interface,internal,allints,local
|
netmap |
type,net1,interface,net2,net3,proto,dport,sport
|
notrack |
source,dest,proto,dport,sport,user
|
policy |
source,dest,policy,loglevel,limit,connlimit
|
providers |
table,number,mark,duplicate,interface,gateway,options,copy
|
proxyarp and proxyndp |
address,interface,external,haveroute,persistent
|
rtrules |
source,dest,provider,priority
|
routes |
provider,dest,gateway,device
|
routestopped |
interface,hosts,options,proto,dport,sport
|
rules |
action,source,dest,proto,dport,sport,origdest,rate,user,mark,connlimit,time,headers,switch,helper
|
secmarks |
secmark,chain,source,dest,proto,dport,sport,user,mark
|
tcclasses |
interface,mark,rate,ceil,prio,options
|
tcdevices |
interface,in_bandwidth,out_bandwidth,options,redirect
|
tcfilters |
class,source,dest,proto,dport,sport,tos,length
|
tcinterfaces |
interface,type,in_bandwidth,out_bandwidth
|
tcpri |
band,proto,port,address,interface,helper
|
tcrules |
mark,source,dest,proto,dport,sport,user,test,length,tos,connbytes,helper,headers.
Beginning with Shorewall 4.5.3, 'action' is a synonym for 'mark'. |
tos |
source,dest,proto,dport,sport,tos,mark
|
tunnels |
type,zone,gateway,gateway_zone. Beginning with Shorewall
4.5.3, 'gateways' is a synonym for 'gateway'. Beginning with Shorewall 4.5.4, 'gateway_zones' is a synonym for 'gateway_zone'. |
zones |
zone,type,options,in_options,out_options
|
Example (rules file):
#ACTION SOURCE DEST PROTO DPORT DNAT net loc:10.0.0.1 tcp 80 ; mark="88"
Here's the same line in several equivalent formats:
{ action=>DNAT, source=>net, dest=>loc:10.0.0.1, proto=>tcp, dport=>80, mark=>88 } ; action:"DNAT" source:"net" dest:"loc:10.0.0.1" proto:"tcp" dport:"80" mark:"88" DNAT { source=net dest=loc:10.0.0.1 proto=tcp dport=80 mark=88 }
Beginning with Shorewall 5.0.11, ip[6]table comments can be attached to individual rules using the comment keyword.
Example from the rules file:
ACCEPT net $FW { proto=tcp, dport=22, comment="Accept \"SSH\"" }
As shown in that example, when the comment contains whitespace, it must be enclosed in double quotes and any embedded double quotes must be escaped using a backslash ("\").
Several of the files include a TIME column that allows you to specify times when the rule is to be applied. Contents of this column is a list of timeelements separated by apersands (&).
Each timeelement is one of the following:
timestart=hh:mm[:ss]
timestop=hh:mm[:ss]
contiguous
utc
localtz
kerneltz
weekdays=ddd[,ddd]...
monthdays=dd[,dd],...
datestart=yyyy[-mm[-dd[Thh[:mm[:ss]]]]]
datestop=yyyy[-mm[-dd[Thh[:mm[:ss]]]]]
Examples:
To match on weekends, use:
weekdays=Sat,Sun
Or, to match (once) on a national holiday block:
datestart=2016-12-24&datestop=2016-12-27
Since the stop time is actually inclusive, you would need the following stop time to not match the first second of the new day:
datestart=2016-12-24T17:00&datestop=2016-12-27T23:59:59
During Lunch Hour
The fourth Friday in the month:
weekdays=Fri&monthdays=22,23,24,25,26,27,28
Matching across days might not do what is expected. For instance,
weekdays=Mon×tart=23:00×top=01:00
Will match Monday, for one hour from midnight to 1 a.m., and then again for another hour from 23:00 onwards. If this is unwanted, e.g. if you would like 'match for two hours from Montay 23:00 onwards' you need to also specify the contiguous option in the example above.
here are times when you would like to enable or disable one or more rules in the configuration without having to do a shorewall reload or shorewall restart. This may be accomplished using the SWITCH column in m[blue]shorewall-rulesm[][32] (5) or m[blue]shorewall6-rulesm[][33] (5). Using this column requires that your kernel and iptables include Condition Match Support and you must be running Shorewall 4.4.24 or later. See the output of shorewall show capabilities and shorewall version to determine if you can use this feature.
The SWITCH column contains the name of a switch. Each switch is initially in the off position. You can turn on the switch named switch1 by:
You can turn it off again by:
If you simply include the switch name in the SWITCH column, then the rule is enabled only when the switch is on. If you precede the switch name with ! (e.g., !switch1), then the rule is enabled only when the switch is off. Switch settings are retained over shorewall restart.
Shorewall requires that switch names:
Multiple rules can be controlled by the same switch.
Example:
Forward port 80 to dmz host $BACKUP if switch 'primary_down' is on.
#ACTION SOURCE DEST PROTO DPORT SPORT ORIGDEST RATE USER MARK CONNLIMIT TIME HEADERS SWITCH DNAT net dmz:$BACKUP tcp 80 - - - - - - - - primary_down