Eth2 complement (Static templated)
Based on 192.168.3.X lan
First:
http://forums.contribs.org/index.php?topic=14394.msg54824#msg54824Next::::
MASQ Templates
/etc/e-smith/templates-custom/etc/rc.d/init.d/masq/35transproxy
{
my $transproxy = db_get_prop($confref, 'squid', 'Transparent') || "yes";
my $status = db_get_prop($confref, 'squid', 'status') || "disabled";
$OUT = '';
return unless ($transproxy eq "yes" && $status eq "enabled");
# Accept localhost apache access directly
$OUT .= " /sbin/ipchains --append input -p tcp " .
"--destination 127.0.0.1 80 -j ACCEPT\n";
# Accept any accesses to the localIP directly
$OUT .= " /sbin/ipchains --append input -p tcp " .
"--destination $LocalIP 80 -j ACCEPT\n";
if (defined $ExternalIP)
{
# Accept any accesses to the ExternalIP directly
$OUT .= " /sbin/ipchains --append input -p tcp " .
"--destination \$OUTERNET 80 -j ACCEPT\n";
}
#@locals contains all local networks, with the real local network first
my $proxyport = db_get_prop($confref, 'squid', 'TransparentPort') || "3128";
foreach my $network (@locals)
{
# Otherwise, divert port 80 traffic through our proxy
$OUT .= " /sbin/ipchains --append input" .
" -p tcp --source $network --destination 0.0.0.0/0 80" .
" -j REDIRECT $proxyport\n";
}
} /sbin/ipchains --append input -p tcp --source 192.168.3.0/255.255.255.0 --destination 0.0.0.0/0 80 -j REDIRECT 3128
/etc/e-smith/templates-custom/etc/rc.d/init.d/masq/40AllowICMPfromLAN
# Allow outgoing ICMP
{
my $result = "";
my ($network, $broadcast) = esmith::util::computeNetworkAndBroadcast ($LocalIP, $LocalNetmask);
$result .= " /sbin/ipchains --append output -p icmp --source $network/$LocalNetmask --destination 0.0.0.0/0 -j ACCEPT\n";
my %networks;
tie %networks, 'esmith::config', '/home/e-smith/networks';
my $key;
my $value;
while (($key,$value) = each %networks)
{
my ($type, %properties) = split (/\|/, $value, -1);
if ($type eq 'network')
{
$result .= " /sbin/ipchains --append output -p icmp --source $key/$properties{'Mask'} --destination 0.0.0.0/0 -j ACCEPT\n";
}
}
$result;
} /sbin/ipchains --append output -p icmp --source 192.168.3.0/255.255.255.0 --destination 0.0.0.0/0 -j ACCEPT
/etc/e-smith/templates-custom/etc/rc.d/init.d/masq/40AllowTCPAckBitSet
/sbin/ipchains --append forward -s 192.168.0.0/255.255.255.0 -d 192.168.3.0/255.255.255.0 -j ACCEPT
/sbin/ipchains --append forward -s 192.168.3.0/255.255.255.0 -d 192.168.0.0/255.255.255.0 -j ACCEPT
/sbin/ipchains --append input -s 192.168.3.0/255.255.255.0 -d 0/0 -j ACCEPT
/sbin/ipchains --append output -d 192.168.3.0/255.255.255.0 -s 0/0 -j ACCEPT
# Allow packets with ack bit set, they are from an established connection.
/sbin/ipchains --append input ! -y -p tcp -s 0.0.0.0/0 -i $OUTERIF -j ACCEPT
/etc/e-smith/templates-custom/etc/rc.d/init.d/masq/40masqLAN
{
my $result = "";
my ($network, $broadcast) = esmith::util::computeNetworkAndBroadcast ($LocalIP, $LocalNetmask);
$result .= "/sbin/ipchains --append forward -j MASQ --source $network/$LocalNetmask --destination 0.0.0.0/0\n";
my %networks;
tie %networks, 'esmith::config', '/home/e-smith/networks';
my $key;
my $value;
while (($key,$value) = each %networks)
{
my ($type, %properties) = split (/\|/, $value, -1);
if ($type eq 'network')
{
$result .= " /sbin/ipchains --append forward -j MASQ --source $key/$properties{'Mask'} --destination 0.0.0.0/0\n";
}
}
$result;
} /sbin/ipchains --append forward -j MASQ --source 192.168.3.0/255.255.255.0 --destination 0.0.0.0/0
/etc/e-smith/templates-custom/etc/rc.d/init.d/masq/98stop
{
#####STOP FIREWALL####
}
stop)
echo ""
echo -n "Shutting down IP masquerade and firewall rules:"
/sbin/ipchains -P forward DENY
/sbin/ipchains -P output ACCEPT
/sbin/ipchains -P input {
# Set "safe" default mode.
($SystemMode eq "serveronly") ? "ACCEPT" : "DENY"
}
/sbin/ipchains -F input
/sbin/ipchains -F output
/sbin/ipchains -F forward
/sbin/ipchains -F
{
$OUT .= '';
# Allow forwarding of local addresses, as we might be a VPN endpoint
# in serveronly mode
# @locals contains a list of local networks, with the real local
# network first
my @mylocals = @locals;
my $local = shift @mylocals;
$OUT .= " /sbin/ipchains --append forward -s $local" .
" -d $local -j ACCEPT\n";
foreach my $network (@mylocals)
{
$OUT .= " /sbin/ipchains --append forward -s $network" .
" -d $local -j ACCEPT\n";
$OUT .= " /sbin/ipchains --append forward -s $local" .
" -d $network -j ACCEPT\n";
}
} /sbin/ipchains --append forward -s 192.168.3.0/255.255.255.0 -d 192.168.0.0/255.255.255.0 -j ACCEPT
/sbin/ipchains --append forward -s 192.168.0.0/255.255.255.0 -d 192.168.3.0/255.255.255.0 -j ACCEPT
/sbin/ipchains -X
echo " Done!"
echo "" ;;
SQUID Template
/etc/e-smith/templates-custom/etc/squid/squid.conf/20ACL10localhost
{
use esmith::util;
my %networks;
tie %networks, 'esmith::config', '/home/e-smith/networks';
my ($network, $broadcast) =
esmith::util::computeNetworkAndBroadcast ($LocalIP, $LocalNetmask);
my $localAccess = "127.0.0.1 $network/$LocalNetmask";
foreach my $network
(grep { db_get_type(\%networks, $_) eq "network" } db_get(\%networks))
{
my $mask = db_get_prop(\%networks, $network, 'Mask')
|| "255.255.255.0";
$localAccess .= " " .
esmith::util::computeLocalNetworkSpec ($network, $mask);
}
$OUT .= "acl localsrc src $localAccess 192.168.3.0/255.255.255.0\n";
$OUT .= "acl localdst dst $localAccess";
}