Modérateur: modos Ixus
#!/bin/sh
<BR>
<BR>###############################################################################
<BR>#
<BR># Original by Dinesh Kandiah
<BR># Major update by Daniel Carrera
<BR>#
<BR># Copyright (C) 2000-2002 Point Clark Networks
<BR>#
<BR># This program is free software; you can redistribute it and/or
<BR># modify it under the terms of the GNU General Public License
<BR># as published by the Free Software Foundation; either version 2
<BR># of the License, or (at your option) any later version.
<BR>#
<BR># This program is distributed in the hope that it will be useful,
<BR># but WITHOUT ANY WARRANTY; without even the implied warranty of
<BR># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
<BR># GNU General Public License for more details.
<BR>#
<BR># You should have received a copy of the GNU General Public License
<BR># along with this program; if not, write to the Free Software
<BR># Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<BR>#
<BR># Inspired by...
<BR># - Trinity OS
<BR># - Linux Security
<BR># - linux-firewall-tools.com
<BR># - Usenet
<BR>#
<BR>###############################################################################
<BR>
<BR>PATH=/sbin:/bin:/usr/bin
<BR>UNIV="0.0.0.0/0"
<BR>
<BR>#########################################################################
<BR># F U N C T I O N S
<BR>#########################################################################
<BR>
<BR>#########################################################################
<BR>#
<BR># K E R N E L S E T T I N G S
<BR>#
<BR>#########################################################################
<BR>
<BR>setKernel() {
<BR> # Enable IP Forwarding, not really required for standalone mode
<BR> sysctl -w net.ipv4.ip_forward=1 >/dev/null
<BR>
<BR> # Enable TCP SYN Cookie protection:
<BR> sysctl -w net.ipv4.tcp_syncookies=1 >/dev/null
<BR>
<BR> # Enabling dynamic TCP/IP address hacking.
<BR> sysctl -w net.ipv4.ip_dynaddr=1 >/dev/null
<BR>
<BR> # Required for IPsec VPN
<BR> sysctl -w net.ipv4.conf.all.rp_filter=0 >/dev/null
<BR> sysctl -w net.ipv4.conf.eth0.rp_filter=0 >/dev/null 2>/dev/null
<BR> sysctl -w net.ipv4.conf.ppp0.rp_filter=0 >/dev/null 2>/dev/null
<BR>
<BR> # Log spoofed, source-routed, and redirect packets
<BR> sysctl -w net.ipv4.conf.all.log_martians=0 >/dev/null
<BR>
<BR> # Disable ICMP Re-directs
<BR> sysctl -w net.ipv4.conf.all.accept_redirects=0 >/dev/null
<BR> sysctl -w net.ipv4.conf.all.send_redirects=0 >/dev/null
<BR>
<BR> # Ensure that source-routed packets are dropped
<BR> sysctl -w net.ipv4.conf.all.accept_source_route=0 >/dev/null
<BR>
<BR> # Disable ICMP broadcast echo protection
<BR> sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1 >/dev/null
<BR>
<BR> # Enable bad error message protection
<BR> sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1 >/dev/null
<BR>}
<BR>
<BR>
<BR>#########################################################################
<BR>#
<BR># S E T P O L I C Y
<BR>#
<BR>#########################################################################
<BR>
<BR>setPolicy() {
<BR> for TABLE in filter nat mangle; do
<BR> iptables -t $TABLE -F # Flush all previous rules.
<BR> iptables -t $TABLE -X # Delete user-defined chains.
<BR> done
<BR>
<BR> iptables -P INPUT DROP
<BR> iptables -P OUTPUT DROP
<BR> iptables -P FORWARD DROP
<BR>}
<BR>
<BR>
<BR>#########################################################################
<BR>#
<BR># D E F I N E C H A I N S
<BR>#
<BR>#########################################################################
<BR>
<BR>defineChains() {
<BR> # Create a chain for dropping trojans and flooders
<BR> #-------------------------------------------------
<BR> iptables -N drop-trojan
<BR> iptables -t filter -A drop-trojan -j LOG --log-prefix "Drop - trojan-flooder: "
<BR> iptables -t filter -A drop-trojan -j DROP
<BR>
<BR>
<BR> # Create a chain for dropping reserved network IPs
<BR> #-------------------------------------------------
<BR> iptables -N drop-reserved
<BR> iptables -t filter -A drop-reserved -j LOG --log-prefix "Drop - reserved network: "
<BR> iptables -t filter -A drop-reserved -j DROP
<BR>
<BR>
<BR> # Create a chain for dropping services that shouldn't leave the LAN
<BR> #------------------------------------------------------------------
<BR> iptables -N drop-lan
<BR> iptables -t filter -A drop-lan -j LOG --log-prefix "Drop - LAN only: "
<BR> iptables -t filter -A drop-lan -j REJECT
<BR>
<BR>
<BR> # Create a chain for flagging possible Trojans & services leaving the LAN
<BR> #------------------------------------------------------------------------
<BR> iptables -N flag-lan
<BR> iptables -t filter -A flag-lan -j LOG --log-prefix "Flag: "
<BR> iptables -t filter -A flag-lan -j ACCEPT
<BR>
<BR>
<BR> # Create a chain for testing
<BR> #---------------------------
<BR> iptables -N testing
<BR> iptables -t filter -A testing -j LOG --log-prefix "testing: "
<BR> iptables -t filter -A testing -j ACCEPT
<BR>}
<BR>
<BR>
<BR>#########################################################################
<BR>#
<BR># L O A D K E R N E L M O D U L E S
<BR>#
<BR>#########################################################################
<BR>
<BR>loadModules() {
<BR> modprobe ipt_LOG # Add LOG target.
<BR> modprobe ipt_REJECT # Add REJECT target.
<BR> modprobe ipt_MASQUERADE # Add MASQUERADE target.
<BR> modprobe ipt_owner # Allows you to match for the owner.
<BR> modprobe ip_conntrack_ftp # Support connection tracking of FTP.
<BR> modprobe ip_conntrack_irc # Support connection tracking of IRC.
<BR> modprobe ip_nat_ftp # Active FTP
<BR> modprobe ip_nat_irc # IRC stuff
<BR> modprobe ip_conntrack_pptp > /dev/null 2>&1 # PPTP (Office only)
<BR> # ip_nat_pptp module is handled in the default rules section.
<BR>}
<BR>
<BR>
<BR>#########################################################################
<BR>#
<BR># A D H O C R U L E S
<BR>#
<BR>#########################################################################
<BR>#
<BR># We sometimes want to drop in special rules into the firewall.
<BR># For instance, the cc-pptpd RPM will add /etc/rc.d/rc.firewal.pptp
<BR># to add the required ports and protocol to the firewall.
<BR>
<BR>runAdhocRules() {
<BR> for EXTRAS in pptpd pptp squid ipsec; do
<BR> FILENAME=/etc/rc.d/rc.firewall.$EXTRAS
<BR> if [ -x $FILENAME ]; then
<BR> logger -p local6.notice -t firewall "Running ad-hoc rules in $EXTRAS"
<BR> . $FILENAME
<BR> logger -p local6.notice -t firewall "Finished ad-hoc rules in $EXTRAS"
<BR> fi
<BR> done
<BR>}
<BR>
<BR>
<BR>#########################################################################
<BR>#
<BR># R U N D E F A U L T
<BR>#
<BR>#########################################################################
<BR>
<BR>runDefaultRules() {
<BR> # Allow everything on the loopback
<BR> #---------------------------------
<BR> iptables -A INPUT -j ACCEPT -i lo
<BR> iptables -A OUTPUT -j ACCEPT -o lo
<BR>
<BR> # Block IPs that should never show up on our external interface
<BR> #--------------------------------------------------------------
<BR> iptables -A INPUT -j drop-reserved -i $EXTIF -s 127.0.0.0/8
<BR> iptables -A INPUT -j drop-reserved -i $EXTIF -s 1.0.0.0/8
<BR> iptables -A INPUT -j drop-reserved -i $EXTIF -s 23.0.0.0/8
<BR> iptables -A INPUT -j drop-reserved -i $EXTIF -s 31.0.0.0/8
<BR> iptables -A INPUT -j drop-reserved -i $EXTIF -s 96.0.0.0/3
<BR> iptables -A INPUT -j drop-reserved -i $EXTIF -s 128.0.0.0/16
<BR> iptables -A INPUT -j drop-reserved -i $EXTIF -s 128.9.64.26/32
<BR> iptables -A INPUT -j drop-reserved -i $EXTIF -s 128.66.0.0/16
<BR> iptables -A INPUT -j drop-reserved -i $EXTIF -s 191.255.0.0/16
<BR> iptables -A INPUT -j drop-reserved -i $EXTIF -s 197.0.0.0/16
<BR> iptables -A INPUT -j drop-reserved -i $EXTIF -s 201.0.0.0/8
<BR> iptables -A INPUT -j drop-reserved -i $EXTIF -s 223.255.255.0/24
<BR> iptables -A INPUT -j drop-reserved -i $EXTIF -s 240.0.0.0/5
<BR> iptables -A INPUT -j drop-reserved -i $EXTIF -s 248.0.0.0/5
<BR>
<BR> CHKINT1=`echo $EXTIP | cut -d '.' -f1,2`
<BR> CHKINT2=`echo $EXTIP | cut -d '.' -f1`
<BR>
<BR> # - If this box is sitting on an internal network, don't block these IPs
<BR> # - Don't log these as drop-reserved... funny ISPs (@Home) to blame
<BR> if [ "$CHKINT1" != "172.16" ]; then
<BR> iptables -A INPUT -j DROP -i $EXTIF -s 172.16.0.0/12
<BR> fi
<BR> if [ "$CHKINT1" != "192.168" ]; then
<BR> iptables -A INPUT -j DROP -i $EXTIF -s 192.168.0.0/16
<BR> fi
<BR> # Ugh... funny ISPs use 10.x.x.x for DNS servers and other such things
<BR> if [ "$CHKINT2" != "10" ]; then
<BR> iptables -A INPUT -j DROP -i $EXTIF -s 10.0.0.0/8
<BR> fi
<BR>
<BR> # Allow some ICMP (ping)
<BR> #-----------------------
<BR> # ICMP can be used for attacks.. we allow as little as possible.
<BR> # The following are necessary ports we *can't* do without:
<BR> # 0 Needed to ping hosts outside the network.
<BR> # 3 Needed by all networks.
<BR> # 11 Needed by the traceroute program.
<BR> iptables -A INPUT -i $EXTIF -d $EXTIP -j ACCEPT -p icmp --icmp-type 0
<BR> iptables -A INPUT -i $EXTIF -d $EXTIP -j ACCEPT -p icmp --icmp-type 3
<BR> iptables -A INPUT -i $EXTIF -d $EXTIP -j ACCEPT -p icmp --icmp-type 11
<BR> # This allows other hosts to ping you. You should keep this rule.
<BR> iptables -A INPUT -i $EXTIF -d $EXTIP -j ACCEPT -p icmp --icmp-type 8
<BR> iptables -A OUTPUT -j ACCEPT -o $EXTIF -p icmp -s $EXTIP
<BR>
<BR> # Allow DHCP client to respond
<BR> #-----------------------------
<BR> iptables -A INPUT -j ACCEPT -i $EXTIF -p udp -d $EXTIP --dport bootpc --sport bootps
<BR> iptables -A INPUT -j ACCEPT -i $EXTIF -p tcp -d $EXTIP --dport bootpc --sport bootps
<BR> iptables -A OUTPUT -j ACCEPT -o $EXTIF -p tcp -s $EXTIP --sport bootpc --dport bootps
<BR> iptables -A OUTPUT -j ACCEPT -o $EXTIF -p udp -s $EXTIP --sport bootpc --dport bootps
<BR>
<BR> # Allow PPTP protocol and port if server is set to run
<BR> #-----------------------------------------------------
<BR> # note: the ip_nat_pptp module should not be run on a PPTP server!
<BR> PPTPCHK=`chkconfig --list pptpd 2>/dev/null | grep "3:on"`
<BR> if [ -z "$PPTPCHK" ]; then
<BR> modprobe ip_nat_pptp > /dev/null 2>&1 # PPTP (Office only)
<BR> else
<BR> logger -p local6.notice -t firewall "Unloading PPTP connection tracker for PPTP server"
<BR> rmmod ip_nat_pptp > /dev/null 2>&1
<BR>
<BR> logger -p local6.notice -t firewall "Allowing incoming GRE protocol 47 for PPTP server"
<BR> iptables -A INPUT -j ACCEPT -i $EXTIF -p 47
<BR> iptables -A OUTPUT -j ACCEPT -o $EXTIF -p 47
<BR>
<BR> logger -p local6.notice -t firewall "Allowing incoming TCP port 1723 for PPTP server"
<BR> iptables -A INPUT -j ACCEPT -i $EXTIF -p tcp -d $EXTIP --dport 1723
<BR> iptables -A OUTPUT -j ACCEPT -o $EXTIF -p tcp -s $EXTIP --sport 1723
<BR> fi
<BR>}
<BR>
<BR>
<BR>#########################################################################
<BR>#
<BR># I N C O M I N G A L L O W E D
<BR>#
<BR>#########################################################################
<BR>
<BR>runIncomingAllowed() {
<BR> for PORT in $INCOMING_ALLOWED_TCP; do
<BR> logger -p local6.notice -t firewall "Allowing incoming TCP port $PORT"
<BR> iptables -A INPUT -j ACCEPT -i $EXTIF -p tcp -d $EXTIP --dport $PORT
<BR> iptables -A OUTPUT -j ACCEPT -o $EXTIF -p tcp -s $EXTIP --sport $PORT
<BR> done
<BR> for PORT in $INCOMING_ALLOWED_UDP; do
<BR> logger -p local6.notice -t firewall "Allowing incoming UDP port $PORT"
<BR> iptables -A INPUT -j ACCEPT -i $EXTIF -p udp -d $EXTIP --dport $PORT
<BR> iptables -A OUTPUT -j ACCEPT -o $EXTIF -p udp -s $EXTIP --sport $PORT
<BR> done
<BR>}
<BR>
<BR>
<BR>#########################################################################
<BR>#
<BR># O U T G O I N G D E N I E D
<BR>#
<BR>#########################################################################
<BR>
<BR>runOutgoingDenied() {
<BR> for PORT in $OUTGOING_DENIED_TCP; do
<BR> logger -p local6.notice -t firewall "Blocking outgoing TCP port $PORT"
<BR> iptables -A FORWARD -s $LANNETWORK/$LANNETMASK -d 0/0 -p tcp --dport $PORT -j DROP
<BR> #iptables -A PREROUTING -t nat -s $LANNETWORK/$LANNETMASK -d 0/0 -p tcp --dport $PORT -j DROP
<BR> done
<BR> for PORT in $OUTGOING_DENIED_UDP; do
<BR> logger -p local6.notice -t firewall "Blocking outgoing UDP port $PORT"
<BR> iptables -A FORWARD -s $LANNETWORK/$LANNETMASK -d 0/0 -p udp --dport $PORT -j DROP
<BR> #iptables -A PREROUTING -t nat -s $LANNETWORK/$LANNETMASK -d 0/0 -p udp --dport $PORT -j DROP
<BR> done
<BR> for HOST in $OUTGOING_DENIED_HOST; do
<BR> logger -p local6.notice -t firewall "Blocking traffic to $HOST"
<BR> iptables -A FORWARD -s $LANNETWORK/$LANNETMASK -d $HOST -j DROP
<BR> #iptables -A PREROUTING -t nat -s $LANNETWORK/$LANNETMASK -d $HOST -j DROP
<BR> done
<BR> for RULE in $OUTGOING_DENIED_HOST_PORT; do
<BR> HOST=`echo $RULE | cut -d ':' -f1`
<BR> PORT=`echo $RULE | cut -d ':' -f2`
<BR> logger -p local6.notice -t firewall "Blocking traffic to $HOST on port $PORT"
<BR> iptables -A FORWARD -s $LANNETWORK/$LANNETMASK -d $HOST -p tcp --dport $PORT -j DROP
<BR> #iptables -A PREROUTING -t nat -s $LANNETWORK/$LANNETMASK -d $HOST -p tcp --dport $PORT -j DROP
<BR> done
<BR>}
<BR>
<BR>
<BR>#########################################################################
<BR>#
<BR># P O R T F O R W A R D I N G
<BR>#
<BR>#########################################################################
<BR>
<BR>runPortForwardRules() {
<BR> for RULE in $FORWARD_TCP_PORT; do
<BR> SOURCE=`echo $RULE | cut -d '|' -f2`
<BR> DEST=`echo $RULE | cut -d '|' -f3`
<BR> NATTRICK=`echo $DEST | cut -d ':' -f1`
<BR> logger -p local6.notice -t firewall "Port forwarding TCP $SOURCE to $DEST"
<BR> iptables -A PREROUTING -t nat -p tcp -d $EXTIP --dport $SOURCE -j DNAT --to $DEST
<BR> iptables -A POSTROUTING -t nat -p tcp -d $NATTRICK -s $LANNETWORK/$LANNETMASK --dport $SOURCE -j SNAT --to $LANIP
<BR> done
<BR> for RULE in $FORWARD_UDP_PORT; do
<BR> SOURCE=`echo $RULE | cut -d '|' -f2`
<BR> DEST=`echo $RULE | cut -d '|' -f3`
<BR> NATTRICK=`echo $DEST | cut -d ':' -f1`
<BR> logger -p local6.notice -t firewall "Port forwarding UDP $SOURCE to $DEST"
<BR> iptables -A PREROUTING -t nat -p udp -d $EXTIP --dport $SOURCE -j DNAT --to $DEST
<BR> iptables -A POSTROUTING -t nat -p udp -d $NATTRICK -s $LANNETWORK/$LANNETMASK --dport $SOURCE -j SNAT --to $LANIP
<BR> done
<BR>}
<BR>
<BR>
<BR>#########################################################################
<BR>#
<BR># S T A N D A L O N E F I R E W A L L
<BR>#
<BR>#########################################################################
<BR>
<BR>standalone() {
<BR> setKernel
<BR> setPolicy
<BR> loadModules
<BR> defineChains
<BR> runDefaultRules
<BR> runAdhocRules
<BR>
<BR> # User defined rules
<BR> #-------------------
<BR> runIncomingAllowed
<BR>
<BR> # INCOMING RULES
<BR> #================================================================
<BR>
<BR> # Allow high ports
<BR> #-----------------
<BR> iptables -A OUTPUT -o $EXTIF -p tcp -j ACCEPT -s $EXTIP --sport 1024:65535
<BR> iptables -A OUTPUT -o $EXTIF -p udp -j ACCEPT -s $EXTIP --sport 1024:65535
<BR> iptables -A INPUT -j ACCEPT -p udp --dport 1024:65535 -d $EXTIP
<BR> iptables -A INPUT -j ACCEPT -p tcp --dport 1024:65535 -d $EXTIP
<BR> -m state --state ESTABLISHED,RELATED
<BR>
<BR> # Block everything else
<BR> #----------------------
<BR> iptables -A INPUT -j DROP -i $EXTIF -s $UNIV -d $UNIV
<BR> iptables -A OUTPUT -j DROP -o $EXTIF -s $UNIV -d $UNIV
<BR>}
<BR>
<BR>
<BR>#########################################################################
<BR>#
<BR># G A T E W A Y F I R E W A L L
<BR>#
<BR>#########################################################################
<BR>
<BR>gateway() {
<BR> setKernel
<BR> setPolicy
<BR> loadModules
<BR> defineChains
<BR> runDefaultRules
<BR> runAdhocRules
<BR>
<BR> # INCOMING RULES
<BR> #================================================================
<BR>
<BR> # User defined rules
<BR> #-------------------
<BR> runIncomingAllowed
<BR>
<BR> # Allow trusted networks (e.g. the LAN)
<BR> #--------------------------------------
<BR> iptables -A INPUT -j ACCEPT -i $TRUSTEDIF
<BR> iptables -A OUTPUT -j ACCEPT -o $TRUSTEDIF
<BR>
<BR> # Allow high ports
<BR> #-----------------
<BR> iptables -A OUTPUT -o $EXTIF -p tcp -j ACCEPT -s $EXTIP --sport 1024:65535
<BR> iptables -A OUTPUT -o $EXTIF -p udp -j ACCEPT -s $EXTIP --sport 1024:65535
<BR> iptables -A INPUT -j ACCEPT -p udp --dport 1024:65535 -d $EXTIP
<BR> iptables -A INPUT -j ACCEPT -p tcp --dport 1024:65535 -d $EXTIP
<BR> -m state --state ESTABLISHED,RELATED
<BR>
<BR> # Block everything else
<BR> #----------------------
<BR> iptables -A INPUT -j DROP -i $EXTIF -s $UNIV -d $UNIV
<BR> iptables -A OUTPUT -j DROP -o $EXTIF -s $UNIV -d $UNIV
<BR>
<BR>
<BR> # FORWARD RULES
<BR> #================================================================
<BR>
<BR> # User defined rules
<BR> #-------------------
<BR> runPortForwardRules
<BR> runOutgoingDenied
<BR>
<BR> # Block services from leaving the LAN (low port numbers)
<BR> # Snort will log suspicious traffic in high port ranges
<BR> #-------------------------------------------------------
<BR> iptables -A FORWARD -j drop-lan -o $EXTIF -p tcp --dport 111 # RPC stuff
<BR> iptables -A FORWARD -j drop-lan -o $EXTIF -p udp --dport 111 # RPC stuff
<BR> iptables -A FORWARD -j drop-lan -o $EXTIF -p tcp --dport 137:139 # Samba
<BR> iptables -A FORWARD -j drop-lan -o $EXTIF -p udp --dport 137:139 # Samba
<BR> iptables -A FORWARD -j drop-lan -o $EXTIF -p tcp --dport 635 # Mountd
<BR> iptables -A FORWARD -j drop-lan -o $EXTIF -p udp --dport 635 # Mountd
<BR>
<BR> # Enable masquerading
<BR> #--------------------
<BR> iptables -A POSTROUTING -t nat -j MASQUERADE -o $EXTIF
<BR> iptables -A FORWARD -i $TRUSTEDIF -j ACCEPT
<BR> iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
<BR> iptables -A FORWARD -m limit --limit 3/minute --limit-burst 3
<BR> -j LOG --log-level DEBUG --log-prefix "IPT FORWARD packet died: "
<BR>
<BR> # Allow all other forwarding
<BR> #---------------------------
<BR> # You need this rule if you port forward packets to machines behind the gateway.
<BR> iptables -A FORWARD -j ACCEPT
<BR>}
<BR>
<BR>
<BR>#########################################################################
<BR>#
<BR># T R U S T E D G A T E W A Y
<BR>#
<BR>#########################################################################
<BR>
<BR>trustedgateway() {
<BR> setKernel
<BR> loadModules
<BR>
<BR> # First clear everything
<BR> #-----------------------
<BR> for TABLE in filter nat mangle; do
<BR> iptables -t $TABLE -F # Flush all previous rules.
<BR> iptables -t $TABLE -X # Delete user-defined chains.
<BR> done
<BR>
<BR> # Default policies
<BR> #-----------------
<BR> iptables -P INPUT ACCEPT
<BR> iptables -P OUTPUT ACCEPT
<BR> iptables -P FORWARD ACCEPT
<BR>
<BR> # Enable masquerading
<BR> #--------------------
<BR> iptables -A POSTROUTING -t nat -j MASQUERADE -o $EXTIF
<BR>}
<BR>
<BR>
<BR>
<BR>#########################################################################
<BR># M A I N #
<BR>#########################################################################
<BR>
<BR>#########################################################################
<BR>#
<BR># We can determine wheter we have a gateway or standalone machine. This
<BR># will work in the following situations:
<BR>#
<BR># 1) Standalone server
<BR># 2) Gateway with two network cards (Internet + LAN)
<BR># 3) Gateway with three or more network cards (Internet + 2 or more LANs)
<BR>#
<BR># DMZs, trusted gateways, and other network configuration will require
<BR># manual configuration in /etc/firewall.
<BR>
<BR>logger -p local6.notice -t firewall "Starting firewall..."
<BR>
<BR># Configuration file
<BR>#-------------------
<BR>
<BR>[ -f /etc/firewall ] && . /etc/firewall
<BR>
<BR>
<BR># Defaults
<BR>#---------
<BR>
<BR>if [ -z $EXTIF ]; then
<BR> EXTIF=`cat /etc/sysconfig/network | grep GATEWAYDEV | cut -d '=' -f2`
<BR> if [ -z $EXTIF ]; then
<BR> echo "Gateway not defined in /etc/sysconfig/network... using eth0"
<BR> logger -p local6.notice -t firewall "Gateway not set in /etc/sysconfig/network... using eth0"
<BR> EXTIF="eth0"
<BR> fi
<BR>fi
<BR>[ -z $LANIF ] && LANIF="eth1"
<BR>[ -z $DMZIF ] && DMZIF="none"
<BR>[ -z $TRUSTEDIF ] && TRUSTEDIF="! $EXTIF"
<BR>
<BR>
<BR># Sanity check
<BR>#-------------
<BR>
<BR>EXTIP=`ifconfig | grep -A 4 $EXTIF | awk '/inet/{print $2}' | sed -e s/addr://`
<BR>if [ -z $EXTIP ]; then
<BR> echo $EXTIF
<BR> echo $EXTIP
<BR> echo "External IP not available... exiting"
<BR> logger -p local6.notice -t firewall "External IP not available... exiting"
<BR> exit 1
<BR>fi
<BR>
<BR>
<BR># LAN info
<BR>#---------
<BR>
<BR>if [ -f /etc/sysconfig/network-scripts/ifcfg-$LANIF ]; then
<BR>
<BR> LANIP=`grep IPADDR /etc/sysconfig/network-scripts/ifcfg-$LANIF | sed -e s/IPADDR=//i`
<BR> if [ -z $LANIP ]; then
<BR> logger -p local6.notice -t firewall "Could not determine LAN IP on $LANIF... exiting"
<BR> echo "Could not determine LAN IP on $LANIF... exiting"
<BR> exit 1
<BR> fi
<BR>
<BR> LANNETMASK=`grep NETMASK /etc/sysconfig/network-scripts/ifcfg-$LANIF | sed -e s/NETMASK=//i`
<BR> if [ -z $LANNETMASK ]; then
<BR> logger -p local6.notice -t firewall "Could not determine LAN netmask on $LANIF... exiting"
<BR> echo "Could not determine LAN netmask on $LANIF... exiting"
<BR> exit 1
<BR> fi
<BR>
<BR> LANNETWORK=`ipcalc --network $LANIP $LANNETMASK | sed s/NETWORK=//i`
<BR> if [ -z $LANNETWORK ]; then
<BR> logger -p local6.notice -t firewall "Could not determine LAN network on $LANIF... exiting"
<BR> echo "Could not determine LAN network on $LANIF... exiting"
<BR> exit 1
<BR> fi
<BR>
<BR> LANPREFIX=`ipcalc --prefix $LANIP $LANNETMASK | sed s/PREFIX=//i`
<BR> if [ -z $LANPREFIX ]; then
<BR> logger -p local6.notice -t firewall "Could not determine LAN prefix on $LANIF... exiting"
<BR> echo "Could not determine LAN prefix on $LANIF... exiting"
<BR> exit 1
<BR> fi
<BR>
<BR> logger -p local6.notice -t firewall "LAN info - $LANIP/$LANNETMASK on network $LANNETWORK/$LANPREFIX"
<BR> TYPE="gateway"
<BR>fi
<BR>
<BR># DMZ info
<BR>#---------
<BR>
<BR>if [ -f /etc/sysconfig/network-scripts/ifcfg-$DMZIF ]; then
<BR>
<BR> GWIP=`grep GATEWAY /etc/sysconfig/network-scripts/ifcfg-$EXTIF | sed -e s/GATEWAY=//i`
<BR> if [ -z $GWIP ]; then
<BR> logger -p local6.notice -t firewall "Could not determine default route... exiting"
<BR> echo "Could not determine default route... exiting"
<BR> exit 1
<BR> fi
<BR>
<BR> DMZIP=`grep IPADDR /etc/sysconfig/network-scripts/ifcfg-$DMZIF | sed -e s/IPADDR=//i`
<BR> if [ -z $DMZIP ]; then
<BR> logger -p local6.notice -t firewall "Could not determine DMZ IP on $DMZIF... exiting"
<BR> echo "Could not determine DMZ IP on $DMZIF... exiting"
<BR> exit 1
<BR> fi
<BR>
<BR> DMZNETMASK=`grep NETMASK /etc/sysconfig/network-scripts/ifcfg-$DMZIF | sed -e s/NETMASK=//i`
<BR> if [ -z $DMZNETMASK ]; then
<BR> logger -p local6.notice -t firewall "Could not determine DMZ netmask on $DMZIF... exiting"
<BR> echo "Could not determine DMZ netmask on $DMZIF... exiting"
<BR> exit 1
<BR> fi
<BR>
<BR> DMZNETWORK=`ipcalc --network $DMZIP $DMZNETMASK | sed s/NETWORK=//i`
<BR> if [ -z $DMZNETWORK ]; then
<BR> logger -p local6.notice -t firewall "Could not determine DMZ network on $DMZIF... exiting"
<BR> echo "Could not determine DMZ network on $DMZIF... exiting"
<BR> exit 1
<BR> fi
<BR>
<BR> DMZPREFIX=`ipcalc --prefix $DMZIP $DMZNETMASK | sed s/PREFIX=//i`
<BR> if [ -z $DMZPREFIX ]; then
<BR> logger -p local6.notice -t firewall "Could not determine DMZ prefix on $DMZIF... exiting"
<BR> echo "Could not determine DMZ prefix on $DMZIF... exiting"
<BR> exit 1
<BR> fi
<BR>
<BR> logger -p local6.notice -t firewall "DMZ info - $DMZIP/$DMZNETMASK on network $DMZNETWORK/$DMZPREFIX"
<BR> TYPE="dmz"
<BR>fi
<BR>
<BR>if [ ! -z $TRUSTEDGATEWAY ]; then
<BR> TYPE="trustedgateway"
<BR>fi
<BR>
<BR># Start the firewall
<BR>#-------------------
<BR>
<BR>if [ "$TYPE" == "gateway" ]; then
<BR> logger -p local6.notice -t firewall "Using gateway mode"
<BR> gateway
<BR>elif [ "$TYPE" == "dmz" ]; then
<BR> logger -p local6.notice -t firewall "Using DMZ mode"
<BR> gateway
<BR>elif [ "$TYPE" == "trustedgateway" ]; then
<BR> logger -p local6.notice -t firewall "Using trusted gateway mode"
<BR> trustedgateway
<BR>else
<BR> logger -p local6.notice -t firewall "Using standalone mode"
<BR> standalone
<BR>fi
<BR>
<BR>
Utilisateur(s) parcourant actuellement ce forum : Aucun utilisateur inscrit et 1 invité