forked from extern/shorewall_code
Compare commits
84 Commits
5.0.13-RC1
...
5.0.14
Author | SHA1 | Date | |
---|---|---|---|
|
8441ac5c5f | ||
|
01a6881f4f | ||
|
f917670fbd | ||
|
c376740329 | ||
|
4169520d63 | ||
|
53d97bbcc8 | ||
|
9ae36e1989 | ||
|
60619fb3cb | ||
|
41ecee356b | ||
|
e188bde6c4 | ||
|
6e08717089 | ||
|
d37967f32f | ||
|
10c1ad245a | ||
|
032a16eb43 | ||
|
a89d8b3af4 | ||
|
3f68814a38 | ||
|
3a70185284 | ||
|
95a1e65016 | ||
|
282253022e | ||
|
174f46f3e6 | ||
|
4d77d673e8 | ||
|
e4e424bbdc | ||
|
71fb1a8cbd | ||
|
46c8147521 | ||
|
de3b05ea41 | ||
|
ae9b57d854 | ||
|
1a06765d14 | ||
|
579910fdb8 | ||
|
21877d5fcb | ||
|
0b9387f09c | ||
|
ee8ffc3ceb | ||
|
fdfd8b919b | ||
|
3d3ae81bce | ||
|
3b6b89336e | ||
|
fc0ad7cd2e | ||
|
c9b1b7684c | ||
|
b8ec460a1a | ||
|
46b8e2e957 | ||
|
0ed813972b | ||
|
f9cfde91e5 | ||
|
3df488e710 | ||
|
0efc7a4899 | ||
|
d241421630 | ||
|
e0203bca87 | ||
|
6e30c286c3 | ||
|
3874bb9fa6 | ||
|
9c749731c5 | ||
|
34f2aeacea | ||
|
5b26f1939b | ||
|
13a321726c | ||
|
b160845713 | ||
|
71566f0ab0 | ||
|
e4169ede4a | ||
|
b44628ddc8 | ||
|
0e7d5f3972 | ||
|
5b5f91f75f | ||
|
ab496987e0 | ||
|
c92ebc3908 | ||
|
bc3573fcbc | ||
|
6b7beaadaf | ||
|
31b6e9e299 | ||
|
d52a4b1c9d | ||
|
9796af5d80 | ||
|
9fc56bb896 | ||
|
f3dd77a3f1 | ||
|
2c191bf595 | ||
|
4bb942f1f9 | ||
|
05dbfbb988 | ||
|
69a7c78179 | ||
|
04051454bf | ||
|
2ca86d9abd | ||
|
e6f3d429a1 | ||
|
1ca91d7ddc | ||
|
fad9dce3e6 | ||
|
342f4ee0f2 | ||
|
047b5ca6d5 | ||
|
ef0253905a | ||
|
86c4333f8f | ||
|
026c30cfff | ||
|
e1de1f0527 | ||
|
43fdddb438 | ||
|
28849e60cf | ||
|
44477d97ac | ||
|
b5906812a2 |
@@ -3566,7 +3566,7 @@ blacklist_command() {
|
||||
if [ $VERBOSITY -gt 1 ]; then
|
||||
echo "$message" | awk '/have been deleted/ { sub( /^.*: /, "" ); sub( / /, " src " ); }; { print; }'
|
||||
else
|
||||
echo "$message" | head -n1 | sed '/^.*: //; s/ / src /'
|
||||
echo "$message" | head -n1 | sed 's/^.*: //; s/ / src /'
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -3576,7 +3576,7 @@ blacklist_command() {
|
||||
if [ $VERBOSITY -gt 1 ]; then
|
||||
echo "$message" | awk '/have been deleted/ { sub( /^.*: /, "" ); sub( / /, " dst " ); }; { print; }'
|
||||
else
|
||||
echo "$message" | head -n1 | sed '/^.*: //; s/ / dst /'
|
||||
echo "$message" | head -n1 | sed 's/^.*: //; s/ / dst /'
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
@@ -266,10 +266,12 @@ our %EXPORT_TAGS = (
|
||||
set_chain_variables
|
||||
mark_firewall_not_started
|
||||
mark_firewall6_not_started
|
||||
interface_address
|
||||
get_interface_address
|
||||
get_interface_addresses
|
||||
get_interface_bcasts
|
||||
get_interface_acasts
|
||||
interface_gateway
|
||||
get_interface_gateway
|
||||
get_interface_mac
|
||||
have_global_variables
|
||||
@@ -2747,11 +2749,13 @@ sub accounting_chainrefs() {
|
||||
grep $_->{accounting} , values %$filter_table;
|
||||
}
|
||||
|
||||
sub ensure_mangle_chain($) {
|
||||
my $chain = $_[0];
|
||||
sub ensure_mangle_chain($;$$) {
|
||||
my ( $chain, $number, $restriction ) = @_;
|
||||
|
||||
my $chainref = ensure_chain 'mangle', $chain;
|
||||
$chainref->{referenced} = 1;
|
||||
$chainref->{referenced} = 1;
|
||||
$chainref->{chainnumber} = $number if $number;
|
||||
$chainref->{restriction} = $restriction if $restriction;
|
||||
$chainref;
|
||||
}
|
||||
|
||||
@@ -5773,12 +5777,12 @@ sub have_ipset_rules() {
|
||||
$ipset_rules;
|
||||
}
|
||||
|
||||
sub get_interface_address( $ );
|
||||
sub get_interface_address( $;$ );
|
||||
|
||||
sub get_interface_gateway ( $;$ );
|
||||
sub get_interface_gateway ( $;$$ );
|
||||
|
||||
sub record_runtime_address( $$;$ ) {
|
||||
my ( $addrtype, $interface, $protect ) = @_;
|
||||
sub record_runtime_address( $$;$$ ) {
|
||||
my ( $addrtype, $interface, $protect, $provider ) = @_;
|
||||
|
||||
if ( $interface =~ /^{([a-zA-Z_]\w*)}$/ ) {
|
||||
fatal_error "Mixed required/optional usage of address variable $1" if ( $address_variables{$1} || $addrtype ) ne $addrtype;
|
||||
@@ -5792,9 +5796,9 @@ sub record_runtime_address( $$;$ ) {
|
||||
my $addr;
|
||||
|
||||
if ( $addrtype eq '&' ) {
|
||||
$addr = get_interface_address( $interface );
|
||||
$addr = get_interface_address( $interface, $provider );
|
||||
} else {
|
||||
$addr = get_interface_gateway( $interface, $protect );
|
||||
$addr = get_interface_gateway( $interface, $protect, $provider );
|
||||
}
|
||||
|
||||
$addr . ' ';
|
||||
@@ -5819,12 +5823,18 @@ sub conditional_rule( $$ ) {
|
||||
if ( $type eq '&' ) {
|
||||
$variable = get_interface_address( $interface );
|
||||
add_commands( $chainref , "if [ $variable != " . NILIP . ' ]; then' );
|
||||
incr_cmd_level $chainref;
|
||||
} else {
|
||||
$variable = get_interface_gateway( $interface );
|
||||
add_commands( $chainref , qq(if [ -n "$variable" ]; then) );
|
||||
|
||||
if ( $variable =~ /^\$/ ) {
|
||||
add_commands( $chainref , qq(if [ -n "$variable" ]; then) );
|
||||
incr_cmd_level $chainref;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
incr_cmd_level $chainref;
|
||||
return 1;
|
||||
}
|
||||
} elsif ( $type eq '%' && $interface =~ /^{([a-zA-Z_]\w*)}$/ ) {
|
||||
@@ -6785,8 +6795,8 @@ sub interface_address( $ ) {
|
||||
#
|
||||
# Record that the ruleset requires the first IP address on the passed interface
|
||||
#
|
||||
sub get_interface_address ( $ ) {
|
||||
my ( $logical ) = $_[0];
|
||||
sub get_interface_address ( $;$ ) {
|
||||
my ( $logical, $provider ) = @_;
|
||||
|
||||
my $interface = get_physical( $logical );
|
||||
my $variable = interface_address( $interface );
|
||||
@@ -6796,6 +6806,8 @@ sub get_interface_address ( $ ) {
|
||||
|
||||
$interfaceaddr{$interface} = "$variable=\$($function $interface)\n";
|
||||
|
||||
set_interface_option( $logical, 'used_address_variable', 1 ) unless $provider;
|
||||
|
||||
"\$$variable";
|
||||
}
|
||||
|
||||
@@ -6856,14 +6868,21 @@ sub interface_gateway( $ ) {
|
||||
#
|
||||
# Record that the ruleset requires the gateway address on the passed interface
|
||||
#
|
||||
sub get_interface_gateway ( $;$ ) {
|
||||
my ( $logical, $protect ) = @_;
|
||||
sub get_interface_gateway ( $;$$ ) {
|
||||
my ( $logical, $protect, $provider ) = @_;
|
||||
|
||||
my $interface = get_physical $logical;
|
||||
my $variable = interface_gateway( $interface );
|
||||
my $gateway = get_interface_option( $interface, 'gateway' );
|
||||
|
||||
$global_variables |= ALL_COMMANDS;
|
||||
|
||||
if ( $gateway ) {
|
||||
fatal_error q(A gateway variable cannot be used for a provider interface with GATEWAY set to 'none' in the providers file) if $gateway eq 'none';
|
||||
fatal_error q(A gateway variable cannot be used for a provider interface with an empty GATEWAY column in the providers file) if $gateway eq 'omitted';
|
||||
return $gateway if $gateway ne 'detect';
|
||||
}
|
||||
|
||||
if ( interface_is_optional $logical ) {
|
||||
$interfacegateways{$interface} = qq([ -n "\$$variable" ] || $variable=\$(detect_gateway $interface));
|
||||
} else {
|
||||
@@ -6871,6 +6890,8 @@ sub get_interface_gateway ( $;$ ) {
|
||||
[ -n "\$$variable" ] || startup_error "Unable to detect the gateway through interface $interface");
|
||||
}
|
||||
|
||||
set_interface_option($interface, 'used_gateway_variable', 1) unless $provider;
|
||||
|
||||
$protect ? "\${$variable:-" . NILIP . '}' : "\$$variable";
|
||||
}
|
||||
|
||||
@@ -7273,6 +7294,7 @@ sub isolate_dest_interface( $$$$ ) {
|
||||
my ( $diface, $dnets );
|
||||
|
||||
if ( ( $restriction & PREROUTE_RESTRICT ) && $dest =~ /^detect:(.*)$/ ) {
|
||||
my $niladdr = NILIP;
|
||||
#
|
||||
# DETECT_DNAT_IPADDRS=Yes and we're generating the nat rule
|
||||
#
|
||||
@@ -7289,14 +7311,14 @@ sub isolate_dest_interface( $$$$ ) {
|
||||
|
||||
push_command( $chainref , "for address in $list; do" , 'done' );
|
||||
|
||||
push_command( $chainref , 'if [ $address != 0.0.0.0 ]; then' , 'fi' ) if $optional;
|
||||
push_command( $chainref , "if [ \$address != $niladdr ]; then" , 'fi' ) if $optional;
|
||||
|
||||
$rule .= '-d $address ';
|
||||
} else {
|
||||
my $interface = $interfaces[0];
|
||||
my $variable = get_interface_address( $interface );
|
||||
|
||||
push_command( $chainref , "if [ $variable != 0.0.0.0 ]; then" , 'fi') if interface_is_optional( $interface );
|
||||
push_command( $chainref , "if [ $variable != $niladdr ]; then" , 'fi') if interface_is_optional( $interface );
|
||||
|
||||
$rule .= "-d $variable ";
|
||||
}
|
||||
@@ -8265,6 +8287,7 @@ EOF
|
||||
|
||||
sub ensure_ipsets( @ ) {
|
||||
my $set;
|
||||
my $counters = have_capability( 'IPSET_MATCH_COUNTERS' ) ? ' counters' : '';
|
||||
|
||||
if ( $globals{DBL_TIMEOUT} ne '' && $_[0] eq $globals{DBL_IPSET} ) {
|
||||
shift;
|
||||
@@ -8277,12 +8300,12 @@ sub ensure_ipsets( @ ) {
|
||||
emit( q( #),
|
||||
q( # Set the timeout for the dynamic blacklisting ipset),
|
||||
q( #),
|
||||
qq( \$IPSET -exist create $globals{DBL_IPSET} hash:net family inet timeout $globals{DBL_TIMEOUT} counters) );
|
||||
qq( \$IPSET -exist create $globals{DBL_IPSET} hash:net family inet timeout $globals{DBL_TIMEOUT}${counters}) );
|
||||
} else {
|
||||
emit( q( #),
|
||||
q( # Set the timeout for the dynamic blacklisting ipset),
|
||||
q( #),
|
||||
qq( \$IPSET -exist create $globals{DBL_IPSET} hash:net family inet6 timeout $globals{DBL_TIMEOUT} counters) );
|
||||
qq( \$IPSET -exist create $globals{DBL_IPSET} hash:net family inet6 timeout $globals{DBL_TIMEOUT}${counters}) );
|
||||
}
|
||||
|
||||
pop_indent;
|
||||
@@ -8303,8 +8326,8 @@ sub ensure_ipsets( @ ) {
|
||||
if ( $family == F_IPV4 ) {
|
||||
if ( have_capability 'IPSET_V5' ) {
|
||||
emit ( qq( if ! qt \$IPSET list $set -n; then) ,
|
||||
qq( error_message "WARNING: ipset $set does not exist; creating it as an hash:net set") ,
|
||||
qq( \$IPSET create $set hash:net family inet timeout 0 counters) ,
|
||||
qq( error_message "WARNING: ipset $set does not exist; creating it as a hash:net set") ,
|
||||
qq( \$IPSET create $set hash:net family inet timeout 0${counters}) ,
|
||||
qq( fi) );
|
||||
} else {
|
||||
emit ( qq( if ! qt \$IPSET -L $set -n; then) ,
|
||||
@@ -8314,8 +8337,8 @@ sub ensure_ipsets( @ ) {
|
||||
}
|
||||
} else {
|
||||
emit ( qq( if ! qt \$IPSET list $set -n; then) ,
|
||||
qq( error_message "WARNING: ipset $set does not exist; creating it as an hash:net set") ,
|
||||
qq( \$IPSET create $set hash:net family inet6 timeout 0 counters) ,
|
||||
qq( error_message "WARNING: ipset $set does not exist; creating it as a hash:net set") ,
|
||||
qq( \$IPSET create $set hash:net family inet6 timeout 0${counters}) ,
|
||||
qq( fi) );
|
||||
}
|
||||
|
||||
|
@@ -804,33 +804,8 @@ sub compiler {
|
||||
# Validate the TC files so that the providers will know what interfaces have TC
|
||||
#
|
||||
my $tcinterfaces = process_tc;
|
||||
#
|
||||
# Generate a function to bring up each provider
|
||||
#
|
||||
|
||||
process_providers( $tcinterfaces );
|
||||
#
|
||||
# [Re-]establish Routing
|
||||
#
|
||||
if ( $scriptfilename || $debug ) {
|
||||
emit( "\n#",
|
||||
'# Setup routing and traffic shaping',
|
||||
'#',
|
||||
'setup_routing_and_traffic_shaping() {'
|
||||
);
|
||||
|
||||
push_indent;
|
||||
}
|
||||
|
||||
setup_providers;
|
||||
#
|
||||
# TCRules and Traffic Shaping
|
||||
#
|
||||
setup_tc( $update );
|
||||
|
||||
if ( $scriptfilename || $debug ) {
|
||||
pop_indent;
|
||||
emit "}\n"; # End of setup_routing_and_traffic_shaping()
|
||||
}
|
||||
|
||||
$have_arptables = process_arprules if $family == F_IPV4;
|
||||
|
||||
@@ -841,13 +816,9 @@ sub compiler {
|
||||
#
|
||||
process_tos;
|
||||
#
|
||||
# ECN
|
||||
# Setup Masquerade/SNAT
|
||||
#
|
||||
setup_ecn if $family == F_IPV4 && have_capability( 'MANGLE_ENABLED' ) && $config{MANGLE_ENABLED};
|
||||
#
|
||||
# Setup Masquerading/SNAT
|
||||
#
|
||||
setup_masq;
|
||||
setup_snat( $update );
|
||||
#
|
||||
# Setup Nat
|
||||
#
|
||||
@@ -889,6 +860,37 @@ sub compiler {
|
||||
#
|
||||
setup_accounting if $config{ACCOUNTING};
|
||||
|
||||
enable_script;
|
||||
#
|
||||
# Generate a function to bring up each provider
|
||||
#
|
||||
if ( $scriptfilename || $debug ) {
|
||||
emit( "\n#",
|
||||
'# Setup routing and traffic shaping',
|
||||
'#',
|
||||
'setup_routing_and_traffic_shaping() {'
|
||||
);
|
||||
|
||||
push_indent;
|
||||
}
|
||||
|
||||
setup_providers;
|
||||
#
|
||||
# TCRules and Traffic Shaping
|
||||
#
|
||||
setup_tc( $update );
|
||||
|
||||
if ( $scriptfilename || $debug ) {
|
||||
pop_indent;
|
||||
emit "}\n"; # End of setup_routing_and_traffic_shaping()
|
||||
}
|
||||
#
|
||||
# ECN
|
||||
#
|
||||
setup_ecn if $family == F_IPV4 && have_capability( 'MANGLE_ENABLED' ) && $config{MANGLE_ENABLED};
|
||||
|
||||
disable_script;
|
||||
|
||||
if ( $scriptfilename ) {
|
||||
#
|
||||
# Compiling a script - generate the zone by zone matrix
|
||||
|
@@ -4544,11 +4544,11 @@ sub IPSet_Match() {
|
||||
}
|
||||
|
||||
sub IPSet_Match_Nomatch() {
|
||||
have_capability 'IPSET_MATCH' && $capabilities{IPSET_MATCH_NOMATCH};
|
||||
have_capability( 'IPSET_MATCH' ) && $capabilities{IPSET_MATCH_NOMATCH};
|
||||
}
|
||||
|
||||
sub IPSet_Match_Counters() {
|
||||
have_capability 'IPSET_MATCH' && $capabilities{IPSET_MATCH_COUNTERS};
|
||||
have_capability( 'IPSET_MATCH' ) && $capabilities{IPSET_MATCH_COUNTERS};
|
||||
}
|
||||
|
||||
sub IPSET_V5() {
|
||||
@@ -6262,16 +6262,20 @@ sub get_configuration( $$$$ ) {
|
||||
|
||||
( $key , my @options ) = split_list( $key, 'option' );
|
||||
|
||||
my $options = '';
|
||||
|
||||
for ( @options ) {
|
||||
unless ( $simple_options{$_} ) {
|
||||
if ( $_ =~ s/^timeout=(\d+)$// ) {
|
||||
$globals{DBL_TIMEOUT} = $1;
|
||||
} else {
|
||||
fatal_error "Invalid ipset option ($_)";
|
||||
}
|
||||
if ( $simple_options{$_} ) {
|
||||
$options = join( ',' , $options, $_ );
|
||||
} elsif ( $_ =~ s/^timeout=(\d+)$// ) {
|
||||
$globals{DBL_TIMEOUT} = $1;
|
||||
} else {
|
||||
fatal_error "Invalid ipset option ($_)";
|
||||
}
|
||||
}
|
||||
|
||||
$globals{DBL_OPTIONS} = $options;
|
||||
|
||||
fatal_error "Invalid DYNAMIC_BLACKLIST setting ( $val )" if $key !~ /^ipset(?:-only)?$/ || defined $rest;
|
||||
|
||||
if ( supplied( $set ) ) {
|
||||
|
@@ -432,13 +432,18 @@ sub validate_port( $$ ) {
|
||||
sub validate_portpair( $$ ) {
|
||||
my ($proto, $portpair) = @_;
|
||||
my $what;
|
||||
my $pair = $portpair;
|
||||
#
|
||||
# Accept '-' as a port-range separator
|
||||
#
|
||||
$pair =~ tr/-/:/ if $pair =~ /^[-0-9]+$/;
|
||||
|
||||
fatal_error "Invalid port range ($portpair)" if $portpair =~ tr/:/:/ > 1;
|
||||
fatal_error "Invalid port range ($portpair)" if $pair =~ tr/:/:/ > 1;
|
||||
|
||||
$portpair = "0$portpair" if substr( $portpair, 0, 1 ) eq ':';
|
||||
$portpair = "${portpair}65535" if substr( $portpair, -1, 1 ) eq ':';
|
||||
$pair = "0$pair" if substr( $pair, 0, 1 ) eq ':';
|
||||
$pair = "${pair}65535" if substr( $pair, -1, 1 ) eq ':';
|
||||
|
||||
my @ports = split /:/, $portpair, 2;
|
||||
my @ports = split /:/, $pair, 2;
|
||||
|
||||
my $protonum = resolve_proto( $proto ) || 0;
|
||||
|
||||
@@ -467,7 +472,7 @@ sub validate_portpair1( $$ ) {
|
||||
|
||||
fatal_error "Invalid port range ($portpair)" if $portpair =~ tr/-/-/ > 1;
|
||||
|
||||
$portpair = "0$portpair" if substr( $portpair, 0, 1 ) eq ':';
|
||||
$portpair = "1$portpair" if substr( $portpair, 0, 1 ) eq ':';
|
||||
$portpair = "${portpair}65535" if substr( $portpair, -1, 1 ) eq ':';
|
||||
|
||||
my @ports = split /-/, $portpair, 2;
|
||||
@@ -478,9 +483,10 @@ sub validate_portpair1( $$ ) {
|
||||
|
||||
if ( @ports == 2 ) {
|
||||
$what = 'port range';
|
||||
fatal_error "Invalid port range ($portpair)" unless $ports[0] < $ports[1];
|
||||
fatal_error "Invalid port range ($portpair)" unless $ports[0] && $ports[0] < $ports[1];
|
||||
} else {
|
||||
$what = 'port';
|
||||
fatal_error 'Invalid port number (0)' unless $portpair;
|
||||
}
|
||||
|
||||
fatal_error "Using a $what ( $portpair ) requires PROTO TCP, UDP, SCTP or DCCP" unless
|
||||
@@ -497,7 +503,7 @@ sub validate_port_list( $$ ) {
|
||||
my ( $proto, $list ) = @_;
|
||||
my @list = split_list( $list, 'port' );
|
||||
|
||||
if ( @list > 1 && $list =~ /:/ ) {
|
||||
if ( @list > 1 && $list =~ /[:-]/ ) {
|
||||
require_capability( 'XMULTIPORT' , 'Port ranges in a port list', '' );
|
||||
}
|
||||
|
||||
|
@@ -688,7 +688,8 @@ sub add_common_rules ( $ ) {
|
||||
my $dbl_ipset;
|
||||
my $dbl_level;
|
||||
my $dbl_tag;
|
||||
my $dbl_target;
|
||||
my $dbl_src_target;
|
||||
my $dbl_dst_target;
|
||||
|
||||
if ( $config{REJECT_ACTION} ) {
|
||||
process_reject_action;
|
||||
@@ -749,8 +750,42 @@ sub add_common_rules ( $ ) {
|
||||
}
|
||||
|
||||
if ( $dbl_ipset ) {
|
||||
if ( $dbl_level ) {
|
||||
my $chainref = set_optflags( new_standard_chain( $dbl_target = 'dbl_log' ) , DONT_OPTIMIZE | DONT_DELETE );
|
||||
if ( $val = $globals{DBL_TIMEOUT} ) {
|
||||
$dbl_src_target = $globals{DBL_OPTIONS} =~ /src-dst/ ? 'dbl_src' : 'dbl_log';
|
||||
|
||||
my $chainref = set_optflags( new_standard_chain( $dbl_src_target ) , DONT_OPTIMIZE | DONT_DELETE );
|
||||
|
||||
log_rule_limit( $dbl_level,
|
||||
$chainref,
|
||||
'dbl_log',
|
||||
'DROP',
|
||||
$globals{LOGLIMIT},
|
||||
$dbl_tag,
|
||||
'add',
|
||||
'',
|
||||
$origin{DYNAMIC_BLACKLIST} ) if $dbl_level;
|
||||
add_ijump_extended( $chainref, j => "SET --add-set $dbl_ipset src --exist --timeout $val", $origin{DYNAMIC_BLACKLIST} );
|
||||
add_ijump_extended( $chainref, j => 'DROP', $origin{DYNAMIC_BLACKLIST} );
|
||||
|
||||
if ( $dbl_src_target eq 'dbl_src' ) {
|
||||
$chainref = set_optflags( new_standard_chain( $dbl_dst_target = 'dbl_dst' ) , DONT_OPTIMIZE | DONT_DELETE );
|
||||
|
||||
log_rule_limit( $dbl_level,
|
||||
$chainref,
|
||||
'dbl_log',
|
||||
'DROP',
|
||||
$globals{LOGLIMIT},
|
||||
$dbl_tag,
|
||||
'add',
|
||||
'',
|
||||
$origin{DYNAMIC_BLACKLIST} ) if $dbl_level;
|
||||
add_ijump_extended( $chainref, j => "SET --add-set $dbl_ipset dst --exist --timeout $val", $origin{DYNAMIC_BLACKLIST} );
|
||||
add_ijump_extended( $chainref, j => 'DROP', $origin{DYNAMIC_BLACKLIST} );
|
||||
} else {
|
||||
$dbl_dst_target = $dbl_src_target;
|
||||
}
|
||||
} elsif ( $dbl_level ) {
|
||||
my $chainref = set_optflags( new_standard_chain( $dbl_src_target = 'dbl_log' ) , DONT_OPTIMIZE | DONT_DELETE );
|
||||
|
||||
log_rule_limit( $dbl_level,
|
||||
$chainref,
|
||||
@@ -763,7 +798,7 @@ sub add_common_rules ( $ ) {
|
||||
$origin{DYNAMIC_BLACKLIST} );
|
||||
add_ijump_extended( $chainref, j => 'DROP', $origin{DYNAMIC_BLACKLIST} );
|
||||
} else {
|
||||
$dbl_target = 'DROP';
|
||||
$dbl_src_target = $dbl_dst_target = 'DROP';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -877,17 +912,17 @@ sub add_common_rules ( $ ) {
|
||||
#
|
||||
# src
|
||||
#
|
||||
add_ijump_extended( $filter_table->{input_option_chain($interface)}, j => $dbl_target, $origin{DYNAMIC_BLACKLIST}, @state, set => "--match-set $dbl_ipset src" );
|
||||
add_ijump_extended( $filter_table->{forward_option_chain($interface)}, j => $dbl_target, $origin{DYNAMIC_BLACKLIST}, @state, set => "--match-set $dbl_ipset src" );
|
||||
add_ijump_extended( $filter_table->{input_option_chain($interface)}, j => $dbl_src_target, $origin{DYNAMIC_BLACKLIST}, @state, set => "--match-set $dbl_ipset src" );
|
||||
add_ijump_extended( $filter_table->{forward_option_chain($interface)}, j => $dbl_src_target, $origin{DYNAMIC_BLACKLIST}, @state, set => "--match-set $dbl_ipset src" );
|
||||
} elsif ( $in == 2 ) {
|
||||
add_ijump_extended( $filter_table->{forward_option_chain($interface)}, j => $dbl_target, $origin{DYNAMIC_BLACKLIST}, @state, set => "--match-set $dbl_ipset dst" );
|
||||
add_ijump_extended( $filter_table->{forward_option_chain($interface)}, j => $dbl_dst_target, $origin{DYNAMIC_BLACKLIST}, @state, set => "--match-set $dbl_ipset dst" );
|
||||
}
|
||||
|
||||
if ( $out == 2 ) {
|
||||
#
|
||||
# dst
|
||||
#
|
||||
add_ijump_extended( $filter_table->{output_option_chain($interface)}, j => $dbl_target, $origin{DYNAMIC_BLACKLIST}, @state, set => "--match-set $dbl_ipset dst" );
|
||||
add_ijump_extended( $filter_table->{output_option_chain($interface)}, j => $dbl_dst_target, $origin{DYNAMIC_BLACKLIST}, @state, set => "--match-set $dbl_ipset dst" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2705,6 +2740,9 @@ EOF
|
||||
pop_indent;
|
||||
|
||||
emit '
|
||||
rm -f ${VARDIR}/*.address
|
||||
rm -f ${VARDIR}/*.gateway
|
||||
|
||||
run_stopped_exit';
|
||||
|
||||
my @ipsets = all_ipsets;
|
||||
|
@@ -36,8 +36,8 @@ use Shorewall::Providers qw( provider_realm );
|
||||
use strict;
|
||||
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw( setup_masq setup_nat setup_netmap add_addresses );
|
||||
our %EXPORT_TAGS = ( rules => [ qw ( handle_nat_rule handle_nonat_rule ) ] );
|
||||
our @EXPORT = qw( setup_nat setup_netmap add_addresses );
|
||||
our %EXPORT_TAGS = ( rules => [ qw ( handle_nat_rule handle_nonat_rule process_one_masq convert_masq @addresses_to_add %addresses_to_add ) ] );
|
||||
our @EXPORT_OK = ();
|
||||
|
||||
Exporter::export_ok_tags('rules');
|
||||
@@ -60,20 +60,22 @@ sub initialize($) {
|
||||
#
|
||||
# Process a single rule from the the masq file
|
||||
#
|
||||
sub process_one_masq1( $$$$$$$$$$$ )
|
||||
sub process_one_masq1( $$$$$$$$$$$$ )
|
||||
{
|
||||
my ($interfacelist, $networks, $addresses, $proto, $ports, $ipsec, $mark, $user, $condition, $origdest, $probability ) = @_;
|
||||
my ( $snat, $interfacelist, $networks, $addresses, $proto, $ports, $ipsec, $mark, $user, $condition, $origdest, $probability ) = @_;
|
||||
|
||||
my $pre_nat;
|
||||
my $add_snat_aliases = $family == F_IPV4 && $config{ADD_SNAT_ALIASES};
|
||||
my $add_snat_aliases = ! $snat && $family == F_IPV4 && $config{ADD_SNAT_ALIASES};
|
||||
my $destnets = '';
|
||||
my $baserule = '';
|
||||
my $inlinematches = '';
|
||||
my $prerule = '';
|
||||
my $savelist;
|
||||
#
|
||||
# Leading '+'
|
||||
#
|
||||
$pre_nat = 1 if $interfacelist =~ s/^\+//;
|
||||
|
||||
#
|
||||
# Check for INLINE
|
||||
#
|
||||
@@ -82,7 +84,9 @@ sub process_one_masq1( $$$$$$$$$$$ )
|
||||
$inlinematches = get_inline_matches(0);
|
||||
} else {
|
||||
$inlinematches = get_inline_matches(0);
|
||||
}
|
||||
}
|
||||
|
||||
$savelist = $interfacelist;
|
||||
#
|
||||
# Handle early matches
|
||||
#
|
||||
@@ -149,9 +153,12 @@ sub process_one_masq1( $$$$$$$$$$$ )
|
||||
$baserule .= do_user( $user ) if $user ne '-';
|
||||
$baserule .= do_probability( $probability ) if $probability ne '-';
|
||||
|
||||
my $target;
|
||||
|
||||
for my $fullinterface (split_list $interfacelist, 'interface' ) {
|
||||
my $rule = '';
|
||||
my $target = 'MASQUERADE ';
|
||||
|
||||
$target = 'MASQUERADE ';
|
||||
#
|
||||
# Isolate and verify the interface part
|
||||
#
|
||||
@@ -193,6 +200,7 @@ sub process_one_masq1( $$$$$$$$$$$ )
|
||||
# Parse the ADDRESSES column
|
||||
#
|
||||
if ( $addresses ne '-' ) {
|
||||
my $saveaddresses = $addresses;
|
||||
if ( $addresses eq 'random' ) {
|
||||
require_capability( 'MASQUERADE_TGT', 'Masquerade rules', '') if $family == F_IPV6;
|
||||
$randomize = '--random ';
|
||||
@@ -218,13 +226,13 @@ sub process_one_masq1( $$$$$$$$$$$ )
|
||||
} elsif ( $addresses eq 'NONAT' ) {
|
||||
fatal_error "'persistent' may not be specified with 'NONAT'" if $persistent;
|
||||
fatal_error "'random' may not be specified with 'NONAT'" if $randomize;
|
||||
$target = 'RETURN';
|
||||
$target = $snat ? 'CONTINUE' : 'RETURN';
|
||||
$add_snat_aliases = 0;
|
||||
} elsif ( $addresses ) {
|
||||
my $addrlist = '';
|
||||
my @addrs = split_list $addresses, 'address';
|
||||
|
||||
fatal_error "Only one IPv6 ADDRESS may be specified" if $family == F_IPV6 && @addrs > 1;
|
||||
fatal_error "Only one ADDRESS may be specified" if @addrs > 1;
|
||||
|
||||
for my $addr ( @addrs ) {
|
||||
if ( $addr =~ /^([&%])(.+)$/ ) {
|
||||
@@ -240,43 +248,52 @@ sub process_one_masq1( $$$$$$$$$$$ )
|
||||
# Address Variable
|
||||
#
|
||||
$target = 'SNAT ';
|
||||
if ( $interface =~ /^{([a-zA-Z_]\w*)}$/ ) {
|
||||
#
|
||||
# User-defined address variable
|
||||
#
|
||||
$conditional = conditional_rule( $chainref, $addr );
|
||||
$addrlist .= '--to-source ' . "\$${1}${ports} ";
|
||||
} else {
|
||||
if ( $conditional = conditional_rule( $chainref, $addr ) ) {
|
||||
|
||||
unless ( $snat ) {
|
||||
if ( $interface =~ /^{([a-zA-Z_]\w*)}$/ ) {
|
||||
#
|
||||
# Optional Interface -- rule is conditional
|
||||
# User-defined address variable
|
||||
#
|
||||
$addr = get_interface_address $interface;
|
||||
$conditional = conditional_rule( $chainref, $addr );
|
||||
$addrlist .= '--to-source ' . "\$${1}${ports} ";
|
||||
} else {
|
||||
#
|
||||
# Interface is not optional
|
||||
#
|
||||
$addr = record_runtime_address( $type, $interface );
|
||||
}
|
||||
if ( $conditional = conditional_rule( $chainref, $addr ) ) {
|
||||
#
|
||||
# Optional Interface -- rule is conditional
|
||||
#
|
||||
$addr = get_interface_address $interface;
|
||||
} else {
|
||||
#
|
||||
# Interface is not optional
|
||||
#
|
||||
$addr = record_runtime_address( $type, $interface );
|
||||
}
|
||||
|
||||
if ( $ports ) {
|
||||
$addr =~ s/ $//;
|
||||
$addr = $family == F_IPV4 ? "${addr}${ports} " : "[$addr]$ports ";
|
||||
}
|
||||
if ( $ports ) {
|
||||
$addr =~ s/ $//;
|
||||
$addr = $family == F_IPV4 ? "${addr}${ports} " : "[$addr]$ports ";
|
||||
}
|
||||
|
||||
$addrlist .= '--to-source ' . $addr;
|
||||
$addrlist .= '--to-source ' . $addr;
|
||||
}
|
||||
}
|
||||
} elsif ( $family == F_IPV4 ) {
|
||||
if ( $addr =~ /^.*\..*\..*\./ ) {
|
||||
$target = 'SNAT ';
|
||||
my ($ipaddr, $rest) = split ':', $addr;
|
||||
my ($ipaddr, $rest) = split ':', $addr, 2;
|
||||
if ( $ipaddr =~ /^(.+)-(.+)$/ ) {
|
||||
validate_range( $1, $2 );
|
||||
} else {
|
||||
validate_address $ipaddr, 0;
|
||||
}
|
||||
validate_portpair1( $proto, $rest ) if supplied $rest;
|
||||
$addrlist .= "--to-source $addr ";
|
||||
|
||||
if ( supplied $rest ) {
|
||||
validate_portpair1( $proto, $rest );
|
||||
$addrlist .= "--to-source $addr ";
|
||||
} else {
|
||||
$addrlist .= "--to-source $ipaddr";
|
||||
}
|
||||
|
||||
$exceptionrule = do_proto( $proto, '', '' ) if $addr =~ /:/;
|
||||
} else {
|
||||
my $ports = $addr;
|
||||
@@ -337,6 +354,7 @@ sub process_one_masq1( $$$$$$$$$$$ )
|
||||
|
||||
$target .= $randomize;
|
||||
$target .= $persistent;
|
||||
$addresses = $saveaddresses;
|
||||
} else {
|
||||
require_capability( 'MASQUERADE_TGT', 'Masquerade rules', '' ) if $family == F_IPV6;
|
||||
$add_snat_aliases = 0;
|
||||
@@ -344,37 +362,39 @@ sub process_one_masq1( $$$$$$$$$$$ )
|
||||
#
|
||||
# And Generate the Rule(s)
|
||||
#
|
||||
expand_rule( $chainref ,
|
||||
POSTROUTE_RESTRICT ,
|
||||
$prerule ,
|
||||
$baserule . $inlinematches . $rule ,
|
||||
$networks ,
|
||||
$destnets ,
|
||||
$origdest ,
|
||||
$target ,
|
||||
'' ,
|
||||
'' ,
|
||||
$exceptionrule ,
|
||||
'' )
|
||||
unless unreachable_warning( 0, $chainref );
|
||||
unless ( $snat ) {
|
||||
expand_rule( $chainref ,
|
||||
POSTROUTE_RESTRICT ,
|
||||
$prerule ,
|
||||
$baserule . $inlinematches . $rule ,
|
||||
$networks ,
|
||||
$destnets ,
|
||||
$origdest ,
|
||||
$target ,
|
||||
'' ,
|
||||
'' ,
|
||||
$exceptionrule ,
|
||||
'' )
|
||||
unless unreachable_warning( 0, $chainref );
|
||||
|
||||
conditional_rule_end( $chainref ) if $detectaddress || $conditional;
|
||||
conditional_rule_end( $chainref ) if $detectaddress || $conditional;
|
||||
|
||||
if ( $add_snat_aliases ) {
|
||||
my ( $interface, $alias , $remainder ) = split( /:/, $fullinterface, 3 );
|
||||
fatal_error "Invalid alias ($alias:$remainder)" if defined $remainder;
|
||||
for my $address ( split_list $addresses, 'address' ) {
|
||||
my ( $addrs, $port ) = split /:/, $address;
|
||||
next unless $addrs;
|
||||
next if $addrs eq 'detect';
|
||||
for my $addr ( ip_range_explicit $addrs ) {
|
||||
unless ( $addresses_to_add{$addr} ) {
|
||||
$addresses_to_add{$addr} = 1;
|
||||
if ( defined $alias ) {
|
||||
push @addresses_to_add, $addr, "$interface:$alias";
|
||||
$alias++;
|
||||
} else {
|
||||
push @addresses_to_add, $addr, $interface;
|
||||
if ( $add_snat_aliases ) {
|
||||
my ( $interface, $alias , $remainder ) = split( /:/, $fullinterface, 3 );
|
||||
fatal_error "Invalid alias ($alias:$remainder)" if defined $remainder;
|
||||
for my $address ( split_list $addresses, 'address' ) {
|
||||
my ( $addrs, $port ) = split /:/, $address;
|
||||
next unless $addrs;
|
||||
next if $addrs eq 'detect';
|
||||
for my $addr ( ip_range_explicit $addrs ) {
|
||||
unless ( $addresses_to_add{$addr} ) {
|
||||
$addresses_to_add{$addr} = 1;
|
||||
if ( defined $alias ) {
|
||||
push @addresses_to_add, $addr, "$interface:$alias";
|
||||
$alias++;
|
||||
} else {
|
||||
push @addresses_to_add, $addr, $interface;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -382,12 +402,36 @@ sub process_one_masq1( $$$$$$$$$$$ )
|
||||
}
|
||||
}
|
||||
|
||||
if ( $snat ) {
|
||||
$target =~ s/ .*//;
|
||||
$target .= '+' if $pre_nat;
|
||||
|
||||
if ( $addresses ne '-' && $addresses ne 'NONAT' ) {
|
||||
$addresses =~ s/^://;
|
||||
$target .= '(' . $addresses . ')';
|
||||
}
|
||||
|
||||
my $line = "$target\t$networks\t$savelist\t$proto\t$ports\t$ipsec\t$mark\t$user\t$condition\t$origdest\t$probability";
|
||||
#
|
||||
# Supress superfluous trailing dashes
|
||||
#
|
||||
$line =~ s/(?:\t-)+$//;
|
||||
|
||||
my $raw_matches = fetch_inline_matches;
|
||||
|
||||
$line .= join( '', ' ;;', $raw_matches ) if $raw_matches ne ' ';
|
||||
|
||||
print $snat "$line\n";
|
||||
}
|
||||
|
||||
progress_message " Masq record \"$currentline\" $done";
|
||||
|
||||
}
|
||||
|
||||
sub process_one_masq( )
|
||||
sub process_one_masq( $ )
|
||||
{
|
||||
my ( $snat ) = @_;
|
||||
|
||||
my ($interfacelist, $networks, $addresses, $protos, $ports, $ipsec, $mark, $user, $condition, $origdest, $probability ) =
|
||||
split_line2( 'masq file',
|
||||
{ interface => 0, source => 1, address => 2, proto => 3, port => 4, ipsec => 5, mark => 6, user => 7, switch => 8, origdest => 9, probability => 10 },
|
||||
@@ -398,20 +442,92 @@ sub process_one_masq( )
|
||||
fatal_error 'INTERFACE must be specified' if $interfacelist eq '-';
|
||||
|
||||
for my $proto ( split_list $protos, 'Protocol' ) {
|
||||
process_one_masq1( $interfacelist, $networks, $addresses, $proto, $ports, $ipsec, $mark, $user, $condition, $origdest, $probability );
|
||||
process_one_masq1( $snat, $interfacelist, $networks, $addresses, $proto, $ports, $ipsec, $mark, $user, $condition, $origdest, $probability );
|
||||
}
|
||||
}
|
||||
|
||||
sub open_snat_for_output( $ ) {
|
||||
my ($fn ) = @_;
|
||||
my ( $snat, $fn1 );
|
||||
|
||||
if ( -f ( $fn1 = find_writable_file( 'snat' ) ) ) {
|
||||
open( $snat , '>>', $fn1 ) || fatal_error "Unable to open $fn1:$!";
|
||||
} else {
|
||||
open( $snat , '>', $fn1 ) || fatal_error "Unable to open $fn1:$!";
|
||||
#
|
||||
# Transfer permissions from the existing masq file to the new snat file
|
||||
#
|
||||
transfer_permissions( $fn, $fn1 );
|
||||
|
||||
if ( $family == F_IPV4 ) {
|
||||
print $snat <<'EOF';
|
||||
#
|
||||
# Process the masq file
|
||||
# Shorewall - SNAT/Masquerade File
|
||||
#
|
||||
sub setup_masq()
|
||||
{
|
||||
# For information about entries in this file, type "man shorewall-snat"
|
||||
#
|
||||
# See http://shorewall.net/manpages/shorewall-snat.html for additional information
|
||||
EOF
|
||||
} else {
|
||||
print $snat <<'EOF';
|
||||
#
|
||||
# Shorewall6 - SNAT/Masquerade File
|
||||
#
|
||||
# For information about entries in this file, type "man shorewall6-snat"
|
||||
#
|
||||
# See http://shorewall.net/manpages6/shorewall6-snat.html for additional information
|
||||
EOF
|
||||
}
|
||||
|
||||
print $snat <<'EOF';
|
||||
###################################################################################################################
|
||||
#ACTION SOURCE DEST PROTO PORT IPSEC MARK USER SWITCH ORIGDEST PROBABILITY
|
||||
EOF
|
||||
}
|
||||
|
||||
return ( $snat, $fn1 );
|
||||
}
|
||||
|
||||
#
|
||||
# Convert a masq file into the equivalent snat file
|
||||
#
|
||||
sub convert_masq() {
|
||||
if ( my $fn = open_file( 'masq', 1, 1 ) ) {
|
||||
my ( $snat, $fn1 ) = open_snat_for_output( $fn );
|
||||
|
||||
first_entry( sub { progress_message2 "$doing $fn..."; require_capability 'NAT_ENABLED' , "a non-empty masq file" , 's'; } );
|
||||
my $have_masq_rules;
|
||||
|
||||
process_one_masq while read_a_line( NORMAL_READ );
|
||||
directive_callback( sub () { print $snat "$_[1]\n"; 0; } );
|
||||
|
||||
first_entry(
|
||||
sub {
|
||||
my $date = compiletime;
|
||||
progress_message2 "Converting $fn...";
|
||||
print( $snat
|
||||
"#\n" ,
|
||||
"# Rules generated from masq file $fn by Shorewall $globals{VERSION} - $date\n" ,
|
||||
"#\n" );
|
||||
}
|
||||
);
|
||||
|
||||
process_one_masq($snat), $have_masq_rules++ while read_a_line( NORMAL_READ );
|
||||
|
||||
if ( $have_masq_rules ) {
|
||||
progress_message2 "Converted $fn to $fn1";
|
||||
if ( rename $fn, "$fn.bak" ) {
|
||||
progress_message2 "$fn renamed $fn.bak";
|
||||
} else {
|
||||
fatal_error "Cannot Rename $fn to $fn.bak: $!";
|
||||
}
|
||||
} else {
|
||||
if ( unlink $fn ) {
|
||||
warning_message "Empty masq file ($fn) removed";
|
||||
} else {
|
||||
warning_message "Unable to remove empty masq file $fn: $!";
|
||||
}
|
||||
}
|
||||
|
||||
close $snat, directive_callback( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -472,12 +472,14 @@ sub process_a_provider( $ ) {
|
||||
|
||||
if ( ( $gw = lc $gateway ) eq 'detect' ) {
|
||||
fatal_error "Configuring multiple providers through one interface requires an explicit gateway" if $shared;
|
||||
$gateway = get_interface_gateway $interface;
|
||||
$gateway = get_interface_gateway( $interface, undef, 1 );
|
||||
$gatewaycase = 'detect';
|
||||
set_interface_option( $interface, 'gateway', 'detect' );
|
||||
} elsif ( $gw eq 'none' ) {
|
||||
fatal_error "Configuring multiple providers through one interface requires a gateway" if $shared;
|
||||
$gatewaycase = 'none';
|
||||
$gateway = '';
|
||||
set_interface_option( $interface, 'gateway', 'none' );
|
||||
} elsif ( $gateway && $gateway ne '-' ) {
|
||||
( $gateway, $mac ) = split_host_list( $gateway, 0 );
|
||||
validate_address $gateway, 0;
|
||||
@@ -491,12 +493,15 @@ sub process_a_provider( $ ) {
|
||||
}
|
||||
|
||||
$gatewaycase = 'specified';
|
||||
set_interface_option( $interface, 'gateway', $gateway );
|
||||
} else {
|
||||
$gatewaycase = 'omitted';
|
||||
fatal_error "Configuring multiple providers through one interface requires a gateway" if $shared;
|
||||
$gateway = '';
|
||||
set_interface_option( $interface, 'gateway', $pseudo ? 'detect' : 'omitted' );
|
||||
}
|
||||
|
||||
|
||||
my ( $loose, $track, $balance, $default, $default_balance, $optional, $mtu, $tproxy, $local, $load, $what, $hostroute, $persistent );
|
||||
|
||||
if ( $pseudo ) {
|
||||
@@ -725,9 +730,9 @@ sub emit_started_message( $$$$$ ) {
|
||||
my ( $spaces, $level, $pseudo, $name, $number ) = @_;
|
||||
|
||||
if ( $pseudo ) {
|
||||
emit qq(${spaces}progress_message${level} " Optional interface $name Started");
|
||||
emit qq(${spaces}progress_message${level} "Optional interface $name Started");
|
||||
} else {
|
||||
emit qq(${spaces}progress_message${level} " Provider $name ($number) Started");
|
||||
emit qq(${spaces}progress_message${level} "Provider $name ($number) Started");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -794,7 +799,7 @@ sub add_a_provider( $$ ) {
|
||||
}
|
||||
|
||||
if ( $gateway ) {
|
||||
$address = get_interface_address $interface unless $address;
|
||||
$address = get_interface_address( $interface, 1 ) unless $address;
|
||||
|
||||
emit( qq([ -z "$address" ] && return\n) );
|
||||
|
||||
@@ -920,7 +925,7 @@ CEOF
|
||||
}
|
||||
|
||||
if ( $gateway ) {
|
||||
$address = get_interface_address $interface unless $address;
|
||||
$address = get_interface_address( $interface, 1 ) unless $address;
|
||||
|
||||
if ( $hostroute ) {
|
||||
emit qq(run_ip route replace $gateway src $address dev $physical ${mtu});
|
||||
@@ -1033,6 +1038,16 @@ CEOF
|
||||
emit( qq(rm -f \${VARDIR}/${physical}_disabled) );
|
||||
emit_started_message( '', 2, $pseudo, $table, $number );
|
||||
|
||||
if ( get_interface_option( $interface, 'used_address_variable' ) || get_interface_option( $interface, 'used_gateway_variable' ) ) {
|
||||
emit( '',
|
||||
'if [ -n "$g_forcereload" ]; then',
|
||||
" progress_message2 \"The IP address or gateway of $physical has changed -- forcing reload of the ruleset\"",
|
||||
' COMMAND=reload',
|
||||
' detect_configuration',
|
||||
' define_firewall',
|
||||
'fi' );
|
||||
}
|
||||
|
||||
pop_indent;
|
||||
|
||||
unless ( $pseudo ) {
|
||||
@@ -1043,6 +1058,17 @@ CEOF
|
||||
}
|
||||
|
||||
emit "fi\n";
|
||||
|
||||
if ( get_interface_option( $interface, 'used_address_variable' ) ) {
|
||||
my $variable = interface_address( $interface );
|
||||
|
||||
emit( "echo \$$variable > \${VARDIR}/${physical}.address" );
|
||||
}
|
||||
|
||||
if ( get_interface_option( $interface, 'used_gateway_variable' ) ) {
|
||||
my $variable = interface_gateway( $interface );
|
||||
emit( qq(echo "\$$variable" > \${VARDIR}/${physical}.gateway\n) );
|
||||
}
|
||||
} else {
|
||||
emit( qq(progress_message "Provider $table ($number) Started") );
|
||||
}
|
||||
@@ -1067,6 +1093,17 @@ CEOF
|
||||
} else {
|
||||
emit ( "error_message \"WARNING: Interface $physical is not usable -- Provider $table ($number) not Started\"" );
|
||||
}
|
||||
|
||||
|
||||
if ( get_interface_option( $interface, 'used_address_variable' ) ) {
|
||||
my $variable = interface_address( $interface );
|
||||
emit( "\necho \$$variable > \${VARDIR}/${physical}.address" );
|
||||
}
|
||||
|
||||
if ( get_interface_option( $interface, 'used_gateway_variable' ) ) {
|
||||
my $variable = interface_gateway( $interface );
|
||||
emit( qq(\necho "\$$variable" > \${VARDIR}/${physical}.gateway) );
|
||||
}
|
||||
} else {
|
||||
if ( $shared ) {
|
||||
emit( "fatal_error \"Gateway $gateway is not reachable -- Provider $table ($number) Cannot be Started\"" );
|
||||
@@ -1205,7 +1242,7 @@ sub add_an_rtrule1( $$$$$ ) {
|
||||
if ( $source eq '-' ) {
|
||||
$source = 'from ' . ALLIP;
|
||||
} elsif ( $source =~ s/^&// ) {
|
||||
$source = 'from ' . record_runtime_address '&', $source;
|
||||
$source = 'from ' . record_runtime_address( '&', $source, undef, 1 );
|
||||
} elsif ( $family == F_IPV4 ) {
|
||||
if ( $source =~ /:/ ) {
|
||||
( my $interface, $source , my $remainder ) = split( /:/, $source, 3 );
|
||||
@@ -2139,6 +2176,7 @@ sub handle_optional_interfaces( $ ) {
|
||||
}
|
||||
|
||||
push_indent;
|
||||
|
||||
if ( $providerref->{gatewaycase} eq 'detect' ) {
|
||||
emit qq(if interface_is_usable $physical && [ -n "$providerref->{gateway}" ]; then);
|
||||
} else {
|
||||
@@ -2151,6 +2189,28 @@ sub handle_optional_interfaces( $ ) {
|
||||
emit( " SW_${wildbase}_IS_USABLE=Yes" ) if $interfaceref->{wildcard};
|
||||
emit( 'fi' );
|
||||
|
||||
if ( get_interface_option( $interface, 'used_address_variable' ) ) {
|
||||
my $variable = interface_address( $interface );
|
||||
|
||||
emit( '',
|
||||
"if [ -f \${VARDIR}/${physical}.address ]; then",
|
||||
" if [ \$(cat \${VARDIR}/${physical}.address) != \$$variable ]; then",
|
||||
' g_forcereload=Yes',
|
||||
' fi',
|
||||
'fi' );
|
||||
}
|
||||
|
||||
if ( get_interface_option( $interface, 'used_gateway_variable' ) ) {
|
||||
my $variable = interface_gateway( $interface );
|
||||
|
||||
emit( '',
|
||||
"if [ -f \${VARDIR}/${physical}.gateway ]; then",
|
||||
" if [ \$(cat \${VARDIR}/${physical}.gateway) != \"\$$variable\" ]; then",
|
||||
' g_forcereload=Yes',
|
||||
' fi',
|
||||
'fi' );
|
||||
}
|
||||
|
||||
pop_indent;
|
||||
|
||||
emit( "fi\n" );
|
||||
@@ -2161,6 +2221,7 @@ sub handle_optional_interfaces( $ ) {
|
||||
my $base = uc var_base( $physical );
|
||||
my $case = $physical;
|
||||
my $wild = $case =~ s/\+$/*/;
|
||||
my $variable = interface_address( $interface );
|
||||
|
||||
if ( $wildcards ) {
|
||||
emit( "$case)" );
|
||||
@@ -2181,6 +2242,15 @@ sub handle_optional_interfaces( $ ) {
|
||||
emit ( " SW_${base}_IS_USABLE=Yes" ,
|
||||
'fi' );
|
||||
|
||||
if ( get_interface_option( $interface, 'used_address_variable' ) ) {
|
||||
emit( '',
|
||||
"if [ -f \${VARDIR}/${physical}.address ]; then",
|
||||
" if [ \$(cat \${VARDIR}/${physical}.address) != \$$variable ]; then",
|
||||
' g_forcereload=Yes',
|
||||
' fi',
|
||||
'fi' );
|
||||
}
|
||||
|
||||
if ( $wildcards ) {
|
||||
pop_indent, emit( 'fi' ) if $wild;
|
||||
emit( ';;' );
|
||||
|
@@ -38,6 +38,7 @@ use Shorewall::IPAddrs;
|
||||
use Shorewall::Nat qw(:rules);
|
||||
use Shorewall::Raw qw( handle_helper_rule );
|
||||
use Scalar::Util 'reftype';
|
||||
use Shorewall::Providers qw( provider_realm );
|
||||
|
||||
use strict;
|
||||
|
||||
@@ -57,6 +58,7 @@ our @EXPORT = qw(
|
||||
perl_action_tcp_helper
|
||||
check_state
|
||||
process_reject_action
|
||||
setup_snat
|
||||
);
|
||||
|
||||
our @EXPORT_OK = qw( initialize process_rule );
|
||||
@@ -1301,18 +1303,19 @@ sub finish_section ( $ ) {
|
||||
#
|
||||
sub normalize_action( $$$ ) {
|
||||
my ( $action, $level, $param ) = @_;
|
||||
my $caller = ''; #We assume that the function doesn't use @CALLER
|
||||
my $caller = ''; #We assume that the action doesn't use @CALLER
|
||||
|
||||
( $level, my $tag ) = split ':', $level;
|
||||
|
||||
if ( $actions{$action}{options} & LOGJUMP_OPT ) {
|
||||
$level = 'none';
|
||||
$tag = '';
|
||||
} else {
|
||||
$level = 'none' unless supplied $level;
|
||||
$tag = '' unless defined $tag;
|
||||
}
|
||||
|
||||
#
|
||||
# Note: SNAT actions store the current interface's name in the tag
|
||||
#
|
||||
$tag = '' unless defined $tag;
|
||||
$param = '' unless defined $param;
|
||||
$param = '' if $param eq '-';
|
||||
|
||||
@@ -1610,6 +1613,41 @@ sub merge_macro_source_dest( $$ ) {
|
||||
$body || '';
|
||||
}
|
||||
|
||||
#
|
||||
# This one is used by snat inline
|
||||
#
|
||||
sub merge_inline_source_dest( $$ ) {
|
||||
my ( $body, $invocation ) = @_;
|
||||
|
||||
if ( $invocation ) {
|
||||
if ( supplied $body && $body ne '-' ) {
|
||||
return $body if $invocation eq '-';
|
||||
|
||||
if ( $family == F_IPV4 ) {
|
||||
fatal_error 'Interface names cannot appear in the DEST column within an action body' if $body =~ /:/;
|
||||
|
||||
if ( $invocation =~ /:/ ) {
|
||||
$invocation =~ s/:.*//;
|
||||
return join( ':', $invocation, $body );
|
||||
}
|
||||
} else {
|
||||
fatal_error 'Interface names cannot appear in the DEST column within an action body' if $body =~ /:\[|:\+|/;
|
||||
|
||||
if ( $invocation =~ /:\[|:\+/ ) {
|
||||
$invocation =~ s/:.*//;
|
||||
return join( ':', $invocation, $body );
|
||||
}
|
||||
}
|
||||
|
||||
return "$invocation:$body";
|
||||
}
|
||||
|
||||
return $invocation;
|
||||
}
|
||||
|
||||
$body || '';
|
||||
}
|
||||
|
||||
sub merge_macro_column( $$ ) {
|
||||
my ( $body, $invocation ) = @_;
|
||||
|
||||
@@ -1836,6 +1874,7 @@ my %builtinops = ( 'dropBcast' => \&dropBcast,
|
||||
|
||||
sub process_rule ( $$$$$$$$$$$$$$$$$$$$ );
|
||||
sub process_mangle_rule1( $$$$$$$$$$$$$$$$$$ );
|
||||
sub process_snat1( $$$$$$$$$$$$ );
|
||||
sub perl_action_helper( $$;$$ );
|
||||
|
||||
#
|
||||
@@ -1884,7 +1923,63 @@ sub process_action(\$\$$) {
|
||||
my $save_comment = push_comment;
|
||||
|
||||
while ( read_a_line( NORMAL_READ ) ) {
|
||||
if ( $type & MANGLE_TABLE ) {
|
||||
unless ( $type & ( MANGLE_TABLE | NAT_TABLE | RAW_TABLE ) ) {
|
||||
my ($target, $source, $dest, $protos, $ports, $sports, $origdest, $rate, $users, $mark, $connlimit, $time, $headers, $condition, $helper );
|
||||
|
||||
if ( $file_format == 1 ) {
|
||||
fatal_error( "FORMAT-1 actions are no longer supported" );
|
||||
} else {
|
||||
($target, $source, $dest, $protos, $ports, $sports, $origdest, $rate, $users, $mark, $connlimit, $time, $headers, $condition, $helper )
|
||||
= split_line2( 'action file',
|
||||
\%rulecolumns,
|
||||
$action_commands,
|
||||
undef,
|
||||
1 );
|
||||
}
|
||||
|
||||
fatal_error 'TARGET must be specified' if $target eq '-';
|
||||
|
||||
if ( $target eq 'DEFAULTS' ) {
|
||||
default_action_params( $action, split_list $source, 'defaults' );
|
||||
|
||||
if ( my $state = $actionref->{state} ) {
|
||||
my ( $action ) = get_action_params( 1 );
|
||||
|
||||
if ( my $check = check_state( $state ) ) {
|
||||
perl_action_helper( $action, $check == 1 ? state_match( $state ) : '' , $state );
|
||||
}
|
||||
}
|
||||
|
||||
next;
|
||||
}
|
||||
|
||||
for my $proto ( split_list( $protos, 'Protocol' ) ) {
|
||||
for my $user ( split_list( $users, 'User/Group' ) ) {
|
||||
process_rule( $chainref,
|
||||
'',
|
||||
'',
|
||||
$nolog ? $target : merge_levels( join(':', @actparams{'chain','loglevel','logtag'}), $target ),
|
||||
'',
|
||||
$source,
|
||||
$dest,
|
||||
$proto,
|
||||
$ports,
|
||||
$sports,
|
||||
$origdest,
|
||||
$rate,
|
||||
$user,
|
||||
$mark,
|
||||
$connlimit,
|
||||
$time,
|
||||
$headers,
|
||||
$condition,
|
||||
$helper,
|
||||
0 );
|
||||
|
||||
set_inline_matches( $matches );
|
||||
}
|
||||
}
|
||||
} elsif ( $type & MANGLE_TABLE ) {
|
||||
my ( $originalmark, $source, $dest, $protos, $ports, $sports, $user, $testval, $length, $tos , $connbytes, $helper, $headers, $probability , $dscp , $state, $time );
|
||||
|
||||
if ( $family == F_IPV4 ) {
|
||||
@@ -1968,60 +2063,45 @@ sub process_action(\$\$$) {
|
||||
set_inline_matches( $matches );
|
||||
}
|
||||
} else {
|
||||
my ($target, $source, $dest, $protos, $ports, $sports, $origdest, $rate, $users, $mark, $connlimit, $time, $headers, $condition, $helper );
|
||||
my ( $action, $source, $dest, $protos, $port, $ipsec, $mark, $user, $condition, $origdest, $probability) =
|
||||
split_line2( 'snat file',
|
||||
{ action =>0,
|
||||
source => 1,
|
||||
dest => 2,
|
||||
proto => 3,
|
||||
port => 4,
|
||||
ipsec => 5,
|
||||
mark => 6,
|
||||
user => 7,
|
||||
switch => 8,
|
||||
origdest => 9,
|
||||
probability => 10,
|
||||
},
|
||||
{},
|
||||
11,
|
||||
1 );
|
||||
|
||||
if ( $file_format == 1 ) {
|
||||
fatal_error( "FORMAT-1 actions are no longer supported" );
|
||||
} else {
|
||||
($target, $source, $dest, $protos, $ports, $sports, $origdest, $rate, $users, $mark, $connlimit, $time, $headers, $condition, $helper )
|
||||
= split_line2( 'action file',
|
||||
\%rulecolumns,
|
||||
$action_commands,
|
||||
undef,
|
||||
1 );
|
||||
}
|
||||
|
||||
fatal_error 'TARGET must be specified' if $target eq '-';
|
||||
|
||||
if ( $target eq 'DEFAULTS' ) {
|
||||
default_action_params( $action, split_list $source, 'defaults' );
|
||||
|
||||
if ( my $state = $actionref->{state} ) {
|
||||
my ( $action ) = get_action_params( 1 );
|
||||
|
||||
if ( my $check = check_state( $state ) ) {
|
||||
perl_action_helper( $action, $check == 1 ? state_match( $state ) : '' , $state );
|
||||
}
|
||||
}
|
||||
fatal_error 'ACTION must be specified' if $action eq '-';
|
||||
|
||||
if ( $action eq 'DEFAULTS' ) {
|
||||
default_action_params( $chainref, split_list( $source, 'defaults' ) );
|
||||
next;
|
||||
}
|
||||
|
||||
for my $proto ( split_list( $protos, 'Protocol' ) ) {
|
||||
for my $user ( split_list( $users, 'User/Group' ) ) {
|
||||
process_rule( $chainref,
|
||||
'',
|
||||
'',
|
||||
$nolog ? $target : merge_levels( join(':', @actparams{'chain','loglevel','logtag'}), $target ),
|
||||
'',
|
||||
$source,
|
||||
$dest,
|
||||
$proto,
|
||||
$ports,
|
||||
$sports,
|
||||
$origdest,
|
||||
$rate,
|
||||
$user,
|
||||
$mark,
|
||||
$connlimit,
|
||||
$time,
|
||||
$headers,
|
||||
$condition,
|
||||
$helper,
|
||||
0 );
|
||||
|
||||
set_inline_matches( $matches );
|
||||
}
|
||||
for my $proto (split_list( $protos, 'Protocol' ) ) {
|
||||
process_snat1( $chainref,
|
||||
$action,
|
||||
$source,
|
||||
$dest,
|
||||
$proto,
|
||||
$port,
|
||||
$ipsec,
|
||||
$mark,
|
||||
$user,
|
||||
$condition,
|
||||
$origdest,
|
||||
$probability,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2175,9 +2255,14 @@ sub process_actions() {
|
||||
|
||||
make_terminating( $action ) if $opts & TERMINATING_OPT
|
||||
} else {
|
||||
fatal_error "Only the 'mangle' and 'filter' table may be specified for non-builtin actions" if $opts & ( RAW_OPT | NAT_OPT );
|
||||
fatal_error "The 'raw' table may not be specified for non-builtin actions" if $opts & RAW_OPT;
|
||||
|
||||
$type |= MANGLE_TABLE if $opts & MANGLE_OPT;
|
||||
|
||||
if ( $opts & NAT_OPT ) {
|
||||
fatal_error q(The 'mangle' and 'nat' options are mutually exclusive) if $opts & MANGLE_OPT;
|
||||
$type |= NAT_TABLE;
|
||||
}
|
||||
|
||||
my $actionfile = find_file( "action.$action" );
|
||||
|
||||
@@ -2891,7 +2976,7 @@ sub process_rule ( $$$$$$$$$$$$$$$$$$$$ ) {
|
||||
fatal_error "A timeout may only be supplied in an ADD rule" unless $basictarget eq 'ADD';
|
||||
fatal_error "Invalid Timeout ($timeout)" unless $timeout && $timeout =~ /^\d+$/;
|
||||
|
||||
$action .= " --timeout $timeout";
|
||||
$action .= " --timeout $timeout --exist";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3958,14 +4043,14 @@ sub process_mangle_inline( $$$$$$$$$$$$$$$$$$$ ) {
|
||||
}
|
||||
|
||||
$msource = $source if $msource eq '-';
|
||||
$mdest = $dest if $msource eq '-';
|
||||
$mdest = $dest if $mdest eq '-';
|
||||
$mprotos = $protos if $mprotos eq '-';
|
||||
|
||||
for my $proto (split_list( $mprotos, 'Protocol' ) ) {
|
||||
process_mangle_rule1( $chainref,
|
||||
$moriginalmark,
|
||||
$msource,
|
||||
$dest,
|
||||
$mdest,
|
||||
$proto,
|
||||
merge_macro_column( $mports, $ports ),
|
||||
merge_macro_column( $msports, $sports ),
|
||||
@@ -4098,11 +4183,13 @@ sub process_mangle_rule1( $$$$$$$$$$$$$$$$$$ ) {
|
||||
|
||||
my $chainref = ensure_chain( 'mangle', $chain = $chainnames{$chain} );
|
||||
|
||||
$restriction |= $chainref->{restriction};
|
||||
|
||||
for ( my $packet = 0; $packet < $marks; $packet++, $markval += $increment ) {
|
||||
my $match = "-m statistic --mode nth --every $marks --packet $packet ";
|
||||
|
||||
expand_rule( $chainref,
|
||||
$restrictions{$chain} | $restriction,
|
||||
$restriction,
|
||||
$prerule ,
|
||||
$match .
|
||||
do_user( $user ) .
|
||||
@@ -4845,8 +4932,10 @@ sub process_mangle_rule1( $$$$$$$$$$$$$$$$$$ ) {
|
||||
$chainref = ensure_chain( 'mangle', $chainnames{$chain} );
|
||||
}
|
||||
|
||||
$restriction |= $chainref->{restriction};
|
||||
|
||||
if ( ( my $result = expand_rule( $chainref ,
|
||||
( $restrictions{$chain} || 0 ) | $restriction,
|
||||
$restriction,
|
||||
$prerule,
|
||||
do_proto( $proto, $ports, $sports) . $matches .
|
||||
do_user( $user ) .
|
||||
@@ -5161,4 +5250,533 @@ sub process_mangle_rule( $ ) {
|
||||
}
|
||||
}
|
||||
|
||||
sub process_snat_inline( $$$$$$$$$$$$$ ) {
|
||||
my ($inline, $chainref, $params, $source, $dest, $protos, $ports, $ipsec, $mark, $user, $condition, $origdest, $probability ) = @_;
|
||||
|
||||
my $oldparms = push_action_params( $inline,
|
||||
$chainref,
|
||||
$params,
|
||||
'none',
|
||||
'' ,
|
||||
$chainref->{name} );
|
||||
|
||||
my $inlinefile = $actions{$inline}{file};
|
||||
my $matches = fetch_inline_matches;
|
||||
|
||||
progress_message "..Expanding inline action $inlinefile...";
|
||||
|
||||
push_open $inlinefile, 2, 1, undef , 2;
|
||||
|
||||
my $save_comment = push_comment;
|
||||
|
||||
while ( read_a_line( NORMAL_READ ) ) {
|
||||
my ( $maction, $msource, $mdest, $mprotos, $mports, $mipsec, $mmark, $muser, $mcondition, $morigdest, $mprobability) =
|
||||
split_line2( 'snat file',
|
||||
{ action =>0,
|
||||
source => 1,
|
||||
dest => 2,
|
||||
proto => 3,
|
||||
port => 4,
|
||||
ipsec => 5,
|
||||
mark => 6,
|
||||
user => 7,
|
||||
switch => 8,
|
||||
origdest => 9,
|
||||
probability => 10,
|
||||
},
|
||||
{},
|
||||
11,
|
||||
1 );
|
||||
|
||||
fatal_error 'ACTION must be specified' if $maction eq '-';
|
||||
|
||||
if ( $maction eq 'DEFAULTS' ) {
|
||||
default_action_params( $chainref, split_list( $msource, 'defaults' ) );
|
||||
next;
|
||||
}
|
||||
|
||||
$msource = $source if $msource eq '-';
|
||||
|
||||
if ( $mdest eq '-' ) {
|
||||
$mdest = $dest;
|
||||
} else {
|
||||
$mdest = merge_inline_source_dest( $mdest, $dest );
|
||||
}
|
||||
|
||||
$mprotos = $protos if $mprotos eq '-';
|
||||
|
||||
for my $proto (split_list( $mprotos, 'Protocol' ) ) {
|
||||
process_snat1( $chainref,
|
||||
$maction,
|
||||
$msource,
|
||||
$mdest,
|
||||
$proto,
|
||||
merge_macro_column( $mports, $ports ),
|
||||
merge_macro_column( $mipsec, $ipsec ),
|
||||
merge_macro_column( $mmark, $mark ),
|
||||
merge_macro_column( $muser, $user ),
|
||||
merge_macro_column( $mcondition, $condition ),
|
||||
merge_macro_column( $morigdest , $origdest ),
|
||||
merge_macro_column( $mprobability, $probability ),
|
||||
);
|
||||
}
|
||||
|
||||
progress_message " Rule \"$currentline\" $done";
|
||||
|
||||
set_inline_matches( $matches );
|
||||
}
|
||||
|
||||
pop_comment( $save_comment );
|
||||
|
||||
pop_open;
|
||||
|
||||
progress_message "..End inline action $inlinefile";
|
||||
|
||||
pop_action_params( $oldparms );
|
||||
}
|
||||
|
||||
#
|
||||
# Process a record in the snat file
|
||||
#
|
||||
sub process_snat1( $$$$$$$$$$$$ ) {
|
||||
my ( $chainref, $action, $source, $dest, $proto, $ports, $ipsec, $mark, $user, $condition, $origdest, $probability ) = @_;
|
||||
|
||||
my $inchain;
|
||||
my $inaction;
|
||||
my $pre_nat;
|
||||
my $add_snat_aliases = $family == F_IPV4 && $config{ADD_SNAT_ALIASES};
|
||||
my $destnets = '';
|
||||
my $baserule = '';
|
||||
my $inlinematches = get_inline_matches(0);
|
||||
my $prerule = '';
|
||||
my $options = '';
|
||||
my $addresses;
|
||||
my $target;
|
||||
my $params;
|
||||
my $actiontype;
|
||||
my $interfaces;
|
||||
my $normalized_action;
|
||||
|
||||
if ( $action =~ /^MASQUERADE(\+)?(?:\((.+)\))?$/ ) {
|
||||
$target = 'MASQUERADE';
|
||||
$actiontype = $builtin_target{$action = $target};
|
||||
$pre_nat = $1;
|
||||
$addresses = ( $2 || '' );
|
||||
$options = 'random' if $addresses =~ s/:?random$//;
|
||||
$add_snat_aliases = '';
|
||||
} elsif ( $action =~ /^SNAT(\+)?\((.+)\)$/ ) {
|
||||
$pre_nat = $1;
|
||||
$addresses = $2;
|
||||
$target = 'SNAT';
|
||||
$actiontype = $builtin_target{$action = $target};
|
||||
$options .= ':persistent' if $addresses =~ s/:persistent//;
|
||||
$options .= ':random' if $addresses =~ s/:random//;
|
||||
$options =~ s/^://;
|
||||
} elsif ( $action =~ /^CONTINUE(\+)?$/ ) {
|
||||
$add_snat_aliases = 0;
|
||||
$actiontype = $builtin_target{$target = 'RETURN'};
|
||||
$pre_nat = $1;
|
||||
} elsif ( $action eq 'MASQUERADE' ) {
|
||||
$actiontype = $builtin_target{$target = 'MASQUERADE'};
|
||||
$add_snat_aliases = '';
|
||||
} else {
|
||||
( $target , $params ) = get_target_param1( $action );
|
||||
|
||||
$pre_nat = ( $target =~ s/\+$// );
|
||||
|
||||
$actiontype = ( $targets{$target} || 0 );
|
||||
|
||||
fatal_error "Invalid ACTION ($action)" unless $actiontype & ( ACTION | INLINE );
|
||||
}
|
||||
|
||||
if ( $inchain = defined $chainref ) {
|
||||
( $inaction, undef, $interfaces, undef, undef ) = split /:/, $normalized_action = $chainref->{action}, 5 if $chainref->{action};
|
||||
fatal_error q('+' is not allowed within an action body) if $pre_nat;
|
||||
}
|
||||
#
|
||||
# Next, parse the DEST column
|
||||
#
|
||||
if ( $inaction ) {
|
||||
$destnets = $dest;
|
||||
} elsif ( $family == F_IPV4 ) {
|
||||
if ( $dest =~ /^([^:]+)::([^:]*)$/ ) {
|
||||
$add_snat_aliases = 0;
|
||||
$destnets = $2;
|
||||
$interfaces = $1;
|
||||
} elsif ( $dest =~ /^([^:]+:[^:]+):([^:]+)$/ ) {
|
||||
$destnets = $2;
|
||||
$interfaces = $1;
|
||||
} elsif ( $dest =~ /^([^:]+):$/ ) {
|
||||
$add_snat_aliases = 0;
|
||||
$interfaces = $1;
|
||||
} elsif ( $dest =~ /^([^:]+):([^:]*)$/ ) {
|
||||
my ( $one, $two ) = ( $1, $2 );
|
||||
if ( $2 =~ /\./ || $2 =~ /^%/ ) {
|
||||
$interfaces = $one;
|
||||
$destnets = $two;
|
||||
} else {
|
||||
$interfaces = $dest;
|
||||
}
|
||||
} else {
|
||||
$interfaces = $dest;
|
||||
}
|
||||
} elsif ( $dest =~ /^(.+?):(.+)$/ ) {
|
||||
$interfaces = $1;
|
||||
$destnets = $2;
|
||||
} else {
|
||||
$interfaces = $dest;
|
||||
}
|
||||
#
|
||||
# Handle IPSEC options, if any
|
||||
#
|
||||
if ( $ipsec ne '-' ) {
|
||||
fatal_error "Non-empty IPSEC column requires policy match support in your kernel and iptables" unless have_capability( 'POLICY_MATCH' );
|
||||
|
||||
if ( $ipsec =~ /^yes$/i ) {
|
||||
$baserule .= do_ipsec_options 'out', 'ipsec', '';
|
||||
} elsif ( $ipsec =~ /^no$/i ) {
|
||||
$baserule .= do_ipsec_options 'out', 'none', '';
|
||||
} else {
|
||||
$baserule .= do_ipsec_options 'out', 'ipsec', $ipsec;
|
||||
}
|
||||
} elsif ( have_ipsec ) {
|
||||
$baserule .= '-m policy --pol none --dir out ';
|
||||
}
|
||||
#
|
||||
# Handle Protocol, Ports and Condition
|
||||
#
|
||||
$baserule .= do_proto( $proto, $ports, '' );
|
||||
#
|
||||
# Handle Mark
|
||||
#
|
||||
$baserule .= do_test( $mark, $globals{TC_MASK} ) if $mark ne '-';
|
||||
$baserule .= do_user( $user ) if $user ne '-';
|
||||
$baserule .= do_probability( $probability ) if $probability ne '-';
|
||||
|
||||
for my $fullinterface ( split_list( $interfaces, 'interface' ) ) {
|
||||
|
||||
my $rule = '';
|
||||
my $saveaddresses = $addresses;
|
||||
my $savetarget = $target;
|
||||
my $savebaserule = $baserule;
|
||||
my $interface = $fullinterface;
|
||||
|
||||
$interface =~ s/:.*//; #interface name may include 'alias'
|
||||
|
||||
unless ( $inaction ) {
|
||||
if ( $interface =~ /(.*)[(](\w*)[)]$/ ) {
|
||||
$interface = $1;
|
||||
my $provider = $2;
|
||||
|
||||
fatal_error "Missing Provider ($dest)" unless supplied $provider;
|
||||
|
||||
$dest =~ s/[(]\w*[)]//;
|
||||
my $realm = provider_realm( $provider );
|
||||
|
||||
fatal_error "$provider is not a shared-interface provider" unless $realm;
|
||||
|
||||
$rule .= "-m realm --realm $realm ";
|
||||
}
|
||||
|
||||
fatal_error "Unknown interface ($interface)" unless my $interfaceref = known_interface( $interface );
|
||||
|
||||
if ( $interfaceref->{root} ) {
|
||||
$interface = $interfaceref->{name} if $interface eq $interfaceref->{physical};
|
||||
} else {
|
||||
$rule .= match_dest_dev( $interface );
|
||||
$interface = $interfaceref->{name};
|
||||
}
|
||||
|
||||
$chainref = ensure_chain('nat', $pre_nat ? snat_chain $interface : masq_chain $interface);
|
||||
}
|
||||
|
||||
$baserule .= do_condition( $condition , $chainref->{name} );
|
||||
|
||||
my $detectaddress = 0;
|
||||
my $exceptionrule = '';
|
||||
my $conditional = 0;
|
||||
|
||||
if ( $action eq 'SNAT' ) {
|
||||
if ( $addresses eq 'detect' ) {
|
||||
my $variable = get_interface_address $interface;
|
||||
$target .= " --to-source $variable";
|
||||
|
||||
if ( interface_is_optional $interface ) {
|
||||
add_commands( $chainref,
|
||||
'',
|
||||
"if [ \"$variable\" != 0.0.0.0 ]; then" );
|
||||
incr_cmd_level( $chainref );
|
||||
$detectaddress = 1;
|
||||
}
|
||||
} else {
|
||||
fatal_error "SNAT rules must spacify a new source address and/or new source ports" unless supplied $addresses;
|
||||
|
||||
my $addrlist = '';
|
||||
my @addrs = split_list $addresses, 'address';
|
||||
|
||||
fatal_error "Only one SNAT address may be specified" if @addrs > 1;
|
||||
|
||||
for my $addr ( @addrs ) {
|
||||
if ( $addr =~ /^([&%])(.+)$/ ) {
|
||||
my ( $type, $interface ) = ( $1, $2 );
|
||||
|
||||
my $ports = '';
|
||||
|
||||
if ( $interface =~ s/:(.+)$// ) {
|
||||
validate_portpair1( $proto, $1 );
|
||||
$ports = ":$1";
|
||||
}
|
||||
#
|
||||
# Address Variable
|
||||
#
|
||||
if ( $interface =~ /^{([a-zA-Z_]\w*)}$/ ) {
|
||||
#
|
||||
# User-defined address variable
|
||||
#
|
||||
$conditional = conditional_rule( $chainref, $addr );
|
||||
$addrlist .= ' --to-source ' . "\$${1}${ports} ";
|
||||
} else {
|
||||
if ( $conditional = conditional_rule( $chainref, $addr ) ) {
|
||||
#
|
||||
# Optional Interface -- rule is conditional
|
||||
#
|
||||
$addr = get_interface_address $interface;
|
||||
} else {
|
||||
#
|
||||
# Interface is not optional
|
||||
#
|
||||
$addr = record_runtime_address( $type, $interface );
|
||||
}
|
||||
|
||||
if ( $ports ) {
|
||||
$addr =~ s/ $//;
|
||||
$addr = $family == F_IPV4 ? "${addr}${ports} " : "[$addr]$ports ";
|
||||
}
|
||||
|
||||
$addrlist .= ' --to-source ' . $addr;
|
||||
}
|
||||
} elsif ( $family == F_IPV4 ) {
|
||||
if ( $addr =~ /^.*\..*\..*\./ ) {
|
||||
my ($ipaddr, $rest) = split ':', $addr, 2;
|
||||
if ( $ipaddr =~ /^(.+)-(.+)$/ ) {
|
||||
validate_range( $1, $2 );
|
||||
} else {
|
||||
validate_address $ipaddr, 0;
|
||||
}
|
||||
|
||||
if ( supplied $rest ) {
|
||||
validate_portpair1( $proto, $rest );
|
||||
$addrlist .= " --to-source $addr";
|
||||
} else {
|
||||
$addrlist .= " --to-source $ipaddr";
|
||||
}
|
||||
|
||||
$exceptionrule = do_proto( $proto, '', '' ) if $addr =~ /:/;
|
||||
} else {
|
||||
my $ports = $addr;
|
||||
$ports =~ s/^://;
|
||||
fatal_error "Missing Address or Port[-range] ($addr)" unless supplied $ports && $ports ne '-';
|
||||
validate_portpair1( $proto, $ports );
|
||||
$addrlist .= " --to-source :$ports";
|
||||
$exceptionrule = do_proto( $proto, '', '' );
|
||||
}
|
||||
} else {
|
||||
if ( $addr =~ /^\[/ ) {
|
||||
#
|
||||
# Can have ports specified
|
||||
#
|
||||
my $ports;
|
||||
|
||||
if ( $addr =~ s/:([^]:]+)$// ) {
|
||||
$ports = $1;
|
||||
}
|
||||
|
||||
fatal_error "Invalid IPv6 Address ($addr)" unless $addr =~ /^\[(.+)\]$/;
|
||||
|
||||
$addr = $1;
|
||||
|
||||
if ( $addr =~ /^(.+)-(.+)$/ ) {
|
||||
fatal_error "Correct address range syntax is '[<addr1>-<addr2>]'" if $addr =~ /]-\[/;
|
||||
validate_range( $1, $2 );
|
||||
} else {
|
||||
validate_address $addr, 0;
|
||||
}
|
||||
|
||||
if ( supplied $ports ) {
|
||||
validate_portpair1( $proto, $ports );
|
||||
$exceptionrule = do_proto( $proto, '', '' );
|
||||
$addr = "[$addr]:$ports";
|
||||
}
|
||||
|
||||
$addrlist .= " --to-source $addr";
|
||||
} else {
|
||||
if ( $addr =~ /^(.+)-(.+)$/ ) {
|
||||
validate_range( $1, $2 );
|
||||
} else {
|
||||
validate_address $addr, 0;
|
||||
}
|
||||
|
||||
$addrlist .= " --to-source $addr";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$target .= $addrlist;
|
||||
}
|
||||
} elsif ( $action eq 'MASQUERADE' ) {
|
||||
if ( supplied $addresses ) {
|
||||
validate_portpair1($proto, $addresses );
|
||||
$target .= " --to-ports $addresses";
|
||||
$exceptionrule = do_proto( $proto, '', '' );
|
||||
}
|
||||
}
|
||||
#
|
||||
# And Generate the Rule(s)
|
||||
#
|
||||
if ( $actiontype & INLINE ) {
|
||||
fatal_error( qq(Action $target may not be used in the snat file) ) unless $actiontype & NAT_TABLE;
|
||||
|
||||
process_snat_inline( $target,
|
||||
$chainref,
|
||||
$params,
|
||||
$source,
|
||||
supplied $destnets && $destnets ne '-' ? $inaction ? $destnets : join( ':', $interface, $destnets ) : $inaction ? '-' : $interface,
|
||||
$proto,
|
||||
$ports,
|
||||
$ipsec,
|
||||
$mark,
|
||||
$user,
|
||||
$condition,
|
||||
$origdest,
|
||||
$probability );
|
||||
} else {
|
||||
if ( $actiontype & ACTION ) {
|
||||
fatal_error( qq(Action $target may not be used in the snat file) ) unless $actiontype & NAT_TABLE;
|
||||
#
|
||||
# Create the action:level:tag:param tuple. Since we don't allow logging out of nat POSTROUTING, we store
|
||||
# the interface name in the log tag
|
||||
#
|
||||
my $normalized_target = normalize_action( $target, "none:$interface", $params );
|
||||
fatal_error( "Action $target invoked Recursively (" . join( '->', map( external_name( $_ ), @actionstack , $normalized_target ) ) . ')' ) if $active{$target};
|
||||
|
||||
my $ref = use_action( 'nat', $normalized_target );
|
||||
|
||||
if ( $ref ) {
|
||||
#
|
||||
# First reference to this tuple - process_action may modify both $normalized_target and $ref!!!
|
||||
#
|
||||
process_action( $normalized_target, $ref, $chainref->{name} );
|
||||
#
|
||||
# Capture the name of the action chain
|
||||
#
|
||||
} else {
|
||||
#
|
||||
# We've seen this tuple before
|
||||
#
|
||||
$ref = $usedactions{$normalized_target};
|
||||
}
|
||||
|
||||
$target = $ref->{name};
|
||||
} else {
|
||||
for my $option ( split_list2( $options , 'option' ) ) {
|
||||
if ( $option eq 'random' ) {
|
||||
$target .= ' --random';
|
||||
require_capability( 'MASQUERADE_TGT', "$action rules", '') if $family == F_IPV6;
|
||||
} elsif ( $option eq 'persistent' ) {
|
||||
fatal_error( "':persistent' is not allowed in a MASQUERADE rule" ) if $action eq 'MASQUERADE';
|
||||
require_capability 'PERSISTENT_SNAT', ':persistent', 's';
|
||||
$target .= ' --persistent';
|
||||
} else {
|
||||
fatal_error "Invalid $action option ($option)";
|
||||
}
|
||||
}
|
||||
}
|
||||
#
|
||||
# If there is no source or destination then allow all addresses
|
||||
#
|
||||
$source = ALLIP if $source eq '-';
|
||||
$destnets = ALLIP unless supplied $destnets && $destnets ne '-';
|
||||
|
||||
expand_rule( $chainref ,
|
||||
POSTROUTE_RESTRICT ,
|
||||
$prerule ,
|
||||
$baserule . $inlinematches . $rule ,
|
||||
$source ,
|
||||
$destnets ,
|
||||
$origdest ,
|
||||
$target ,
|
||||
'' ,
|
||||
'' ,
|
||||
$exceptionrule ,
|
||||
'' )
|
||||
unless unreachable_warning( 0, $chainref );
|
||||
|
||||
conditional_rule_end( $chainref ) if $detectaddress || $conditional;
|
||||
|
||||
if ( $add_snat_aliases && $addresses ) {
|
||||
my ( $interface, $alias , $remainder ) = split( /:/, $fullinterface, 3 );
|
||||
fatal_error "Invalid alias ($alias:$remainder)" if defined $remainder;
|
||||
for my $address ( split_list $addresses, 'address' ) {
|
||||
my ( $addrs, $port ) = split /:/, $address;
|
||||
next unless $addrs;
|
||||
next if $addrs eq 'detect';
|
||||
for my $addr ( ip_range_explicit $addrs ) {
|
||||
unless ( $addresses_to_add{$addr} ) {
|
||||
$addresses_to_add{$addr} = 1;
|
||||
if ( defined $alias ) {
|
||||
push @addresses_to_add, $addr, "$interface:$alias";
|
||||
$alias++;
|
||||
} else {
|
||||
push @addresses_to_add, $addr, $interface;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$addresses = $saveaddresses;
|
||||
$target = $savetarget;
|
||||
$baserule = $savebaserule;
|
||||
}
|
||||
|
||||
progress_message " Snat record \"$currentline\" $done"
|
||||
|
||||
}
|
||||
|
||||
sub process_snat( )
|
||||
{
|
||||
my ($action, $source, $dest, $protos, $ports, $ipsec, $mark, $user, $condition, $origdest, $probability ) =
|
||||
split_line2( 'snat file',
|
||||
{ action => 0, source => 1, dest => 2, proto => 3, port => 4, ipsec => 5, mark => 6, user => 7, switch => 8, origdest => 9, probability => 10 },
|
||||
{}, #Nopad
|
||||
undef, #Columns
|
||||
1 ); #Allow inline matches
|
||||
|
||||
fatal_error 'ACTION must be specified' if $action eq '-';
|
||||
fatal_error 'DEST must be specified' if $dest eq '-';
|
||||
|
||||
for my $proto ( split_list $protos, 'Protocol' ) {
|
||||
process_snat1( undef, $action, $source, $dest, $proto, $ports, $ipsec, $mark, $user, $condition, $origdest, $probability );
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Process the masq or snat file
|
||||
#
|
||||
sub setup_snat( $ ) # Convert masq->snat if true
|
||||
{
|
||||
my $fn;
|
||||
|
||||
convert_masq() if $_[0];
|
||||
|
||||
if ( $fn = open_file( 'masq', 1, 1 ) ) {
|
||||
first_entry( sub { progress_message2 "$doing $fn..."; require_capability 'NAT_ENABLED' , "a non-empty masq file" , 's'; } );
|
||||
process_one_masq(0) while read_a_line( NORMAL_READ );
|
||||
} elsif ( $fn = open_file( 'snat', 1, 1 ) ) {
|
||||
first_entry( sub { progress_message2 "$doing $fn..."; require_capability 'NAT_ENABLED' , "a non-empty snat file" , 's'; } );
|
||||
process_snat while read_a_line( NORMAL_READ );
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
@@ -827,7 +827,7 @@ sub validate_tc_class( ) {
|
||||
fatal_error "Invalid 'occurs' ($val)" unless defined $occurs && $occurs > 1 && $occurs <= 256;
|
||||
fatal_error "Invalid 'occurs' ($val)" if $occurs > $globals{TC_MAX};
|
||||
fatal_error q(Duplicate 'occurs') if $tcref->{occurs} > 1;
|
||||
fatal_error q(The 'occurs' option is not valid with 'default') if $devref->{default} == $classnumber;
|
||||
fatal_error q(The 'occurs' option is not valid with 'default') if defined($devref->{default}) && $devref->{default} == $classnumber;
|
||||
fatal_error q(The 'occurs' option is not valid with 'tos') if @{$tcref->{tos}};
|
||||
warning_message "MARK ($mark) is ignored on an occurring class" if $mark ne '-';
|
||||
|
||||
@@ -1308,6 +1308,8 @@ sub handle_ematch( $$ ) {
|
||||
|
||||
$setname =~ s/\+//;
|
||||
|
||||
add_ipset($setname);
|
||||
|
||||
return "ipset\\($setname $options\\)";
|
||||
}
|
||||
|
||||
@@ -1518,7 +1520,7 @@ sub process_tc_filter2( $$$$$$$$$ ) {
|
||||
$rule .= ' and' if $have_rule;
|
||||
|
||||
if ( $source =~ /^\+/ ) {
|
||||
$rule = join( '', "\\\n ", handle_ematch( $source, 'src' ) );
|
||||
$rule .= join( '', "\\\n ", handle_ematch( $source, 'src' ) );
|
||||
} else {
|
||||
my @parts = decompose_net_u32( $source );
|
||||
|
||||
@@ -1557,9 +1559,9 @@ sub process_tc_filter2( $$$$$$$$$ ) {
|
||||
$rule .= ' and' if @parts;
|
||||
}
|
||||
}
|
||||
|
||||
$have_rule = 1;
|
||||
}
|
||||
|
||||
$have_rule = 1;
|
||||
}
|
||||
|
||||
if ( $have_rule ) {
|
||||
@@ -2276,13 +2278,13 @@ sub setup_tc( $ ) {
|
||||
$convert = $_[0];
|
||||
|
||||
if ( $config{MANGLE_ENABLED} ) {
|
||||
ensure_mangle_chain 'tcpre';
|
||||
ensure_mangle_chain 'tcout';
|
||||
ensure_mangle_chain( 'tcpre', PREROUTING, PREROUTE_RESTRICT );
|
||||
ensure_mangle_chain( 'tcout', OUTPUT , OUTPUT_RESTRICT );
|
||||
|
||||
if ( have_capability( 'MANGLE_FORWARD' ) ) {
|
||||
ensure_mangle_chain 'tcfor';
|
||||
ensure_mangle_chain 'tcpost';
|
||||
ensure_mangle_chain 'tcin';
|
||||
ensure_mangle_chain( 'tcfor', FORWARD , NO_RESTRICT );
|
||||
ensure_mangle_chain( 'tcpost', POSTROUTING, POSTROUTE_RESTRICT );
|
||||
ensure_mangle_chain( 'tcin', INPUT , INPUT_RESTRICT );
|
||||
}
|
||||
|
||||
my @mark_part;
|
||||
|
@@ -95,7 +95,6 @@ our @EXPORT = ( qw( NOTHING
|
||||
get_interface_origin
|
||||
interface_has_option
|
||||
set_interface_option
|
||||
set_interface_provider
|
||||
interface_zone
|
||||
interface_zones
|
||||
verify_required_interfaces
|
||||
@@ -195,7 +194,6 @@ our %reservedName = ( all => 1,
|
||||
# number => <ordinal position in the interfaces file>
|
||||
# physical => <physical interface name>
|
||||
# base => <shell variable base representing this interface>
|
||||
# provider => <Provider Name, if interface is associated with a provider>
|
||||
# wildcard => undef|1 # Wildcard Name
|
||||
# zones => { zone1 => 1, ... }
|
||||
# origin => <where defined>
|
||||
@@ -398,7 +396,6 @@ sub initialize( $$ ) {
|
||||
nodbl => SIMPLE_IF_OPTION,
|
||||
nosmurfs => SIMPLE_IF_OPTION + IF_OPTION_HOST,
|
||||
optional => SIMPLE_IF_OPTION,
|
||||
optional => SIMPLE_IF_OPTION,
|
||||
proxyndp => BINARY_IF_OPTION,
|
||||
required => SIMPLE_IF_OPTION,
|
||||
routeback => BINARY_IF_OPTION + IF_OPTION_ZONEONLY + IF_OPTION_HOST + IF_OPTION_VSERVER,
|
||||
|
@@ -128,6 +128,7 @@ g_compiled=
|
||||
g_file=
|
||||
g_docker=
|
||||
g_dockernetwork=
|
||||
g_forcereload=
|
||||
|
||||
initialize
|
||||
|
||||
|
@@ -1,19 +0,0 @@
|
||||
#
|
||||
# Shorewall - Sample Masq file for three-interface configuration.
|
||||
# Copyright (C) 2006-2015 by the Shorewall Team
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# See the file README.txt for further details.
|
||||
#------------------------------------------------------------------------------
|
||||
# For information about entries in this file, type "man shorewall-masq"
|
||||
################################################################################################################
|
||||
#INTERFACE:DEST SOURCE ADDRESS PROTO PORT(S) IPSEC MARK USER/ SWITCH ORIGINAL
|
||||
# GROUP DEST
|
||||
eth0 10.0.0.0/8,\
|
||||
169.254.0.0/16,\
|
||||
172.16.0.0/12,\
|
||||
192.168.0.0/16
|
23
Shorewall/Samples/three-interfaces/snat
Normal file
23
Shorewall/Samples/three-interfaces/snat
Normal file
@@ -0,0 +1,23 @@
|
||||
#
|
||||
# Shorewall - Sample SNAT/Masqueradee File for three-interface configuration.
|
||||
# Copyright (C) 2006-2016 by the Shorewall Team
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# See the file README.txt for further details.
|
||||
#------------------------------------------------------------------------------
|
||||
# For information about entries in this file, type "man shorewall-snat"
|
||||
#
|
||||
# See http://shorewall.net/manpages/shorewall-snat.html for more information
|
||||
###########################################################################################################################################
|
||||
#ACTION SOURCE DEST PROTO PORT IPSEC MARK USER SWITCH ORIGDEST PROBABILITY
|
||||
#
|
||||
# Rules generated from masq file /home/teastep/shorewall/trunk/Shorewall/Samples/three-interfaces/masq by Shorewall 5.0.13-RC1 - Sat Oct 15 11:43:47 PDT 2016
|
||||
#
|
||||
MASQUERADE 10.0.0.0/8,\
|
||||
169.254.0.0/16,\
|
||||
172.16.0.0/12,\
|
||||
192.168.0.0/16 eth0
|
@@ -1,19 +0,0 @@
|
||||
#
|
||||
# Shorewall - Sample Masq file for two-interface configuration.
|
||||
# Copyright (C) 2006-2015 by the Shorewall Team
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# See the file README.txt for further details.
|
||||
#------------------------------------------------------------------------------
|
||||
# For information about entries in this file, type "man shorewall-masq"
|
||||
################################################################################################################
|
||||
#INTERFACE:DEST SOURCE ADDRESS PROTO PORT(S) IPSEC MARK USER/ SWITCH ORIGINAL
|
||||
# GROUP DEST
|
||||
eth0 10.0.0.0/8,\
|
||||
169.254.0.0/16,\
|
||||
172.16.0.0/12,\
|
||||
192.168.0.0/16
|
23
Shorewall/Samples/two-interfaces/snat
Normal file
23
Shorewall/Samples/two-interfaces/snat
Normal file
@@ -0,0 +1,23 @@
|
||||
#
|
||||
# Shorewall - Sample SNAT/Masqueradee File for two-interface configuration.
|
||||
# Copyright (C) 2006-2016 by the Shorewall Team
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# See the file README.txt for further details.
|
||||
#------------------------------------------------------------------------------
|
||||
# For information about entries in this file, type "man shorewall-snat"
|
||||
#
|
||||
# See http://shorewall.net/manpages/shorewall-snat.html for more information
|
||||
###########################################################################################################################################
|
||||
#ACTION SOURCE DEST PROTO PORT IPSEC MARK USER SWITCH ORIGDEST PROBABILITY
|
||||
#
|
||||
# Rules generated from masq file /home/teastep/shorewall/trunk/Shorewall/Samples/two-interfaces/masq by Shorewall 5.0.13-RC1 - Sat Oct 15 11:41:40 PDT 2016
|
||||
#
|
||||
MASQUERADE 10.0.0.0/8,\
|
||||
169.254.0.0/16,\
|
||||
172.16.0.0/12,\
|
||||
1 92.168.0.0/16 eth0
|
9
Shorewall/configfiles/snat
Normal file
9
Shorewall/configfiles/snat
Normal file
@@ -0,0 +1,9 @@
|
||||
#
|
||||
# Shorewall -- /etc/shorewall/snat
|
||||
#
|
||||
# For information about entries in this file, type "man shorewall-snat"
|
||||
#
|
||||
# See http://shorewall.net/manpages/shorewall-snat.html for more information
|
||||
#
|
||||
###########################################################################################################################################
|
||||
#ACTION SOURCE DEST PROTO PORT IPSEC MARK USER SWITCH ORIGDEST PROBABILITY
|
@@ -696,17 +696,15 @@ if [ -z "$SPARSE" -a ! -f ${DESTDIR}${CONFDIR}/$PRODUCT/maclist ]; then
|
||||
echo "mac list file installed as ${DESTDIR}${CONFDIR}/$PRODUCT/maclist"
|
||||
fi
|
||||
|
||||
if [ -f masq ]; then
|
||||
#
|
||||
# Install the Masq file
|
||||
#
|
||||
run_install $OWNERSHIP -m 0644 masq ${DESTDIR}${SHAREDIR}/$PRODUCT/configfiles
|
||||
run_install $OWNERSHIP -m 0644 masq.annotated ${DESTDIR}${SHAREDIR}/$PRODUCT/configfiles
|
||||
#
|
||||
# Install the SNAT file
|
||||
#
|
||||
run_install $OWNERSHIP -m 0644 snat ${DESTDIR}${SHAREDIR}/$PRODUCT/configfiles
|
||||
run_install $OWNERSHIP -m 0644 snat.annotated ${DESTDIR}${SHAREDIR}/$PRODUCT/configfiles
|
||||
|
||||
if [ -z "$SPARSE" -a ! -f ${DESTDIR}${CONFDIR}/$PRODUCT/masq ]; then
|
||||
run_install $OWNERSHIP -m 0600 masq${suffix} ${DESTDIR}${CONFDIR}/$PRODUCT/masq
|
||||
echo "Masquerade file installed as ${DESTDIR}${CONFDIR}/$PRODUCT/masq"
|
||||
fi
|
||||
if [ -z "$SPARSE" -a ! -f ${DESTDIR}${CONFDIR}/$PRODUCT/snat ]; then
|
||||
run_install $OWNERSHIP -m 0600 snat${suffix} ${DESTDIR}${CONFDIR}/$PRODUCT/snat
|
||||
echo "SNAT file installed as ${DESTDIR}${CONFDIR}/$PRODUCT/snat"
|
||||
fi
|
||||
|
||||
if [ -f arprules ]; then
|
||||
|
@@ -154,6 +154,20 @@
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>nat</option></term>
|
||||
|
||||
<listitem>
|
||||
<para>Added in Shorewall 5.0.13. Specifies that this action is
|
||||
to be used in <ulink
|
||||
url="shorewall-snat.html">shorewall-snat(5)</ulink> rather
|
||||
than <ulink
|
||||
url="shorewall-rules.html">shorewall-rules(5)</ulink>. The
|
||||
<option>mangle</option> and <option>nat</option> options are
|
||||
mutually exclusive.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>noinline</option></term>
|
||||
|
||||
|
@@ -25,8 +25,10 @@
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
|
||||
<para>Use this file to define dynamic NAT (Masquerading) and to define
|
||||
Source NAT (SNAT).</para>
|
||||
<para>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 <ulink url="shorewall-snat.html">shorewall-snat</ulink>(5) which was
|
||||
introduced in Shorewall 5.0.14.</para>
|
||||
|
||||
<warning>
|
||||
<para>The entries in this file are order-sensitive. The first entry that
|
||||
@@ -162,7 +164,7 @@
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">ADDRESS</emphasis> (Optional) - [<emphasis
|
||||
role="bold">-</emphasis>|<emphasis
|
||||
role="bold">NONAT</emphasis>|[<emphasis>address-or-address-range</emphasis>[,<emphasis>address-or-address-range</emphasis>]...][:<emphasis>lowport</emphasis><emphasis
|
||||
role="bold">NONAT</emphasis>|[<emphasis>address-or-address-range</emphasis>][:<emphasis>lowport</emphasis><emphasis
|
||||
role="bold">-</emphasis><emphasis>highport</emphasis>][<emphasis
|
||||
role="bold">:random</emphasis>][:persistent]|<emphasis
|
||||
role="bold">detect</emphasis>|<emphasis
|
||||
@@ -682,7 +684,7 @@
|
||||
#INTERFACE SOURCE ADDRESS ...
|
||||
eth0 192.168.1.0/24 1.1.1.1 ; mark=1:C
|
||||
eth0 192.168.1.0/24 1.1.1.3 ; mark=2:C
|
||||
eth0 192.168.1.0/24 1.1.1.4 ; mark=3:C</programlisting>
|
||||
eth0 192.168.1.0/24 1.1.1.9 ; mark=3:C</programlisting>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
743
Shorewall/manpages/shorewall-snat.xml
Normal file
743
Shorewall/manpages/shorewall-snat.xml
Normal file
@@ -0,0 +1,743 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<refentry>
|
||||
<refmeta>
|
||||
<refentrytitle>shorewall-snat</refentrytitle>
|
||||
|
||||
<manvolnum>5</manvolnum>
|
||||
|
||||
<refmiscinfo>Configuration Files</refmiscinfo>
|
||||
</refmeta>
|
||||
|
||||
<refnamediv>
|
||||
<refname>snat</refname>
|
||||
|
||||
<refpurpose>Shorewall SNAT/Masquerade definition file</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsynopsisdiv>
|
||||
<cmdsynopsis>
|
||||
<command>/etc/shorewall/snat</command>
|
||||
</cmdsynopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
|
||||
<para>This file is used to define dynamic NAT (Masquerading) and to define
|
||||
Source NAT (SNAT). It superseded <ulink
|
||||
url="shorewall-masq.html">shorewall-masq</ulink>(5) in Shorewall
|
||||
5.0.14.</para>
|
||||
|
||||
<warning>
|
||||
<para>The entries in this file are order-sensitive. The first entry that
|
||||
matches a particular connection will be the one that is used.</para>
|
||||
</warning>
|
||||
|
||||
<warning>
|
||||
<para>If you have more than one ISP link, adding entries to this file
|
||||
will <emphasis role="bold">not</emphasis> force connections to go out
|
||||
through a particular link. You must use entries in <ulink
|
||||
url="/manpages/shorewall-rtrules.html">shorewall-rtrules</ulink>(5) or
|
||||
PREROUTING entries in <ulink
|
||||
url="/manpages/shorewall-mangle.html">shorewall-mangle</ulink>(5) to do
|
||||
that.</para>
|
||||
</warning>
|
||||
|
||||
<para>The columns in the file are as follows.</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">ACTION</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>Defines the type of rule to generate. Choices are:</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><emphasis
|
||||
role="bold">MASQUERADE[+]</emphasis>[([<replaceable>lowport</replaceable>-<replaceable>highport</replaceable>][<option>random</option>])]</term>
|
||||
|
||||
<listitem>
|
||||
<para>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
|
||||
<replaceable>lowport</replaceable>-<replaceable>highport</replaceable>
|
||||
is given, that port range will be used to assign a source
|
||||
port. If option <option>random</option> 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's static
|
||||
address.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis
|
||||
role="bold">SNAT[+]</emphasis>([<emphasis>address-or-address-range</emphasis>][:<emphasis>lowport</emphasis><emphasis
|
||||
role="bold">-</emphasis><emphasis>highport</emphasis>][<emphasis
|
||||
role="bold">:random</emphasis>][:<option>persistent</option>]|<emphasis
|
||||
role="bold">detect</emphasis>|</term>
|
||||
|
||||
<listitem>
|
||||
<para>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 <ulink
|
||||
url="/manpages/shorewall.conf.html">shorewall.conf</ulink>(5)
|
||||
then Shorewall will automatically add this address to the
|
||||
INTERFACE named in the first column.</para>
|
||||
|
||||
<para>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
|
||||
<emphasis>first.ip.in.range</emphasis>-<emphasis>last.ip.in.range</emphasis>.
|
||||
You may follow the port range with<emphasis role="bold">
|
||||
:random</emphasis> in which case assignment of ports from the
|
||||
list will be random. <emphasis role="bold">random</emphasis>
|
||||
may also be specified by itself in this column in which case
|
||||
random local port assignments are made for the outgoing
|
||||
connections.</para>
|
||||
|
||||
<para>Example: 206.124.146.177-206.124.146.180</para>
|
||||
|
||||
<para>You may follow the port range (or <emphasis
|
||||
role="bold">:random</emphasis>) with <emphasis
|
||||
role="bold">:persistent</emphasis>. 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.</para>
|
||||
|
||||
<para>You may also use the special value
|
||||
<option>detect</option> which causes Shorewall to determine
|
||||
the IP addresses configured on the interface named in the DEST
|
||||
column and substitute them in this column.</para>
|
||||
|
||||
<para>Finally, you may also specify a comma-separated list of
|
||||
ranges and/or addresses in this column.</para>
|
||||
|
||||
<para>DNS Names names are not allowed.</para>
|
||||
|
||||
<para>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
|
||||
<emphasis>lowport</emphasis>-<emphasis>highport</emphasis>. If
|
||||
this is done, you must specify "tcp", "udp", "dccp" or "stcp"
|
||||
in the PROTO column.</para>
|
||||
|
||||
<para>Examples:</para>
|
||||
|
||||
<programlisting> 192.0.2.4:5000-6000
|
||||
:4000-5000</programlisting>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">CONTINUE</emphasis>[+]</term>
|
||||
|
||||
<listitem>
|
||||
<para>Causes matching packets to be exempted from any
|
||||
following rules in the file.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis
|
||||
role="bold"><replaceable>action</replaceable></emphasis>[+][(<replaceable>parameter</replaceable>,...)]</term>
|
||||
|
||||
<listitem>
|
||||
<para>where <replaceable>action</replaceable> is an action
|
||||
declared in <ulink
|
||||
url="shorewall-actions.html">shorewall-actions(5)</ulink> with
|
||||
the <option>nat</option> option. See <ulink
|
||||
url="/Actions.html">www.shorewall.net/Actions.html</ulink> for
|
||||
further information.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
||||
<para>Normally Masq/SNAT rules are evaluated after those for
|
||||
one-to-one NAT (defined in <ulink
|
||||
url="/manpages/shorewall-nat.html">shorewall-nat</ulink>(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 <ulink
|
||||
url="/manpages/shorewall-nat.html">shorewall-nat</ulink>(5).</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">SOURCE</emphasis> (Optional) -
|
||||
[<emphasis>interface</emphasis>|<emphasis>address</emphasis>[<emphasis
|
||||
role="bold">,</emphasis><emphasis>address</emphasis>][<emphasis>exclusion</emphasis>]]</term>
|
||||
|
||||
<listitem>
|
||||
<para>Set of hosts that you wish to masquerade. You can specify this
|
||||
as an <emphasis>address</emphasis> (net or host) or as an
|
||||
<emphasis>interface</emphasis> (use of an
|
||||
<emphasis>interface</emphasis> 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).</para>
|
||||
|
||||
<para>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.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">DEST</emphasis> - {[<emphasis
|
||||
role="bold">+</emphasis>]<emphasis>interface</emphasis>[<emphasis
|
||||
role="bold">:</emphasis>[<emphasis>digit</emphasis>]][<emphasis
|
||||
role="bold">:</emphasis>[<emphasis>dest-address</emphasis>[<emphasis
|
||||
role="bold">,</emphasis><emphasis>dest-address</emphasis>]...[<emphasis>exclusion</emphasis>]]}</term>
|
||||
|
||||
<listitem>
|
||||
<para>Outgoing <emphasis>interface</emphasis>. This is usually your
|
||||
internet interface. If ADD_SNAT_ALIASES=Yes in <ulink
|
||||
url="/manpages/shorewall.conf.html">shorewall.conf</ulink>(5), you
|
||||
may add ":" and a <emphasis>digit</emphasis> 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. <emphasis role="bold">That
|
||||
is the only use for the alias name; it may not appear in any other
|
||||
place in your Shorewall configuration.</emphasis></para>
|
||||
|
||||
<para>Each interface must match an entry in <ulink
|
||||
url="/manpages/shorewall-interfaces.html">shorewall-interfaces</ulink>(5).
|
||||
Shorewall allows loose matches to wildcard entries in <ulink
|
||||
url="/manpages/shorewall-interfaces.html">shorewall-interfaces</ulink>(5).
|
||||
For example, <filename class="devicefile">ppp0</filename> in this
|
||||
file will match a <ulink
|
||||
url="/manpages/shorewall-interfaces.html">shorewall-interfaces</ulink>(5)
|
||||
entry that defines <filename
|
||||
class="devicefile">ppp+</filename>.</para>
|
||||
|
||||
<para>Where <ulink url="/4.4/MultiISP.html#Shared">more that one
|
||||
internet provider share a single interface</ulink>, the provider is
|
||||
specified by including the provider name or number in
|
||||
parentheses:</para>
|
||||
|
||||
<programlisting> eth0(Avvanta)</programlisting>
|
||||
|
||||
<para>In that case, you will want to specify the interface's address
|
||||
for that provider as the SNAT parameter.</para>
|
||||
|
||||
<para>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 <ulink
|
||||
url="/manpages/shorewall-exclusion.html">shorewall-exclusion</ulink>(5))
|
||||
as are ipset names preceded by a plus sign '+';</para>
|
||||
|
||||
<para>If you wish to inhibit the action of ADD_SNAT_ALIASES for this
|
||||
entry then include the ":" but omit the digit:</para>
|
||||
|
||||
<programlisting> eth0(Avvanta):
|
||||
eth2::192.0.2.32/27</programlisting>
|
||||
|
||||
<para>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.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">PROTO</emphasis> (Optional) - {<emphasis
|
||||
role="bold">-</emphasis>|[!]{<emphasis>protocol-name</emphasis>|<emphasis>protocol-number</emphasis>}[,...]|+<replaceable>ipset</replaceable>}</term>
|
||||
|
||||
<listitem>
|
||||
<para>If you wish to restrict this entry to a particular protocol
|
||||
then enter the protocol name (from protocols(5)) or number
|
||||
here.</para>
|
||||
|
||||
<para>Beginning with Shorewall 4.5.12, this column can accept a
|
||||
comma-separated list of protocols.</para>
|
||||
|
||||
<para>Beginning with Shorewall 4.6.0, an
|
||||
<replaceable>ipset</replaceable> name can be specified in this
|
||||
column. This is intended to be used with
|
||||
<firstterm>bitmap:port</firstterm> ipsets.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">PORT</emphasis> (Optional) -
|
||||
{-|[!]<emphasis>port-name-or-number</emphasis>[,<emphasis>port-name-or-number</emphasis>]...|+<replaceable>ipset</replaceable>}</term>
|
||||
|
||||
<listitem>
|
||||
<para>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.</para>
|
||||
|
||||
<para>Port ranges are of the form
|
||||
<emphasis>lowport</emphasis>:<emphasis>highport</emphasis>.</para>
|
||||
|
||||
<para>Beginning with Shorewall 4.6.0, an
|
||||
<replaceable>ipset</replaceable> name can be specified in this
|
||||
column. This is intended to be used with
|
||||
<firstterm>bitmap:port</firstterm> ipsets.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">IPSEC</emphasis> (Optional) -
|
||||
[<emphasis>option</emphasis>[<emphasis
|
||||
role="bold">,</emphasis><emphasis>option</emphasis>]...]</term>
|
||||
|
||||
<listitem>
|
||||
<para>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.</para>
|
||||
|
||||
<para>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.</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><emphasis
|
||||
role="bold">reqid=</emphasis><emphasis>number</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>where <emphasis>number</emphasis> is specified using
|
||||
setkey(8) using the 'unique:<emphasis>number</emphasis> option
|
||||
for the SPD level.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">spi=</emphasis><number></term>
|
||||
|
||||
<listitem>
|
||||
<para>where <emphasis>number</emphasis> is the SPI of the SA
|
||||
used to encrypt/decrypt packets.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">proto=</emphasis><emphasis
|
||||
role="bold">ah</emphasis>|<emphasis
|
||||
role="bold">esp</emphasis>|<emphasis
|
||||
role="bold">ipcomp</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>IPSEC Encapsulation Protocol</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis
|
||||
role="bold">mss=</emphasis><emphasis>number</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>sets the MSS field in TCP packets</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">mode=</emphasis><emphasis
|
||||
role="bold">transport</emphasis>|<emphasis
|
||||
role="bold">tunnel</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>IPSEC mode</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis
|
||||
role="bold">tunnel-src=</emphasis><emphasis>address</emphasis>[/<emphasis>mask</emphasis>]</term>
|
||||
|
||||
<listitem>
|
||||
<para>only available with mode=tunnel</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis
|
||||
role="bold">tunnel-dst=</emphasis><emphasis>address</emphasis>[/<emphasis>mask</emphasis>]</term>
|
||||
|
||||
<listitem>
|
||||
<para>only available with mode=tunnel</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">strict</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>Means that packets must match all rules.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">next</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>Separates rules; can only be used with strict</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">yes</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>When used by itself, causes all traffic that will be
|
||||
encrypted/encapsulated to match the rule.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">MARK</emphasis> - [<emphasis
|
||||
role="bold">!</emphasis>]<emphasis>value</emphasis>[/<emphasis>mask</emphasis>][<emphasis
|
||||
role="bold">:C</emphasis>]</term>
|
||||
|
||||
<listitem>
|
||||
<para>Defines a test on the existing packet or connection mark. The
|
||||
rule will match only if the test returns true.</para>
|
||||
|
||||
<para>If you don't want to define a test but need to specify
|
||||
anything in the following columns, place a "-" in this field.</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>!</term>
|
||||
|
||||
<listitem>
|
||||
<para>Inverts the test (not equal)</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis>value</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>Value of the packet or connection mark.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis>mask</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>A mask to be applied to the mark before testing.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">:C</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>Designates a connection mark. If omitted, the packet
|
||||
mark's value is tested.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">USER</emphasis> (Optional) - [<emphasis
|
||||
role="bold">!</emphasis>][<emphasis>user-name-or-number</emphasis>][<emphasis
|
||||
role="bold">:</emphasis><emphasis>group-name-or-number</emphasis>][<emphasis
|
||||
role="bold">+</emphasis><emphasis>program-name</emphasis>]</term>
|
||||
|
||||
<listitem>
|
||||
<para>This column was formerly labelled USER/GROUP.</para>
|
||||
|
||||
<para>Only locally-generated connections will match if this column
|
||||
is non-empty.</para>
|
||||
|
||||
<para>When this column is non-empty, the rule matches only if the
|
||||
program generating the output is running under the effective
|
||||
<emphasis>user</emphasis> and/or <emphasis>group</emphasis>
|
||||
specified (or is NOT running under that id if "!" is given).</para>
|
||||
|
||||
<para>Examples:</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>joe</term>
|
||||
|
||||
<listitem>
|
||||
<para>program must be run by joe</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>:kids</term>
|
||||
|
||||
<listitem>
|
||||
<para>program must be run by a member of the 'kids'
|
||||
group</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>!:kids</term>
|
||||
|
||||
<listitem>
|
||||
<para>program must not be run by a member of the 'kids'
|
||||
group</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>+upnpd</term>
|
||||
|
||||
<listitem>
|
||||
<para>#program named upnpd</para>
|
||||
|
||||
<important>
|
||||
<para>The ability to specify a program name was removed from
|
||||
Netfilter in kernel version 2.6.14.</para>
|
||||
</important>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">SWITCH -
|
||||
[!]<replaceable>switch-name</replaceable>[={0|1}]</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>Added in Shorewall 4.5.1 and allows enabling and disabling the
|
||||
rule without requiring <command>shorewall restart</command>.</para>
|
||||
|
||||
<para>The rule is enabled if the value stored in
|
||||
<filename>/proc/net/nf_condition/<replaceable>switch-name</replaceable></filename>
|
||||
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.</para>
|
||||
|
||||
<para>Within the <replaceable>switch-name</replaceable>, '@0' and
|
||||
'@{0}' are replaced by the name of the chain to which the rule is a
|
||||
added. The <replaceable>switch-name</replaceable> (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.</para>
|
||||
|
||||
<para>Switches are normally <emphasis role="bold">off</emphasis>. To
|
||||
turn a switch <emphasis role="bold">on</emphasis>:</para>
|
||||
|
||||
<simplelist>
|
||||
<member><command>echo 1 >
|
||||
/proc/net/nf_condition/<replaceable>switch-name</replaceable></command></member>
|
||||
</simplelist>
|
||||
|
||||
<para>To turn it <emphasis role="bold">off</emphasis> again:</para>
|
||||
|
||||
<simplelist>
|
||||
<member><command>echo 0 >
|
||||
/proc/net/nf_condition/<replaceable>switch-name</replaceable></command></member>
|
||||
</simplelist>
|
||||
|
||||
<para>Switch settings are retained over <command>shorewall
|
||||
restart</command>.</para>
|
||||
|
||||
<para>Beginning with Shorewall 4.5.10, when the
|
||||
<replaceable>switch-name</replaceable> is followed by
|
||||
<option>=0</option> or <option>=1</option>, then the switch is
|
||||
initialized to off or on respectively by the
|
||||
<command>start</command> command. Other commands do not affect the
|
||||
switch setting.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">ORIGDEST</emphasis> - [<emphasis
|
||||
role="bold">-</emphasis>|<emphasis>address</emphasis>[,<emphasis>address</emphasis>]...[<emphasis>exclusion</emphasis>]|<emphasis>exclusion</emphasis>]</term>
|
||||
|
||||
<listitem>
|
||||
<para>(Optional) Added in Shorewall 4.5.6. 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.</para>
|
||||
|
||||
<para>This column was formerly labelled ORIGINAL DEST.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">PROBABILITY</emphasis> -
|
||||
[<replaceable>probability</replaceable>]</term>
|
||||
|
||||
<listitem>
|
||||
<para>Added in Shorewall 5.0.0. When non-empty, requires the
|
||||
<firstterm>Statistics Match</firstterm> capability in your kernel
|
||||
and ip6tables and causes the rule to match randomly but with the
|
||||
given <replaceable>probability</replaceable>. The
|
||||
<replaceable>probability</replaceable> is a number 0 <
|
||||
<replaceable>probability</replaceable> <= 1 and may be expressed
|
||||
at up to 8 decimal points of precision.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Examples</title>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>Example 1:</term>
|
||||
|
||||
<listitem>
|
||||
<para>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.</para>
|
||||
|
||||
<para>Your entry in the file will be:</para>
|
||||
|
||||
<programlisting> #ACTION SOURCE DEST
|
||||
MASQUERADE 192.168.0.0/24 eth0</programlisting>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>Example 2:</term>
|
||||
|
||||
<listitem>
|
||||
<para>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:</para>
|
||||
|
||||
<programlisting> #ACTION SOURCE DEST
|
||||
MASQUERADE 192.168.0.0/24 eth0
|
||||
MASQUERADE 192.168.1.0/24 eth0</programlisting>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>Example 3:</term>
|
||||
|
||||
<listitem>
|
||||
<para>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.</para>
|
||||
|
||||
<programlisting> #ACTION SOURCE DEST
|
||||
SNAT(206.124.146.176) 192.168.1.0/24 eth0:0</programlisting>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>Example 4:</term>
|
||||
|
||||
<listitem>
|
||||
<para>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.</para>
|
||||
|
||||
<programlisting> #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</programlisting>
|
||||
|
||||
<programlisting> #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</programlisting>
|
||||
|
||||
<warning>
|
||||
<para>The order of the above two rules is significant!</para>
|
||||
</warning>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>Example 5:</term>
|
||||
|
||||
<listitem>
|
||||
<para>Connections leaving on eth0 and destined to any host defined
|
||||
in the ipset <emphasis>myset</emphasis> should have the source IP
|
||||
address changed to 206.124.146.177.</para>
|
||||
|
||||
<programlisting> #ACTION SOURCE DEST
|
||||
SNAT(206.124.146.177) - eth0+myset[dst]</programlisting>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>Example 6:</term>
|
||||
|
||||
<listitem>
|
||||
<para>SNAT outgoing connections on eth0 from 192.168.1.0/24 in
|
||||
round-robin fashion between addresses 1.1.1.1, 1.1.1.3, and 1.1.1.9
|
||||
(Shorewall 4.5.9 and later).</para>
|
||||
|
||||
<programlisting>/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 }</programlisting>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>Example 7:</term>
|
||||
|
||||
<listitem>
|
||||
<para>Your eth1 has two public IP addresses: 70.90.191.121 and
|
||||
70.90.191.123. You want to use the iptables statistics match to
|
||||
masquerade outgoing connections evenly between these two
|
||||
addresses.</para>
|
||||
|
||||
<programlisting>/etc/shorewall/snat:
|
||||
|
||||
#ACTION SOURCE DEST
|
||||
SNAT(70.90.191.121) - eth1 { probability=.50 }
|
||||
SNAT(70.90.191.123) - eth1</programlisting>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>FILES</title>
|
||||
|
||||
<para>/etc/shorewall/snat</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>See ALSO</title>
|
||||
|
||||
<para><ulink
|
||||
url="/configuration_file_basics.htm#Pairs">http://www.shorewall.net/configuration_file_basics.htm#Pairs</ulink></para>
|
||||
|
||||
<para>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-mangle(5), shorewall-tos(5),
|
||||
shorewall-tunnels(5), shorewall-zones(5)</para>
|
||||
</refsect1>
|
||||
</refentry>
|
@@ -798,7 +798,7 @@
|
||||
<para>Normally, only packets whose source address matches an
|
||||
entry in the ipset are dropped. If <option>src-dst</option> is
|
||||
included, then packets whose destination address matches an
|
||||
entry in the ipset are also dropped. </para>
|
||||
entry in the ipset are also dropped.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
@@ -920,7 +920,8 @@ net all DROP info</programlisting>then the chain name is 'net-all'
|
||||
an administrative system in directories containing the
|
||||
configurations of remote firewalls. The contents of the variable are
|
||||
the default value for the <replaceable>system</replaceable>
|
||||
parameter to the <command>remote-reload</command> and
|
||||
parameter to the <command>remote-start</command>,
|
||||
<command>remote-reload</command> and
|
||||
<command>remote-restart</command> commands.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -1086,10 +1087,12 @@ net all DROP info</programlisting>then the chain name is 'net-all'
|
||||
|
||||
<para>Beginning with Shorewall 5.0.0, it is no longer necessary to
|
||||
set INLINE_MATCHES=Yes in order to be able to specify your own
|
||||
iptables text in a rule. You may simply preface that text with a
|
||||
pair of semicolons (";;"). If alternate input is also specified in
|
||||
the rule, it should appear before the semicolons and may be
|
||||
separated from normal column input by a single semicolon.</para>
|
||||
iptables text in a rule and INLINE_MATCHES=Yes is deprecated.
|
||||
Beginning with 5.0.0, you may simply preface your text with a pair
|
||||
of semicolons (";;"). If alternate input is also specified in the
|
||||
rule, it should appear before the semicolons and may be separated
|
||||
from normal column input by a single semicolon or enclosed in curly
|
||||
braces ("{....}").</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
9
Shorewall6/configfiles/snat
Normal file
9
Shorewall6/configfiles/snat
Normal file
@@ -0,0 +1,9 @@
|
||||
#
|
||||
# Shorewall6 -- /etc/shorewall6/snat
|
||||
#
|
||||
# For information about entries in this file, type "man shorewall6-snat"
|
||||
#
|
||||
# See http://shorewall.net/manpages6/shorewall6-snat.html for more information
|
||||
#
|
||||
###########################################################################################################################################
|
||||
#ACTION SOURCE DEST PROTO PORT IPSEC MARK USER SWITCH ORIGDEST PROBABILITY
|
@@ -125,7 +125,7 @@
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">ADDRESS</emphasis> (Optional) - [<emphasis
|
||||
role="bold">-</emphasis>|<emphasis
|
||||
role="bold">NONAT</emphasis>|[<emphasis>address-or-address-range</emphasis>[,<emphasis>address-or-address-range</emphasis>]...][:<emphasis>lowport</emphasis><emphasis
|
||||
role="bold">NONAT</emphasis>|[<emphasis>address-or-address-range</emphasis>][:<emphasis>lowport</emphasis><emphasis
|
||||
role="bold">-</emphasis><emphasis>highport</emphasis>][<emphasis
|
||||
role="bold">:random</emphasis>][:persistent]|<emphasis
|
||||
role="bold">detect</emphasis>|<emphasis
|
||||
@@ -551,8 +551,8 @@
|
||||
<programlisting>/etc/shorewall/masq:
|
||||
|
||||
#INTERFACE SOURCE ADDRESS
|
||||
INLINE(sit1) 0.0.0.0/0 2001:470:a:227::1 ; -m statistic --mode random --probability 0.50
|
||||
sit1 0.0.0.0/0 2001:470:a:227::2
|
||||
INLINE(sit1) ::/0 2001:470:a:227::1 ; -m statistic --mode random --probability 0.50
|
||||
sit1 ::/0 2001:470:a:227::2
|
||||
</programlisting>
|
||||
|
||||
<para>If INLINE_MATCHES=Yes in <ulink
|
||||
@@ -562,9 +562,8 @@
|
||||
<programlisting>/etc/shorewall/masq:
|
||||
|
||||
#INTERFACE SOURCE ADDRESS
|
||||
sit1 0.0.0.0/0 2001:470:a:227::1 ; -m statistic --mode random --probability 0.50
|
||||
sit1 0.0.0.0/0 2001:470:a:227::2
|
||||
</programlisting>
|
||||
sit1 ::/0 2001:470:a:227::1 ; -m statistic --mode random --probability 0.50
|
||||
sit1 ::/0 2001:470:a:227::2</programlisting>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
615
Shorewall6/manpages/shorewall6-snat.xml
Normal file
615
Shorewall6/manpages/shorewall6-snat.xml
Normal file
@@ -0,0 +1,615 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
|
||||
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
|
||||
<refentry>
|
||||
<refmeta>
|
||||
<refentrytitle>shorewall6-masq</refentrytitle>
|
||||
|
||||
<manvolnum>5</manvolnum>
|
||||
|
||||
<refmiscinfo>Configuration Files</refmiscinfo>
|
||||
</refmeta>
|
||||
|
||||
<refnamediv>
|
||||
<refname>snat</refname>
|
||||
|
||||
<refpurpose>Shorewall6 SNAT/Masquerade definition file</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsynopsisdiv>
|
||||
<cmdsynopsis>
|
||||
<command>/etc/shorewall6/snat</command>
|
||||
</cmdsynopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
|
||||
<para>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 <ulink url="shorewall6-snat.html">shorewall6-snat</ulink>(5) which was
|
||||
introduced in Shorewall 5.0.14.</para>
|
||||
|
||||
<warning>
|
||||
<para>The entries in this file are order-sensitive. The first entry that
|
||||
matches a particular connection will be the one that is used.</para>
|
||||
</warning>
|
||||
|
||||
<warning>
|
||||
<para>If you have more than one ISP link, adding entries to this file
|
||||
will <emphasis role="bold">not</emphasis> force connections to go out
|
||||
through a particular link. You must use entries in <ulink
|
||||
url="/manpages6/shorewall6-rtrules.html">shorewall6-rtrules</ulink>(5)
|
||||
or PREROUTING entries in <ulink
|
||||
url="/manpages6/shorewall6-tcrules.html">shorewall-tcrules</ulink>(5) to
|
||||
do that.</para>
|
||||
</warning>
|
||||
|
||||
<para>The columns in the file are as follows.</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">ACTION</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>Defines the type of rule to generate. Choices are:</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><emphasis
|
||||
role="bold">MASQUERADE</emphasis>[+][([<replaceable>lowport</replaceable>-<replaceable>highport</replaceable>][<option>random</option>])]</term>
|
||||
|
||||
<listitem>
|
||||
<para>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
|
||||
<replaceable>lowport</replaceable>-<replaceable>highport</replaceable>
|
||||
is given, that port range will be used to assign a source
|
||||
port. If option <option>random</option> 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's static
|
||||
address.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis
|
||||
role="bold">SNAT</emphasis>[+]([<emphasis>address-or-address-range</emphasis>][:<emphasis>lowport</emphasis><emphasis
|
||||
role="bold">-</emphasis><emphasis>highport</emphasis>][<emphasis
|
||||
role="bold">:random</emphasis>][:<option>persistent</option>]|<emphasis
|
||||
role="bold">detect</emphasis>|</term>
|
||||
|
||||
<listitem>
|
||||
<para>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 <ulink
|
||||
url="shorewall6.conf.html">shorewall6.conf</ulink>(5) then
|
||||
Shorewall will automatically add this address to the INTERFACE
|
||||
named in the first column.</para>
|
||||
|
||||
<para>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
|
||||
<emphasis>first.ip.in.range</emphasis>-<emphasis>last.ip.in.range</emphasis>.
|
||||
You may follow the port range with<emphasis role="bold">
|
||||
:random</emphasis> in which case assignment of ports from the
|
||||
list will be random. <emphasis role="bold">random</emphasis>
|
||||
may also be specified by itself in this column in which case
|
||||
random local port assignments are made for the outgoing
|
||||
connections.</para>
|
||||
|
||||
<para>Example: 206.124.146.177-206.124.146.180</para>
|
||||
|
||||
<para>You may follow the port range (or <emphasis
|
||||
role="bold">:random</emphasis>) with <emphasis
|
||||
role="bold">:persistent</emphasis>. 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.</para>
|
||||
|
||||
<para>You may also use the special value
|
||||
<option>detect</option> which causes Shorewall to determine
|
||||
the IP addresses configured on the interface named in the DEST
|
||||
column and substitute them in this column.</para>
|
||||
|
||||
<para>Finally, you may also specify a comma-separated list of
|
||||
ranges and/or addresses in this column.</para>
|
||||
|
||||
<para>DNS Names names are not allowed.</para>
|
||||
|
||||
<para>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
|
||||
<emphasis>lowport</emphasis>-<emphasis>highport</emphasis>. If
|
||||
this is done, you must specify "tcp", "udp", "dccp" or "stcp"
|
||||
in the PROTO column.</para>
|
||||
|
||||
<para>Example:</para>
|
||||
|
||||
<programlisting> [2001:470:a:787::2]:5000-6000</programlisting>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>CONTINUE[+]</term>
|
||||
|
||||
<listitem>
|
||||
<para>Causes matching packets to be exempted from any
|
||||
following rules in the file.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis
|
||||
role="bold"><replaceable>action</replaceable></emphasis>[+][(<replaceable>parameter</replaceable>,...)]</term>
|
||||
|
||||
<listitem>
|
||||
<para>where <replaceable>action</replaceable> is an action
|
||||
declared in <ulink
|
||||
url="shorewall6-actions.html">shorewall6-actions(5)</ulink>
|
||||
with the <option>nat</option> option. See <ulink
|
||||
url="/Actions.html">www.shorewall.net/Actions.html</ulink> for
|
||||
further information.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
||||
<para>Normally Masq/SNAT rules are evaluated after those for
|
||||
one-to-one NAT (defined in <ulink
|
||||
url="/manpages6/shorewall6-nat.html">shorewall6-nat</ulink>(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 <ulink
|
||||
url="/manpages6/shorewall6-nat.html">shorewall6-nat</ulink>(5).</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">SOURCE</emphasis> (Optional) -
|
||||
[<emphasis>interface</emphasis>|<emphasis>address</emphasis>[<emphasis
|
||||
role="bold">,</emphasis><emphasis>address</emphasis>][<emphasis>exclusion</emphasis>]]</term>
|
||||
|
||||
<listitem>
|
||||
<para>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.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">DEST</emphasis> -
|
||||
{<emphasis>interface</emphasis>|[<emphasis
|
||||
role="bold">:</emphasis>[<emphasis>dest-address</emphasis>[<emphasis
|
||||
role="bold">,</emphasis><emphasis>dest-address</emphasis>]...[<emphasis>exclusion</emphasis>]]|?COMMENT}</term>
|
||||
|
||||
<listitem>
|
||||
<para>Outgoing <emphasis>interface</emphasis>. This is usually your
|
||||
internet interface.</para>
|
||||
|
||||
<para>The <replaceable>interface</replaceable> must match an entry
|
||||
in <ulink
|
||||
url="/manpages6/shorewall6-interfaces.html">shorewall6-interfaces</ulink>(5).
|
||||
Shorewall allows loose matches to wildcard entries in <ulink
|
||||
url="/manpages6/shorewall6-interfaces.html">shorewall6-interfaces</ulink>(5).
|
||||
For example, <filename class="devicefile">ppp0</filename> in this
|
||||
file will match a <ulink
|
||||
url="/manpages6/shorewall6-interfaces.html">shorewall6-interfaces</ulink>(5)
|
||||
entry that defines <filename
|
||||
class="devicefile">ppp+</filename>.</para>
|
||||
|
||||
<para>Where <ulink url="/4.4/MultiISP.html#Shared">more that one
|
||||
internet provider share a single interface</ulink>, the provider is
|
||||
specified by including the provider name or number in
|
||||
parentheses:</para>
|
||||
|
||||
<programlisting> eth0(Avvanta)</programlisting>
|
||||
|
||||
<para>In that case, you will want to specify the interface's address
|
||||
for that provider as the SNAT parameter.</para>
|
||||
|
||||
<para>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 <ulink
|
||||
url="/manpages6/shorewall6-exclusion.html">shorewall6-exclusion</ulink>(5))
|
||||
as are ipset names preceded by a plus sign '+'.</para>
|
||||
|
||||
<para>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.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">PROTO</emphasis> (Optional) - {<emphasis
|
||||
role="bold">-</emphasis>|[!]{<emphasis>protocol-name</emphasis>|<emphasis>protocol-number</emphasis>}[,...]|+<replaceable>ipset</replaceable>}</term>
|
||||
|
||||
<listitem>
|
||||
<para>If you wish to restrict this entry to a particular protocol
|
||||
then enter the protocol name (from protocols(5)) or number
|
||||
here.</para>
|
||||
|
||||
<para>Beginning with Shorewall 4.5.12, this column can accept a
|
||||
comma-separated list of protocols.</para>
|
||||
|
||||
<para>Beginning with Shorewall 4.6.0, an
|
||||
<replaceable>ipset</replaceable> name can be specified in this
|
||||
column. This is intended to be used with
|
||||
<firstterm>bitmap:port</firstterm> ipsets.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">DPORT</emphasis> (Optional) -
|
||||
{-|[!]<emphasis>port-name-or-number</emphasis>[,<emphasis>port-name-or-number</emphasis>]...|+<replaceable>ipset</replaceable>}</term>
|
||||
|
||||
<listitem>
|
||||
<para>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.</para>
|
||||
|
||||
<para>Port ranges are of the form
|
||||
<emphasis>lowport</emphasis>:<emphasis>highport</emphasis>.</para>
|
||||
|
||||
<para>Beginning with Shorewall 4.6.0, an
|
||||
<replaceable>ipset</replaceable> name can be specified in this
|
||||
column. This is intended to be used with
|
||||
<firstterm>bitmap:port</firstterm> ipsets.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">IPSEC</emphasis> (Optional) -
|
||||
[<emphasis>option</emphasis>[<emphasis
|
||||
role="bold">,</emphasis><emphasis>option</emphasis>]...]</term>
|
||||
|
||||
<listitem>
|
||||
<para>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.</para>
|
||||
|
||||
<para>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.</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><emphasis
|
||||
role="bold">reqid=</emphasis><emphasis>number</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>where <emphasis>number</emphasis> is specified using
|
||||
setkey(8) using the 'unique:<emphasis>number</emphasis> option
|
||||
for the SPD level.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">spi=</emphasis><number></term>
|
||||
|
||||
<listitem>
|
||||
<para>where <emphasis>number</emphasis> is the SPI of the SA
|
||||
used to encrypt/decrypt packets.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">proto=</emphasis><emphasis
|
||||
role="bold">ah</emphasis>|<emphasis
|
||||
role="bold">esp</emphasis>|<emphasis
|
||||
role="bold">ipcomp</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>IPSEC Encapsulation Protocol</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis
|
||||
role="bold">mss=</emphasis><emphasis>number</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>sets the MSS field in TCP packets</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">mode=</emphasis><emphasis
|
||||
role="bold">transport</emphasis>|<emphasis
|
||||
role="bold">tunnel</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>IPSEC mode</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis
|
||||
role="bold">tunnel-src=</emphasis><emphasis>address</emphasis>[/<emphasis>mask</emphasis>]</term>
|
||||
|
||||
<listitem>
|
||||
<para>only available with mode=tunnel</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis
|
||||
role="bold">tunnel-dst=</emphasis><emphasis>address</emphasis>[/<emphasis>mask</emphasis>]</term>
|
||||
|
||||
<listitem>
|
||||
<para>only available with mode=tunnel</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">strict</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>Means that packets must match all rules.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">next</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>Separates rules; can only be used with strict</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">yes</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>When used by itself, causes all traffic that will be
|
||||
encrypted/encapsulated to match the rule.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">MARK</emphasis> - [<emphasis
|
||||
role="bold">!</emphasis>]<emphasis>value</emphasis>[/<emphasis>mask</emphasis>][<emphasis
|
||||
role="bold">:C</emphasis>]</term>
|
||||
|
||||
<listitem>
|
||||
<para>Defines a test on the existing packet or connection mark. The
|
||||
rule will match only if the test returns true.</para>
|
||||
|
||||
<para>If you don't want to define a test but need to specify
|
||||
anything in the following columns, place a "-" in this field.</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>!</term>
|
||||
|
||||
<listitem>
|
||||
<para>Inverts the test (not equal)</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis>value</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>Value of the packet or connection mark.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis>mask</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>A mask to be applied to the mark before testing.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">:C</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>Designates a connection mark. If omitted, the packet
|
||||
mark's value is tested.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">USER</emphasis> (Optional) - [<emphasis
|
||||
role="bold">!</emphasis>][<emphasis>user-name-or-number</emphasis>][<emphasis
|
||||
role="bold">:</emphasis><emphasis>group-name-or-number</emphasis>][<emphasis
|
||||
role="bold">+</emphasis><emphasis>program-name</emphasis>]</term>
|
||||
|
||||
<listitem>
|
||||
<para>Only locally-generated connections will match if this column
|
||||
is non-empty.</para>
|
||||
|
||||
<para>When this column is non-empty, the rule matches only if the
|
||||
program generating the output is running under the effective
|
||||
<emphasis>user</emphasis> and/or <emphasis>group</emphasis>
|
||||
specified (or is NOT running under that id if "!" is given).</para>
|
||||
|
||||
<para>Examples:</para>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>joe</term>
|
||||
|
||||
<listitem>
|
||||
<para>program must be run by joe</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>:kids</term>
|
||||
|
||||
<listitem>
|
||||
<para>program must be run by a member of the 'kids'
|
||||
group</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>!:kids</term>
|
||||
|
||||
<listitem>
|
||||
<para>program must not be run by a member of the 'kids'
|
||||
group</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>+upnpd</term>
|
||||
|
||||
<listitem>
|
||||
<para>#program named upnpd</para>
|
||||
|
||||
<important>
|
||||
<para>The ability to specify a program name was removed from
|
||||
Netfilter in kernel version 2.6.14.</para>
|
||||
</important>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">SWITCH -
|
||||
[!]<replaceable>switch-name</replaceable>[={0|1}]</emphasis></term>
|
||||
|
||||
<listitem>
|
||||
<para>Added in Shorewall 4.5.1 and allows enabling and disabling the
|
||||
rule without requiring <command>shorewall restart</command>.</para>
|
||||
|
||||
<para>The rule is enabled if the value stored in
|
||||
<filename>/proc/net/nf_condition/<replaceable>switch-name</replaceable></filename>
|
||||
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.</para>
|
||||
|
||||
<para>Within the <replaceable>switch-name</replaceable>, '@0' and
|
||||
'@{0}' are replaced by the name of the chain to which the rule is a
|
||||
added. The <replaceable>switch-name</replaceable> (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.</para>
|
||||
|
||||
<para>Switches are normally <emphasis role="bold">off</emphasis>. To
|
||||
turn a switch <emphasis role="bold">on</emphasis>:</para>
|
||||
|
||||
<simplelist>
|
||||
<member><command>echo 1 >
|
||||
/proc/net/nf_condition/<replaceable>switch-name</replaceable></command></member>
|
||||
</simplelist>
|
||||
|
||||
<para>To turn it <emphasis role="bold">off</emphasis> again:</para>
|
||||
|
||||
<simplelist>
|
||||
<member><command>echo 0 >
|
||||
/proc/net/nf_condition/<replaceable>switch-name</replaceable></command></member>
|
||||
</simplelist>
|
||||
|
||||
<para>Switch settings are retained over <command>shorewall
|
||||
restart</command>.</para>
|
||||
|
||||
<para>Beginning with Shorewall 4.5.10, when the
|
||||
<replaceable>switch-name</replaceable> is followed by
|
||||
<option>=0</option> or <option>=1</option>, then the switch is
|
||||
initialized to off or on respectively by the
|
||||
<command>start</command> command. Other commands do not affect the
|
||||
switch setting.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">ORIGDEST</emphasis> - [<emphasis
|
||||
role="bold">-</emphasis>|<emphasis>address</emphasis>[,<emphasis>address</emphasis>]...[<emphasis>exclusion</emphasis>]|<emphasis>exclusion</emphasis>]</term>
|
||||
|
||||
<listitem>
|
||||
<para>(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.</para>
|
||||
|
||||
<para>This column was formerly labelled ORIGINAL DEST.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><emphasis role="bold">PROBABILITY</emphasis> -
|
||||
[<replaceable>probability</replaceable>]</term>
|
||||
|
||||
<listitem>
|
||||
<para>Added in Shorewall 5.0.0. When non-empty, requires the
|
||||
<firstterm>Statistics Match</firstterm> capability in your kernel
|
||||
and ip6tables and causes the rule to match randomly but with the
|
||||
given <replaceable>probability</replaceable>. The
|
||||
<replaceable>probability</replaceable> is a number 0 <
|
||||
<replaceable>probability</replaceable> <= 1 and may be expressed
|
||||
at up to 8 decimal points of precision.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Examples</title>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>Example 1:</term>
|
||||
|
||||
<listitem>
|
||||
<para>You have a simple 'masquerading' 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</para>
|
||||
|
||||
<para>Your entry in the file will be:</para>
|
||||
|
||||
<programlisting> #ACTION SOURCE DEST
|
||||
MASQUERADE 2001:470:b:787::0/64 eth0</programlisting>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>Example 2:</term>
|
||||
|
||||
<listitem>
|
||||
<para>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.</para>
|
||||
|
||||
<programlisting>/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</programlisting>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>FILES</title>
|
||||
|
||||
<para>/etc/shorewall6/snat</para>
|
||||
</refsect1>
|
||||
</refentry>
|
@@ -647,7 +647,7 @@
|
||||
is SW_DBL6 and the default log level is <option>none</option> (no
|
||||
logging). if <option>ipset-only</option> is given, then chain-based
|
||||
dynamic blacklisting is disabled just as if DYNAMIC_BLACKLISTING=No
|
||||
had been specified. </para>
|
||||
had been specified.</para>
|
||||
|
||||
<para>Possible <replaceable>option</replaceable>s are:</para>
|
||||
|
||||
@@ -781,7 +781,8 @@ net all DROP info</programlisting>then the chain name is 'net-all'
|
||||
an administrative system in directories containing the
|
||||
configurations of remote firewalls. The contents of the variable are
|
||||
the default value for the <replaceable>system</replaceable>
|
||||
parameter to the <command>remote-reload</command> and
|
||||
parameter to the <command>remote-start</command>,
|
||||
<command>remote-reload</command> and
|
||||
<command>remote-restart</command> commands.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -919,13 +920,13 @@ net all DROP info</programlisting>then the chain name is 'net-all'
|
||||
|
||||
<listitem>
|
||||
<para>Added in Shorewall 4.6.0. Traditionally in <ulink
|
||||
url="/manpages6/shorewall6-rules.html">shorewall6-rules(5)</ulink>,
|
||||
url="/manpages6/shorewall6-rules.html">shorewall6-rules</ulink>(5),
|
||||
a semicolon separates column-oriented specifications on the left
|
||||
from <ulink url="/configuration_file_basics.htm#Pairs">alternative
|
||||
specificaitons</ulink> on the right.. When INLINE_MATCHES=Yes is
|
||||
specified, the specifications on the right are interpreted as if
|
||||
INLINE had been specified in the ACTION column. This also applies to
|
||||
<ulink url="shorewall6-masq.html">shorewall6-masq(5)</ulink> and
|
||||
<ulink url="shorewall-masq.html">shorewall6-masq(5)</ulink> and
|
||||
<ulink url="shorewall6-mangle.html">shorewall6-mangle(5</ulink>)
|
||||
which also support INLINE. If not specified or if specified as the
|
||||
empty value, the value 'No' is assumed for backward
|
||||
@@ -933,10 +934,12 @@ net all DROP info</programlisting>then the chain name is 'net-all'
|
||||
|
||||
<para>Beginning with Shorewall 5.0.0, it is no longer necessary to
|
||||
set INLINE_MATCHES=Yes in order to be able to specify your own
|
||||
iptables text in a rule. You may simply preface that text with a
|
||||
pair of semicolons (";;"). If alternate input is also specified in
|
||||
the rule, it should appear before the semicolons and may be
|
||||
separated from normal column input by a single semicolon.</para>
|
||||
iptables text in a rule and INLINE_MATCHES=Yes is deprecated.
|
||||
Beginning with 5.0.0, you may simply preface your text with a pair
|
||||
of semicolons (";;"). If alternate input is also specified in the
|
||||
rule, it should appear before the semicolons and may be separated
|
||||
from normal column input by a single semicolon or enclosed in curly
|
||||
braces ("{....}").</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
145
docs/Actions.xml
145
docs/Actions.xml
@@ -417,8 +417,8 @@ REDIRECT net - tcp 80 - 1.2.3.4</programlisting>
|
||||
|
||||
<para>To create a mangle action, follow the steps in the preceding
|
||||
section, but use the
|
||||
<filename>/usr/share/shorewall/action.mangletemplate</filename> file.
|
||||
</para>
|
||||
<filename>/usr/share/shorewall/action.mangletemplate</filename>
|
||||
file.</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
@@ -1011,4 +1011,145 @@ add_rule $chainref, '-j ACCEPT';
|
||||
1; </programlisting>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Mangle Actions</title>
|
||||
|
||||
<para>Beginning with Shorewall 5.0.7, actions are supported in <ulink
|
||||
url="manpages/shorewall-mangle.html">shorewall-mangle(5)</ulink>. Like
|
||||
actions used out of <ulink
|
||||
url="manpages/shorewall-rules.html">shorewall-rules(5)</ulink>, they must
|
||||
be declared in <ulink
|
||||
url="manpages/shorewall-actions.html">shorewall-actions(5)</ulink>. These
|
||||
<firstterm>mangle actions</firstterm> must have the
|
||||
<option>mangle</option> option specified on <ulink
|
||||
url="manpages/shorewall-actions.html">shorewall-actions(5)</ulink>. Like
|
||||
the actions described in the preceding sections, mangle actions are
|
||||
defined in a files with names of the form
|
||||
action.<replaceable>action</replaceable>. Rules in those files have the
|
||||
same format as those in <ulink
|
||||
url="manpages/shorewall-mangle.html">shorewall-mangle(5)</ulink> with the
|
||||
restriction that chain designators (:P, :F, etc.) are not permitted in the
|
||||
ACTION column. Both regular and inline actions are supported.</para>
|
||||
|
||||
<para>Inline Example</para>
|
||||
|
||||
<para><filename>/etc/shorewall/actions</filename>:</para>
|
||||
|
||||
<programlisting>#ACTION OPTIONS
|
||||
Divert inline,mangle # TProxy Rules
|
||||
</programlisting>
|
||||
|
||||
<para><filename>/etc/shorewall/action.Divert</filename>:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO DPORT SPORT
|
||||
DIVERT COMB_IF - tcp - 80
|
||||
DIVERT COMC_IF - tcp - 80
|
||||
DIVERT DMZ_IF 172.20.1.0/24 tcp - 80
|
||||
</programlisting>
|
||||
|
||||
<para><filename>/etc/shorewall/mangle</filename>:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO DPORT SPORT
|
||||
Divert</programlisting>
|
||||
|
||||
<para>More efficient way to do this:</para>
|
||||
|
||||
<para><filename>/etc/shorewall/actions</filename>:</para>
|
||||
|
||||
<programlisting>#ACTION OPTIONS
|
||||
Divert inline # TProxy Rules
|
||||
</programlisting>
|
||||
|
||||
<para><filename>/etc/shorewall/action.Divert</filename>:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO DPORT SPORT
|
||||
DIVERT COMB_IF -
|
||||
DIVERT COMC_IF -
|
||||
DIVERT DMZ_IF 172.20.1.0/24
|
||||
</programlisting>
|
||||
|
||||
<para><filename>/etc/shorewall/mangle</filename>:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO DPORT SPORT
|
||||
Divert - - tcp - 80</programlisting>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>SNAT Actions</title>
|
||||
|
||||
<para>Beginning with Shorewall 5.0.14, actions are supported in <ulink
|
||||
url="manpages/shorewall-snat.html">shorewall-snat(5</ulink>); that file
|
||||
supercedes <ulink
|
||||
url="manpages/shorewall-masq.html">shorewall-masq(5)</ulink> which is
|
||||
still supported. The shorewall update command will convert a
|
||||
<filename>masq</filename> file into the equivalent
|
||||
<filename>snat</filename> file. Like actions used out of <ulink
|
||||
url="manpages/shorewall-rules.html">shorewall-rules(5)</ulink>,
|
||||
<firstterm>SNAT actions</firstterm> must be declared in <ulink
|
||||
url="manpages/shorewall-actions.html">shorewall-actions(5)</ulink>. These
|
||||
<firstterm>mangle actions</firstterm> must have the <option>nat</option>
|
||||
option specified on <ulink
|
||||
url="manpages/shorewall-actions.html">shorewall-actions(5)</ulink>. Like
|
||||
the actions described in the preceding sections, SNAT actions are defined
|
||||
in a files with names of the form
|
||||
action.<replaceable>action</replaceable>. Rules in those files have the
|
||||
same format as those in <ulink
|
||||
url="manpages/shorewall-snat.html">shorewall-snat(5)</ulink> with two
|
||||
restrictions:</para>
|
||||
|
||||
<orderedlist>
|
||||
<listitem>
|
||||
<para>The plus sign ("+") is not allowed in the ACTION column, so all
|
||||
rules in the action will either be pre-nat or post-nat depending on
|
||||
whether '+' was present in the action's invocation.</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>Interface names are not allowed in the DEST column, so all rules
|
||||
in the action will apply to the interface specified in the action's
|
||||
invocation.</para>
|
||||
</listitem>
|
||||
</orderedlist>
|
||||
|
||||
<para>Both regular and inline actions are supported.</para>
|
||||
|
||||
<para>Example:</para>
|
||||
|
||||
<para><filename>/etc/shorewall/actions</filename>:</para>
|
||||
|
||||
<programlisting>#ACTION OPTIONS
|
||||
custEPTs nat,inline</programlisting>
|
||||
|
||||
<para><filename>/etc/shorewall/action.custEPTs</filename>:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT($GW_IP) { proto=udp port=1146 }
|
||||
SNAT($GW_IP) { proto=tcp port=1156,7221,21000 }
|
||||
</programlisting>
|
||||
|
||||
<para><filename>/etc/shorewall/snat</filename>:</para>
|
||||
|
||||
<programlisting>ACTION SOURCE DEST PROTO PORT
|
||||
custEPTs { source=$EPT_LIST dest=$IF_NET:$EPT_SERVERS }</programlisting>
|
||||
|
||||
<para>More effeciently:</para>
|
||||
|
||||
<para><filename>/etc/shorewall/actions</filename>:</para>
|
||||
|
||||
<programlisting>#ACTION OPTIONS
|
||||
custEPTs nat</programlisting>
|
||||
|
||||
<para><filename>/etc/shorewall/action.custEPTs</filename>:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT($GW_IP) { proto=udp port=1146 }
|
||||
SNAT($GW_IP) { proto=tcp port=1156,7221,21000 }
|
||||
</programlisting>
|
||||
|
||||
<para><filename>/etc/shorewall/snat</filename>:</para>
|
||||
|
||||
<programlisting>ACTION SOURCE DEST PROTO PORT
|
||||
custEPT { source=$EPT_LIST dest=$IF_NET:$EPT_SERVERS }</programlisting>
|
||||
</section>
|
||||
</article>
|
||||
|
@@ -106,8 +106,17 @@
|
||||
url="Install.htm#idp8774904608">configure scripts included with Shorewall
|
||||
Core</ulink>.</para>
|
||||
|
||||
<important>
|
||||
<para>Since Shorewall 4.5.2, each of these directories is now
|
||||
relocatable using the <ulink url="Install.htm#idp8774904608">configure
|
||||
scripts included with Shorewall Core</ulink>. These scripts set shell
|
||||
variables in the shorewallrc file which is normally installed in
|
||||
/usr/share/shorewall/. The name of the variable is included in
|
||||
parentheses in the section headings below.</para>
|
||||
</important>
|
||||
|
||||
<section id="sbin">
|
||||
<title>/sbin</title>
|
||||
<title>/sbin ($SBINDIR)</title>
|
||||
|
||||
<para>The <filename>/sbin/shorewall</filename> shell program is used to
|
||||
interact with Shorewall. See <ulink
|
||||
@@ -115,7 +124,7 @@
|
||||
</section>
|
||||
|
||||
<section id="share-shorewall">
|
||||
<title>/usr/share/shorewall</title>
|
||||
<title>/usr/share/shorewall (${SHAREDIR}/shorewall)</title>
|
||||
|
||||
<para>The bulk of Shorewall is installed here.</para>
|
||||
|
||||
@@ -220,22 +229,28 @@
|
||||
</section>
|
||||
|
||||
<section id="shorewall">
|
||||
<title>/etc/shorewall</title>
|
||||
<title>/etc/shorewall (${CONFDIR}/shorewall)</title>
|
||||
|
||||
<para>This is where the modifiable IPv4 configuration files are
|
||||
installed.</para>
|
||||
</section>
|
||||
|
||||
<section id="init">
|
||||
<title>/etc/init.d or /etc/rc.d (depends on distribution)</title>
|
||||
<title>/etc/init.d or /etc/rc.d (depends on distribution)
|
||||
($INITDIR)</title>
|
||||
|
||||
<para>An init script is installed here. Depending on the distribution,
|
||||
it is named <filename>shorewall</filename> or
|
||||
<filename>rc.firewall</filename>.</para>
|
||||
<filename>rc.firewall</filename>. Only installed on systems where
|
||||
systemd is not installed.</para>
|
||||
|
||||
<para>When systemd is installed, the Shorewall .service files are
|
||||
installed in the directory specified by the SERVICEDIR variable in
|
||||
<filename>/usr/share/shorewall/shorewallrc</filename>.</para>
|
||||
</section>
|
||||
|
||||
<section id="var">
|
||||
<title>/var/lib/shorewall</title>
|
||||
<title>/var/lib/shorewall (${VARLIB}/shorewall)</title>
|
||||
|
||||
<para>Shorewall doesn't install any files in this directory but rather
|
||||
uses the directory for storing state information. This directory may be
|
||||
@@ -332,7 +347,7 @@
|
||||
<para>Shorewall6 installs its files in a number of directories:</para>
|
||||
|
||||
<section id="sbin6">
|
||||
<title>/sbin</title>
|
||||
<title>/sbin ($SBINDIR)</title>
|
||||
|
||||
<para>The <filename>/sbin/shorewall6</filename> shell program is used to
|
||||
interact with Shorewall6. See <ulink
|
||||
@@ -340,7 +355,7 @@
|
||||
</section>
|
||||
|
||||
<section id="share-shorewall6">
|
||||
<title>/usr/share/shorewall6</title>
|
||||
<title>/usr/share/shorewall6 (${SHAREDIR}/shorewall6)</title>
|
||||
|
||||
<para>The bulk of Shorewall6 is installed here.</para>
|
||||
|
||||
@@ -417,14 +432,28 @@
|
||||
</section>
|
||||
|
||||
<section id="etc-shorewall6">
|
||||
<title>/etc/shorewall6</title>
|
||||
<title>/etc/shorewall6 (${CONFDIR}/</title>
|
||||
|
||||
<para>This is where the modifiable IPv6 configuration files are
|
||||
installed.</para>
|
||||
</section>
|
||||
|
||||
<section id="init">
|
||||
<title>/etc/init.d or /etc/rc.d (depends on distribution)
|
||||
($INITDIR)</title>
|
||||
|
||||
<para>An init script is installed here. Depending on the distribution,
|
||||
it is named <filename>shorewall6</filename> or
|
||||
<filename>rc.firewall</filename>. Only installed on systems where
|
||||
systemd is not installed.</para>
|
||||
|
||||
<para>When systemd is installed, the Shorewall .service files are
|
||||
installed in the directory specified by the SERVICEDIR variable in
|
||||
<filename>/usr/share/shorewall/shorewallrc</filename>.</para>
|
||||
</section>
|
||||
|
||||
<section id="var-shorewall6">
|
||||
<title>/var/lib/shorewall6</title>
|
||||
<title>/var/lib/shorewall6 (${VARLIB}/shorewall6)</title>
|
||||
|
||||
<para>Shorewall6 doesn't install any files in this directory but rather
|
||||
uses the directory for storing state information. This directory may be
|
||||
@@ -514,7 +543,7 @@
|
||||
in the sub-sections that follow.</para>
|
||||
|
||||
<section id="sbin-lite">
|
||||
<title>/sbin</title>
|
||||
<title>/sbin ($SBINDIR_</title>
|
||||
|
||||
<para>The <filename>/sbin/shorewall-lite</filename> shell program is
|
||||
used to interact with Shorewall lite. See <ulink
|
||||
@@ -522,22 +551,28 @@
|
||||
</section>
|
||||
|
||||
<section id="init-lite">
|
||||
<title>/etc/init.d or /etc/rc.d (depends on distribution)</title>
|
||||
<title>/etc/init.d or /etc/rc.d (depends on distribution)
|
||||
($INITDIR)</title>
|
||||
|
||||
<para>An init script is installed here. Depending on the distribution,
|
||||
it is named <filename>shorewall-lite</filename> or
|
||||
<filename>rc.firewall</filename>.</para>
|
||||
<filename>rc.firewall</filename>. Only installed on systems where
|
||||
systemd is not installed.</para>
|
||||
|
||||
<para>When systemd is installed, the Shorewall .service files are
|
||||
installed in the directory specified by the SERVICEDIR variable in
|
||||
<filename>/usr/share/shorewall/shorewallrc</filename>.</para>
|
||||
</section>
|
||||
|
||||
<section id="shorewall-lite">
|
||||
<title>/etc/shorewall-lite</title>
|
||||
<title>/etc/shorewall-lite (${CONFDIR}/shorewall-lite)</title>
|
||||
|
||||
<para>This is where the modifiable configuration files are
|
||||
installed.</para>
|
||||
</section>
|
||||
|
||||
<section id="share-lite">
|
||||
<title>/usr/share/shorewall-lite</title>
|
||||
<title>/usr/share/shorewall-lite (${SHAREDIR}/shorewall-lite)</title>
|
||||
|
||||
<para>The bulk of Shorewall-lite is installed here.</para>
|
||||
|
||||
@@ -586,7 +621,7 @@
|
||||
</section>
|
||||
|
||||
<section id="var-lite">
|
||||
<title>/var/lib/shorewall-lite</title>
|
||||
<title>/var/lib/shorewall-lite (${VARLIB}/shorewall-lite)</title>
|
||||
|
||||
<para>Shorewall-lite doesn't install any files in this directory but
|
||||
rather uses the directory for storing state information. This directory
|
||||
@@ -719,15 +754,29 @@
|
||||
<filename>rc.firewall</filename>.</para>
|
||||
</section>
|
||||
|
||||
<section id="init">
|
||||
<title>/etc/init.d or /etc/rc.d (depends on distribution)
|
||||
($INITDIR)</title>
|
||||
|
||||
<para>An init script is installed here. Depending on the distribution,
|
||||
it is named <filename>shorewall</filename>6-lite or
|
||||
<filename>rc.firewall</filename>. Only installed on systems where
|
||||
systemd is not installed.</para>
|
||||
|
||||
<para>When systemd is installed, the Shorewall .service files are
|
||||
installed in the directory specified by the SERVICEDIR variable in
|
||||
<filename>/usr/share/shorewall/shorewallrc</filename>.</para>
|
||||
</section>
|
||||
|
||||
<section id="etc-shorewall6-lite">
|
||||
<title>/etc/shorewall6-lite</title>
|
||||
<title>/etc/shorewall6-lite (${CONFDIR}/shorewall6-lite)</title>
|
||||
|
||||
<para>This is where the modifiable configuration files are
|
||||
installed.</para>
|
||||
</section>
|
||||
|
||||
<section id="share-lite6">
|
||||
<title>/usr/share/shorewall6-lite</title>
|
||||
<title>/usr/share/shorewall6-lite (${SHAREDIR}/shorewall6-lite)</title>
|
||||
|
||||
<para>The bulk of Shorewall-lite is installed here.</para>
|
||||
|
||||
@@ -776,7 +825,7 @@
|
||||
</section>
|
||||
|
||||
<section id="var-lite6">
|
||||
<title>/var/lib/shorewall6-lite</title>
|
||||
<title>/var/lib/shorewall6-lite (${VARLIB}/shorewall6-lite)</title>
|
||||
|
||||
<para>Shorewall6-lite doesn't install any files in this directory but
|
||||
rather uses the directory for storing state information. This directory
|
||||
|
43
docs/FAQ.xml
43
docs/FAQ.xml
@@ -494,6 +494,12 @@ DNAT net loc:192.168.1.4 tcp 21 - 206.1
|
||||
<filename>/etc/shorewall/masq</filename>:<programlisting>#INTERFACE SOURCE ADDRESS PROTO PORT
|
||||
eth1:192.168.1.4 0.0.0.0/0 192.168.1.1 tcp 21</programlisting></para>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the eqivalent
|
||||
<filename>/etc/shorewall/snat</filename> file is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(192.168.1.1) 0.0.0.0/0 eth1:192.168.1.4 tcp 21</programlisting>
|
||||
|
||||
<para>This rule has the undesirable side effect of making all FTP
|
||||
connections from the net appear to the FTP server as if they
|
||||
originated on the Shorewall system. But it will force the FTP server
|
||||
@@ -531,6 +537,12 @@ net eth0 <emphasis role="bold">routeback</emphasi
|
||||
<para><filename>/etc/shorewall/masq</filename>;<programlisting>#INTERFACE SOURCE ADDRESS PROTO PORT
|
||||
eth0:66.249.93.111 0.0.0.0/0 206.124.146.176 tcp 993</programlisting></para>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
/etc/shorewall/snat file is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(206.124.146.176) 0.0.0.0/0 eth0:66.249.93.111 tcp 993</programlisting>
|
||||
|
||||
<para>and in
|
||||
<filename>/etc/shorewall/shorewall.conf</filename>:</para>
|
||||
|
||||
@@ -718,6 +730,12 @@ loc eth1 <emphasis role="bold">routeback</emphasi
|
||||
<programlisting>#INTERFACE SOURCE ADDRESS PROTO PORT
|
||||
<emphasis role="bold">eth1:192.168.1.5 192.168.1.0/24 192.168.1.254 tcp www</emphasis></programlisting>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the corresponding
|
||||
<filename>/etc/shorewall/snat</filename> file is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
<emphasis role="bold">SNAT(192.168.1.254) 192.168.1.0/24 eth1:192.168.1.5 tcp www</emphasis></programlisting>
|
||||
|
||||
<para>Note: The technique described here is known as
|
||||
<firstterm>hairpinning NAT</firstterm> and is described in section 6
|
||||
of <ulink url="http://www.faqs.org/rfcs/rfc4787.html">RFC
|
||||
@@ -727,6 +745,11 @@ loc eth1 <emphasis role="bold">routeback</emphasi
|
||||
|
||||
<programlisting>#INTERFACE SOURCE ADDRESS PROTO PORT
|
||||
eth1:192.168.1.5 192.168.1.0/24 <emphasis role="bold">130.151.100.69</emphasis> tcp www</programlisting>
|
||||
|
||||
<para>Equivalent <filename>/etc/shorewall/snat</filename>:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(<emphasis role="bold">130.151.100.69</emphasis>) 192.168.1.0/24 eth1:192.168.1.5 tcp www</programlisting>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
@@ -852,6 +875,12 @@ dmz eth2 <emphasis role="bold">routeback</emphasi
|
||||
<programlisting>#INTERFACE SOURCE
|
||||
eth2:192.168.1.2 192.168.2.0/24</programlisting>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
MASQUERADE 192.168.1.0/24 eth2:192.168.1.2 tcp www</programlisting>
|
||||
|
||||
<para>In <filename>/etc/shorewall/nat</filename>, be sure that you
|
||||
have <quote>Yes</quote> in the ALL INTERFACES column.</para>
|
||||
</example>
|
||||
@@ -3191,11 +3220,17 @@ loc $FW ACCEPT</programlisting>
|
||||
|
||||
<programlisting>#INTERFACE SOURCE ADDRESS
|
||||
|
||||
COMMENT DSL Modem
|
||||
?COMMENT DSL Modem
|
||||
|
||||
EXT_IF:172.20.1.2 0.0.0.0/0 172.20.1.254
|
||||
</programlisting>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(172.20.1.254) 0.0.0.0/0 EXT_IF:192.168.1.2 tcp www</programlisting>
|
||||
|
||||
<para><filename>/etc/shorewall/proxyarp</filename>:</para>
|
||||
|
||||
<programlisting>#ADDRESS INTERFACE EXTERNAL HAVEROUTE PERSISTENT
|
||||
@@ -3233,6 +3268,12 @@ COMMENT DSL Modem
|
||||
|
||||
EXT_IF:192.168.1.1 0.0.0.0/0 192.168.1.254
|
||||
</programlisting>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(192.168.1.254) 0.0.0.0/0 EXT_IF:192.168.1.1 tcp www</programlisting>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</section>
|
||||
|
@@ -152,11 +152,13 @@
|
||||
|
||||
<orderedlist>
|
||||
<listitem>
|
||||
<para>In <filename>/etc/shorewall/masq</filename>, traffic that will
|
||||
later be encrypted is exempted from MASQUERADE/SNAT using existing
|
||||
entries. If you want to MASQUERADE/SNAT outgoing traffic that will
|
||||
later be encrypted, you must include the appropriate indication in the
|
||||
new IPSEC column in that file.</para>
|
||||
<para>In <filename>/etc/shorewall/masq</filename>
|
||||
(<filename>/etc/shorewall/snat</filename> when running Shorewall
|
||||
5.0.14 or later), traffic that will later be encrypted is exempted
|
||||
from MASQUERADE/SNAT using existing entries. If you want to
|
||||
MASQUERADE/SNAT outgoing traffic that will later be encrypted, you
|
||||
must include the appropriate indication in the IPSEC column in that
|
||||
file. </para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
|
@@ -774,7 +774,7 @@ fi</programlisting>
|
||||
</section>
|
||||
|
||||
<section id="masq">
|
||||
<title>./etc/shorewall/masq and Multi-ISP</title>
|
||||
<title>./etc/shorewall/masq (/etc/shorewall/snat) and Multi-ISP</title>
|
||||
|
||||
<para>If you masquerade a local network, you will need to add masquerade
|
||||
rules for both external interfaces. Referring to the diagram above, if
|
||||
@@ -786,6 +786,13 @@ fi</programlisting>
|
||||
eth0 0.0.0.0/0 206.124.146.176
|
||||
eth1 0.0.0.0/0 130.252.99.27</programlisting>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(206.124.146.176) 0.0.0.0/0 eth0
|
||||
SNAT(130252.99.27) 0.0.0.0/0 eth1</programlisting>
|
||||
|
||||
<para>If you have a public subnet (for example 206.124.146.176/30)
|
||||
behind your firewall, then use exclusion:</para>
|
||||
|
||||
@@ -793,6 +800,12 @@ eth1 0.0.0.0/0 130.252.99.27</programlisting>
|
||||
eth0 !206.124.146.176/29 206.124.146.176
|
||||
eth1 0.0.0.0/0 130.252.99.27</programlisting>
|
||||
|
||||
<para>The equivalent <filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(206.124.146.176) !206.124.146.176/29 eth0
|
||||
SNAT(130.252.99.27) 0.0.0.0/0 eth1</programlisting>
|
||||
|
||||
<para>Note that exclusion is only used on the interface corresponding to
|
||||
internal subnetwork.</para>
|
||||
|
||||
@@ -801,10 +814,10 @@ eth1 0.0.0.0/0 130.252.99.27</programlisting>
|
||||
contains all of those addresses from being masqueraded.</para>
|
||||
|
||||
<warning>
|
||||
<para>Entries in <filename>/etc/shorewall/masq</filename> have no
|
||||
effect on which ISP a particular connection will be sent through. That
|
||||
is rather the purpose of entries in
|
||||
<filename>/etc/shorewall/mangle</filename> and
|
||||
<para>Entries in <filename>/etc/shorewall/masq</filename>
|
||||
(<filename>/etc/shorewall/snat</filename>) have no effect on which ISP
|
||||
a particular connection will be sent through. That is rather the
|
||||
purpose of entries in <filename>/etc/shorewall/mangle</filename> and
|
||||
<filename>/etc/shorewall/rtrules</filename>.</para>
|
||||
</warning>
|
||||
</section>
|
||||
@@ -830,7 +843,8 @@ Feb 9 17:23:45 gw.ilinx kernel: ll header: 00:a0:24:2a:1f:72:00:13:5f:07:97:05:
|
||||
206.124.146.176. Another gotcha is that the incoming packet has already
|
||||
had the destination IP address changed for DNAT or because the original
|
||||
outgoing connection was altered by an entry in
|
||||
<filename>/etc/shorewall/masq</filename> (SNAT or Masquerade). So the
|
||||
<filename>/etc/shorewall/masq</filename> or
|
||||
<filename>/etc/shorewall/snat</filename> (SNAT or Masquerade). So the
|
||||
destination IP address (206.124.146.176) may not have been the
|
||||
destination IP address in the packet as it was initially
|
||||
received.</para>
|
||||
@@ -960,6 +974,13 @@ net net DROP</programlisting>
|
||||
<programlisting>#INTERFACE SOURCE ADDRESS
|
||||
eth0 0.0.0.0/0 206.124.146.176
|
||||
eth1 0.0.0.0/0 130.252.99.27</programlisting>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(206.124.146.176) 0.0.0.0/0 eth0
|
||||
SNAT(130.252.99.27) 0.0.0.0/0 eth1</programlisting>
|
||||
</section>
|
||||
|
||||
<section id="Applications">
|
||||
@@ -1050,7 +1071,8 @@ DNAT net loc:192.168.1.3 tcp 25 <
|
||||
|
||||
<listitem>
|
||||
<para>For each external interface, you need to add an entry to
|
||||
<filename>/etc/shorewall/masq</filename>.</para>
|
||||
<filename>/etc/shorewall/masq</filename>
|
||||
(<filename>/etc/shorewall/snat</filename>).</para>
|
||||
</listitem>
|
||||
</orderedlist>
|
||||
|
||||
@@ -1066,6 +1088,14 @@ ISP3 3 3 main eth3 16.105.78.254 track,ba
|
||||
eth0 0.0.0.0/0 206.124.146.176
|
||||
eth1 0.0.0.0/0 130.252.99.27
|
||||
eth3 0.0.0.0/0 16.105.78.4</programlisting></para>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(206.124.146.176) 0.0.0.0/0 eth0
|
||||
SNAT(130.252.99.27) 0.0.0.0/0 eth1
|
||||
SNAT(16.105.78.4) 0.0.0.0/0 eth2</programlisting>
|
||||
</section>
|
||||
|
||||
<section id="rtrules">
|
||||
@@ -2498,8 +2528,9 @@ exit 0
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>Entries in <filename>/etc/shorewall/masq</filename> must be
|
||||
qualified by the provider name (or number).</para>
|
||||
<para>Entries in <filename>/etc/shorewall/masq</filename> and
|
||||
<filename>/etc/shorewall/snat</filename> must be qualified by the
|
||||
provider name (or number).</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
|
@@ -349,6 +349,12 @@ loc eth0:192.168.1.0/24 maclist</programlisting>
|
||||
<programlisting>#INTERFACE SOURCE ADDRESS
|
||||
eth0:!192.168.1.0/24 192.168.1.0/24</programlisting>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
MASQUERADE 0.0.0.0/0 eth0:!192.168.1.0/24</programlisting>
|
||||
|
||||
<para>Note that the <emphasis role="bold">maclist</emphasis> option is
|
||||
specified in <filename>/etc/shorewall/interfaces</filename>. This is to
|
||||
help protect your router from unauthorized access by your friends and
|
||||
|
@@ -79,7 +79,8 @@
|
||||
|
||||
<para>Be sure that the internal system(s) (10.1.1.2 and 10.1.1.3 in the
|
||||
above example) is (are) not included in any specification in
|
||||
<filename>/etc/shorewall/masq</filename> or
|
||||
<filename>/etc/shorewall/masq</filename>
|
||||
(<filename>/etc/shorewall/snat</filename>) or
|
||||
<filename>/etc/shorewall/proxyarp</filename>.</para>
|
||||
|
||||
<note>
|
||||
|
@@ -311,9 +311,10 @@
|
||||
|
||||
<listitem>
|
||||
<para>The source IP address may be rewritten according to an entry in
|
||||
the <filename>/etc/shorewall/masq</filename> file. If this is a new
|
||||
connection request, then the rewriting occurs in a
|
||||
<emphasis>nat</emphasis> table chain called <emphasis
|
||||
the <filename>/etc/shorewall/masq</filename> or
|
||||
<filename>/etc/shorewall/snat</filename> file (Shorewall 5.0.14 or
|
||||
later). If this is a new connection request, then the rewriting occurs
|
||||
in a <emphasis>nat</emphasis> table chain called <emphasis
|
||||
role="bold"><emphasis>interface</emphasis>_masq</emphasis> where
|
||||
<emphasis>interface</emphasis> is the interface on which the packet
|
||||
will be sent. For packets that are part of an already established
|
||||
|
@@ -98,7 +98,8 @@
|
||||
|
||||
<para><emphasis role="bold">Be sure that the internal systems
|
||||
(130.242.100.18 and 130.252.100.19 in the above example) are not included
|
||||
in any specification in <filename>/etc/shorewall/masq</filename> or
|
||||
in any specification in <filename>/etc/shorewall/masq</filename>
|
||||
(/etc/shorewall/snat on Shorewall 5.0.14 or later) or
|
||||
<filename>/etc/shorewall/nat</filename>.</emphasis></para>
|
||||
|
||||
<note>
|
||||
|
@@ -200,10 +200,22 @@ DNAT net loc:192.168.1.3:22 tcp 10000 - 20
|
||||
<programlisting>#INTERFACE SUBNET ADDRESS
|
||||
eth0 192.168.1.0/24 206.124.146.178</programlisting>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(206.124.146.178) 0.0.0.0/0 eth0</programlisting>
|
||||
|
||||
<para>Similarly, you want SMTP traffic from local system 192.168.1.22 to
|
||||
have source IP 206.124.146.178:<programlisting>#INTERFACE SUBNET ADDRESS PROTO DPORT
|
||||
eth0 192.168.1.22 206.124.146.178 tcp 25</programlisting></para>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(206.124.146.178) 0.0.0.0/0 eth0 tcp 25</programlisting>
|
||||
|
||||
<para>Shorewall can create the alias (additional address) for you if you
|
||||
set ADD_SNAT_ALIASES=Yes in
|
||||
<filename>/etc/shorewall/shorewall.con</filename>f.</para>
|
||||
@@ -220,16 +232,29 @@ eth0 192.168.1.22 206.124.146.178 tcp 25</progra
|
||||
the INTERFACE column as follows.</para>
|
||||
|
||||
<para><filename>/etc/shorewall/masq</filename><programlisting>#INTERFACE SUBNET ADDRESS
|
||||
eth0:0 192.168.1.0/24 206.124.146.178</programlisting>Shorewall
|
||||
can also set up SNAT to round-robin over a range of IP addresses. To do
|
||||
that, you specify a range of IP addresses in the ADDRESS column. If you
|
||||
specify a label in the INTERFACE column, Shorewall will use that label
|
||||
for the first address of the range and will increment the label by one
|
||||
for each subsequent label.</para>
|
||||
eth0:0 192.168.1.0/24 206.124.146.178</programlisting></para>
|
||||
|
||||
<para><filename>/etc/shorewall/masq</filename><programlisting>#INTERFACE SUBNET ADDRESS
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(206.124.146.178) 192.168.1.0/24 eth0</programlisting>
|
||||
|
||||
<para>Shorewall can also set up SNAT to round-robin over a range of IP
|
||||
addresses. To do that, you specify a range of IP addresses in the
|
||||
ADDRESS column. If you specify a label in the INTERFACE column,
|
||||
Shorewall will use that label for the first address of the range and
|
||||
will increment the label by one for each subsequent label.</para>
|
||||
|
||||
<para><filename>/etc/shorewall/masq</filename><programlisting>#INTERFACE SOURCE ADDRESS
|
||||
eth0:0 192.168.1.0/24 206.124.146.178-206.124.146.180</programlisting></para>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(206.124.146.178-206.24.146.80) 192.168.1.0/24 eth0</programlisting>
|
||||
|
||||
<para>The above would create three IP addresses:</para>
|
||||
|
||||
<programlisting>eth0:0 = 206.124.146.178
|
||||
|
@@ -145,5 +145,11 @@ loc <emphasis role="bold">br0</emphasis> <emphasis
|
||||
|
||||
<programlisting>#INTERFACE SOURCE ADDRESS
|
||||
eth0 10.0.1.0/24 ... # 10.0.1.0/24 is the local network on LAN A and LAN B</programlisting>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
MASQUERADE 10.0.1.0/24 eth0</programlisting>
|
||||
</section>
|
||||
</article>
|
||||
|
@@ -102,12 +102,9 @@
|
||||
<listitem>
|
||||
<para>Your kernel must contain Netfilter physdev match support
|
||||
(CONFIG_IP_NF_MATCH_PHYSDEV=m or CONFIG_IP_NF_MATCH_PHYSDEV=y).
|
||||
Physdev match is standard in the 2.6 kernel series but must be patched
|
||||
into the 2.4 kernels (see <ulink
|
||||
url="http://bridge.sf.net">http://bridge.sf.net</ulink>). Bering and
|
||||
Bering uCLibc users must find and install ipt_physdev.o for their
|
||||
distribution and add <quote>ipt_physdev</quote> to
|
||||
/etc/modules.</para>
|
||||
Physdev match is standard in the 2.6 and later kernel series but must
|
||||
be patched into the 2.4 kernels (see <ulink
|
||||
url="http://bridge.sf.net">http://bridge.sf.net</ulink>).</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
|
@@ -1654,6 +1654,20 @@ SSH(ACCEPT) net:$MYIP $FW
|
||||
<section id="AddressVariables">
|
||||
<title>Address Variables</title>
|
||||
|
||||
<caution>
|
||||
<para>Prior to Shorewall 5.0.14, if you use address variables that refer
|
||||
to an optional interface, the <command>enable</command> command will not
|
||||
change/insert the rules that use the variable. Therefore, to be
|
||||
completely safe, if you use such address variables then you must follow
|
||||
a successful <command>enable</command> command with a
|
||||
<command>reload</command> command.</para>
|
||||
|
||||
<para>Beginning with Shorewall 5.0.14, if a Shorewall-defined address
|
||||
variable's value has changed since the Netfilter ruleset was
|
||||
instantiated, then a successful <command>enable</command> command will
|
||||
automatically reload the ruleset.</para>
|
||||
</caution>
|
||||
|
||||
<para>Given that shell variables are expanded at compile time, there is no
|
||||
way to cause such variables to be expanded at run time. Prior to Shorewall
|
||||
4.4.17, this made it difficult (to impossible) to include dynamic IP
|
||||
@@ -1883,9 +1897,8 @@ SSH(ACCEPT) net:$MYIP $FW
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
||||
<para>If there is no gateway out of the named interface, the nil IP
|
||||
address is used (0.0.0.0 in IPv4 and :: in IPv6). That way, the generated
|
||||
rule will match no packets (or all packets if used with exclusion).</para>
|
||||
<para>If there is no gateway out of the named interface, rules containing
|
||||
the intefaces's run-time gateway variable are omitted.</para>
|
||||
</section>
|
||||
|
||||
<section id="ActionVariables">
|
||||
@@ -2619,6 +2632,13 @@ DNAT net loc:192.168.1.3 tcp <emphasis role="bold">4000:4100<
|
||||
<para>Also, unless otherwise documented, a port range can be preceded by
|
||||
'!' to specify "All ports except those in this range" (e.g.,
|
||||
"!4000:4100").</para>
|
||||
|
||||
<para>Beginning with Shorewall 5.0.14, a hyphen ("-") may also be used to
|
||||
separate the two port numbers; when using service names, the colon must
|
||||
still be used.</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DESTINATION PROTO DPORT
|
||||
DNAT net loc:192.168.1.3 tcp <emphasis role="bold">4000-4100</emphasis></programlisting>
|
||||
</section>
|
||||
|
||||
<section id="Portlists">
|
||||
@@ -2969,8 +2989,8 @@ redirect => 137</programlisting>
|
||||
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 <emphasis
|
||||
role="bold">contiguous</emphasis> option in the example above.
|
||||
</para>
|
||||
role="bold">contiguous</emphasis> option in the example
|
||||
above.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
@@ -13,14 +13,20 @@
|
||||
|
||||
<surname>Eastep</surname>
|
||||
</author>
|
||||
|
||||
<author>
|
||||
<surname>Bill Shirley</surname>
|
||||
</author>
|
||||
</authorgroup>
|
||||
|
||||
<pubdate><?dbtimestamp format="Y/m/d"?></pubdate>
|
||||
|
||||
<copyright>
|
||||
<year>2001 - 2015</year>
|
||||
<year>2001 - 2016</year>
|
||||
|
||||
<holder>Thomas M. Eastep</holder>
|
||||
|
||||
<holder>Bill Shirley</holder>
|
||||
</copyright>
|
||||
|
||||
<legalnotice>
|
||||
@@ -463,9 +469,32 @@ sync=1</programlisting>
|
||||
<para>By setting the LOGTAGONLY option to Yes in <ulink
|
||||
url="manpages/shorewall.conf.html">shorewall.conf(5)</ulink> or <ulink
|
||||
url="manpages6/shorewall6.conf.html">shorewall6.conf(5)</ulink>, the
|
||||
disposition ('DROP' in the above example) will be omitted. See the
|
||||
shorewall[6].conf man page for further information about how
|
||||
LOGTAGONLY=Yes can be used.</para>
|
||||
disposition ('DROP' in the above example) will be omitted. Consider the
|
||||
following rule:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO
|
||||
REJECT(icmp-proto-unreachable):notice:IPv6 loc net 41 # who's using IPv6 tunneling</programlisting>
|
||||
|
||||
<para>This rule generates the following warning at compile time:</para>
|
||||
|
||||
<simplelist>
|
||||
<member>WARNING: Log Prefix shortened to "Shorewall:IPv6:REJECT(icmp-p
|
||||
" /etc/shorewall/rules (line 212)</member>
|
||||
</simplelist>
|
||||
|
||||
<para>and produces the rather ugly prefix "Shorewall:IPv6:REJECT(icmp-p
|
||||
".</para>
|
||||
|
||||
<para>Now consider this similar rule:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO
|
||||
REJECT(icmp-proto-unreachable):notice:IPv6,tunneling loc net 41 # who's using IPv6 tunneling</programlisting>
|
||||
|
||||
<para>With LOGTAGONLY=Yes, no warning is generated and the prefix
|
||||
becomes "Shorewall:IPv6:tunneling:"</para>
|
||||
|
||||
<para>See the shorewall[6].conf man page for further information about
|
||||
how LOGTAGONLY=Yes can be used.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
@@ -479,4 +508,72 @@ sync=1</programlisting>
|
||||
linkend="LogTags">above</link>.</para>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Some Additional Thoughts on Logging (by Bill Shirley)</title>
|
||||
|
||||
<para>As a side note to the LOGTAGONLY example above, i recommend blocking
|
||||
all tunneling because it bypasses the firewall rules:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO DPORT
|
||||
?COMMENT tunneling
|
||||
REJECT(icmp-proto-unreachable):notice:IPv6,tunneling loc net 41 # who's using IPv6 tunneling
|
||||
REJECT(icmp-port-unreachable) loc net tcp,udp teredo
|
||||
REJECT(icmp-port-unreachable) loc net tcp,udp isakmp,ipsec-nat-t</programlisting>
|
||||
|
||||
<para>Here is an example of logging traffic only once:</para>
|
||||
|
||||
<para><filename>/etc/shorewall/init:</filename></para>
|
||||
|
||||
<programlisting>ipset -exist create IPv4 hash:ip timeout 86400
|
||||
ipset -exist create IPv4-port hash:ip,port timeout 14400</programlisting>
|
||||
|
||||
<para><filename>/etc/shorewall/rules</filename> (at the top):</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO
|
||||
?SECTION NEW
|
||||
# ------------------
|
||||
?COMMENT drop previously flagged
|
||||
DROP net:+IPv4[src] fw
|
||||
DROP net:+IPv4-port[src,dst] fw</programlisting>
|
||||
|
||||
<para>After all the rules have been checked, at the bottom of
|
||||
<filename>/etc/shorewall/rules</filename>:</para>
|
||||
|
||||
<programlisting># =============================================================================
|
||||
# =============================== H@ck0rz =====================================
|
||||
# =============================================================================
|
||||
?COMMENT dont whack myself
|
||||
REJECT:notice inet:$ME_NET fw
|
||||
|
||||
?COMMENT not public
|
||||
ADD(+IPv4-port:src,dst) net fw tcp,udp domain
|
||||
ADD(+IPv4-port:src,dst) net fw tcp ldap,ldaps
|
||||
ADD(+IPv4-port:src,dst) net fw tcp,udp ipp
|
||||
|
||||
?COMMENT H@ck0rz
|
||||
ADD(+IPv4:src) net fw tcp ssh
|
||||
ADD(+IPv4:src) net fw tcp ftp,ftps,sftp,telnet,telnets,exec,login,shell,sunrpc
|
||||
ADD(+IPv4:src) net fw tcp,udp ms-sql-s,ms-sql-m
|
||||
|
||||
?COMMENT drop if added
|
||||
DROP:info:BAN,IPv4 net:+IPv4[src] fw
|
||||
DROP:info:BAN,IPv4-port net:+IPv4-port[src,dst] fw</programlisting>
|
||||
|
||||
<para>One final note: I wanted less firewall messages in /var/log/messages
|
||||
so I added to rsyslog.conf:</para>
|
||||
|
||||
<programlisting>#### RULES #### <-- find this
|
||||
if $msg contains 'Shorewall' then {
|
||||
action(type="omfile" file="/var/log/shorewall.log")
|
||||
# if ($syslogfacility == 0 and $syslogseverity >= 4) then stop # warning
|
||||
# if ($syslogfacility == 0 and $syslogseverity >= 5) then stop # notice
|
||||
if ($syslogfacility == 0 and $syslogseverity >= 6) then stop # info
|
||||
}</programlisting>
|
||||
|
||||
<para> I log at 'notice' log level if I want the message in
|
||||
<filename>/var/log/messages</filename> and everything goes to
|
||||
<filename>/var/log/shorewall.log</filename>. Don't forget to add
|
||||
/var/log/shorewall.log to logrotate. </para>
|
||||
</section>
|
||||
</article>
|
||||
|
@@ -1373,12 +1373,20 @@ Destination Gateway Genmask Flags MSS Window irtt Iface
|
||||
|
||||
<member>SNAT is configured in Shorewall using the <filename><ulink
|
||||
url="manpages/shorewall-masq.html">/etc/shorewall/masq</ulink></filename>
|
||||
file.</member>
|
||||
file (<ulink
|
||||
url="manpages/shorewall-snat.html">/etc/shorewall/snat</ulink> when
|
||||
running Shorewall 5.0.14 or later):</member>
|
||||
</simplelist>
|
||||
|
||||
<programlisting>#INTERFACE SUBNET ADDRESS
|
||||
<programlisting>#INTERFACE SOURCE ADDRESS
|
||||
eth0 192.168.201.0/29 192.0.2.176</programlisting>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(192.0.2.176) 192.168.201.0/24 eth0</programlisting>
|
||||
|
||||
<para>This example used the normal technique of assigning the same
|
||||
public IP address for the firewall external interface and for SNAT. If
|
||||
you wanted to use a different IP address, you would either have to use
|
||||
@@ -1592,9 +1600,15 @@ DNAT net loc:192.168.201.4 tcp www</programlisting>
|
||||
connections. This is done with the following entry in
|
||||
<filename>/etc/shorewall/masq</filename>:</para>
|
||||
|
||||
<programlisting>#INTERFACE SUBNET ADDRESS
|
||||
<programlisting>#INTERFACE SOURCE ADDRESS
|
||||
eth0 192.168.201.0/29 192.0.2.176</programlisting>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(192.0.2.176) 192.168.201.0/24 eth0</programlisting>
|
||||
|
||||
<para><inlinegraphic fileref="images/BD21298_.gif"/></para>
|
||||
|
||||
<para>Suppose now that you have decided to give your daughter her own
|
||||
@@ -1816,6 +1830,12 @@ dmz eth2</programlisting>
|
||||
<programlisting>#INTERFACE SUBNET ADDRESS
|
||||
eth0 192.168.201.0/29 192.0.2.176</programlisting>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> is:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
SNAT(192.02.176) 192.168.201.0/24 eth0</programlisting>
|
||||
|
||||
<para><filename>/etc/shorewall/proxyarp</filename> - DMZ</para>
|
||||
|
||||
<programlisting>#ADDRESS EXTERNAL INTERFACE HAVE ROUTE
|
||||
|
@@ -194,6 +194,17 @@
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces/policy
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces/rules
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces/zones
|
||||
~#</programlisting>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later:</para>
|
||||
|
||||
<programlisting>~# rpm -ql shorewall | fgrep three-interfaces
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces/interfaces
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces/policy
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces/rules
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces/snat
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces/zones
|
||||
~#</programlisting>
|
||||
</listitem>
|
||||
|
||||
@@ -647,16 +658,18 @@ root@lists:~# </programlisting>
|
||||
</listitem>
|
||||
</itemizedlist> In Shorewall, both Masquerading and SNAT are configured
|
||||
with entries in the <filename
|
||||
class="directory">/etc/shorewall/</filename><filename>masq</filename>
|
||||
file.</para>
|
||||
class="directory">/etc/shorewall/</filename><filename>masq</filename> file
|
||||
(<filename>/etc/shorewall/snat</filename> when running Shorewall 5.0.14 or
|
||||
later).</para>
|
||||
|
||||
<para><inlinegraphic fileref="images/BD21298_.gif" format="GIF"/></para>
|
||||
|
||||
<para>If your external firewall interface is <filename
|
||||
class="devicefile">eth0</filename> then you do not need to modify the file
|
||||
provided with the sample. Otherwise, edit <filename
|
||||
class="directory">/etc/shorewall/</filename><filename>masq</filename> and
|
||||
change it to match your configuration.</para>
|
||||
class="directory">/etc/shorewall/</filename><filename>masq</filename> or
|
||||
<filename>/etc/shorewall/snat</filename> and change it to match your
|
||||
configuration.</para>
|
||||
|
||||
<para>If, in spite of all advice to the contrary, you are using this guide
|
||||
and want to use one-to-one NAT or Proxy ARP for your DMZ, you will need to
|
||||
@@ -665,13 +678,23 @@ root@lists:~# </programlisting>
|
||||
|
||||
<para><inlinegraphic fileref="images/BD21298_.gif" format="GIF"/></para>
|
||||
|
||||
<para>If your external IP is static, you can enter it in the third column
|
||||
in the <filename
|
||||
<para>If your external <acronym>IP</acronym> is static then, if you are
|
||||
running Shorewall 5.0.13 or earlier, you can enter our static IP in the
|
||||
third column in the <filename
|
||||
class="directory">/etc/shorewall/</filename><filename>masq</filename>
|
||||
entry if you like although your firewall will work fine if you leave that
|
||||
column empty. Entering your static IP in column 3 makes processing
|
||||
outgoing packets a little more efficient.<graphic align="left"
|
||||
fileref="images/openlogo-nd-25.png"/></para>
|
||||
column empty (Masquerade). Entering your static <acronym>IP</acronym> in
|
||||
column 3 (SNAT) makes the processing of outgoing packets a little more
|
||||
efficient.</para>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the rule in
|
||||
/etc/shorewall/snat must be change from a MASQUERADE rule to an SNAT
|
||||
rule.</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
<emphasis role="bold">SNAT(<replaceable>static-ip</replaceable>)</emphasis> ...</programlisting>
|
||||
|
||||
<graphic align="left" fileref="images/openlogo-nd-25.png"/>
|
||||
|
||||
<para><emphasis role="bold">If you are using the Debian package, please
|
||||
check your <filename>shorewall.conf</filename> file to ensure that the
|
||||
|
@@ -1652,6 +1652,12 @@ DNAT net dmz:192.168.4.5 tcp 80 -
|
||||
<filename>/etc/shorewall/masq</filename>:<programlisting>#INTERFACE SOURCE ADDRESS
|
||||
eth0 192.168.1.0/24 206.124.146.179</programlisting></para>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later, the equivalent
|
||||
<filename>/etc/shorewall/snat</filename> would be:</para>
|
||||
|
||||
<programlisting>#ACTION SOURCE DEST ...
|
||||
SNAT(206.124.146.179) 192.168.1.0/24 eth0</programlisting>
|
||||
|
||||
<para>HTTP response packets corresponding to requests that fall
|
||||
under that rule will have destination IP address 206.124.146.179 and
|
||||
<emphasis role="bold">source</emphasis> port 80.</para>
|
||||
|
@@ -172,6 +172,17 @@
|
||||
/usr/share/doc/packages/shorewall/Samples/two-interfaces/policy
|
||||
/usr/share/doc/packages/shorewall/Samples/two-interfaces/rules
|
||||
/usr/share/doc/packages/shorewall/Samples/two-interfaces/zones
|
||||
~#</programlisting>
|
||||
|
||||
<para>When running Shorewall 5.0.14 or later:</para>
|
||||
|
||||
<programlisting>~# rpm -ql shorewall | fgrep three-interfaces
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces/interfaces
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces/policy
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces/rules
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces/snat
|
||||
/usr/share/doc/packages/shorewall/Samples/three-interfaces/zones
|
||||
~#</programlisting>
|
||||
</listitem>
|
||||
|
||||
@@ -601,7 +612,8 @@ root@lists:~# </programlisting>
|
||||
<emphasis><acronym>SNAT</acronym></emphasis> are configured with entries
|
||||
in the <ulink url="manpages/shorewall-masq.html"><filename
|
||||
class="directory">/etc/shorewall/</filename><filename>masq</filename></ulink>
|
||||
file. You will normally use Masquerading if your external
|
||||
file (<filename>/etc/shorewall/snat</filename> when running Shorewall
|
||||
5.0.14 or later). You will normally use Masquerading if your external
|
||||
<acronym>IP</acronym> is dynamic and <acronym>SNAT</acronym> if the
|
||||
<acronym>IP</acronym> is static.</para>
|
||||
|
||||
@@ -611,25 +623,34 @@ root@lists:~# </programlisting>
|
||||
class="devicefile">eth0</filename>, you do not need to modify the file
|
||||
provided with <link linkend="Concepts">the sample</link>. Otherwise, edit
|
||||
<filename
|
||||
class="directory">/etc/shorewall/</filename><filename>masq</filename> and
|
||||
change the first column to the name of your external interface.</para>
|
||||
class="directory">/etc/shorewall/</filename><filename>masq</filename> or
|
||||
<filename>/etc/shorewall/snat</filename> and change it to match your
|
||||
configuration.</para>
|
||||
|
||||
<para><inlinegraphic fileref="images/BD21298_.gif" format="GIF"/></para>
|
||||
|
||||
<para>If your external <acronym>IP</acronym> is static, you can enter it
|
||||
in the third column in the <filename
|
||||
<para>If your external <acronym>IP</acronym> is static then, if you are
|
||||
running Shorewall 5.0.13 or earlier, you can enter our static IP in the
|
||||
third column in the <filename
|
||||
class="directory">/etc/shorewall/</filename><filename>masq</filename>
|
||||
entry if you like although your firewall will work fine if you leave that
|
||||
column empty (Masquerade). Entering your static <acronym>IP</acronym> in
|
||||
column 3 (SNAT) makes the processing of outgoing packets a little more
|
||||
efficient.</para>
|
||||
|
||||
<graphic align="left" fileref="images/openlogo-nd-25.png"/>
|
||||
<para>When running Shorewall 5.0.14 or later, the rule in
|
||||
/etc/shorewall/snat must be change from a MASQUERADE rule to an SNAT
|
||||
rule.</para>
|
||||
|
||||
<para>I<emphasis role="bold">f you are using the Debian package, please
|
||||
check your <filename>shorewall.conf</filename> file to ensure that the
|
||||
following is set correctly; if it is not, change it
|
||||
appropriately:</emphasis> <itemizedlist spacing="compact">
|
||||
<programlisting>#ACTION SOURCE DEST PROTO PORT
|
||||
<emphasis role="bold">SNAT(<replaceable>static-ip</replaceable>)</emphasis> ...</programlisting>
|
||||
|
||||
<para><graphic align="left"
|
||||
fileref="images/openlogo-nd-25.png"/>I<emphasis role="bold">f you are
|
||||
using the Debian package, please check your
|
||||
<filename>shorewall.conf</filename> file to ensure that the following is
|
||||
set correctly; if it is not, change it appropriately:</emphasis>
|
||||
<itemizedlist spacing="compact">
|
||||
<listitem>
|
||||
<para><varname>IP_FORWARDING=On</varname></para>
|
||||
</listitem>
|
||||
@@ -1253,8 +1274,9 @@ eth0 10.0.0.0/8,\
|
||||
192.168.0.0/16
|
||||
</programlisting>
|
||||
|
||||
<para>then you do <emphasis role="bold">not</emphasis> need to change
|
||||
the contents.</para>
|
||||
<para>or of you are running Shorewall 5.0.14 or later, then you do
|
||||
<emphasis role="bold">not</emphasis> need to change the
|
||||
contents.</para>
|
||||
|
||||
<para>Otherwise, if your Internet interface is <filename
|
||||
class="devicefile">eth0</filename> and your wireless interface is
|
||||
|
Reference in New Issue
Block a user