Página 1 de 2 12 ÚltimoÚltimo
+ Responder ao Tópico



  1. Caros amigos, sou novo por aqui e gostaria de pedir uma ajudinha a vocês.
    Desculpem o post longo, mas é que quero ser o mais claro possível para ajudar vocês a me ajudarem.
    Na empresa onde trabalho, estou configurando um servidor WEB (192.168.20.2) que se localiza na rede interna atrás de um Servidor com Firewall ativada (200.xxx.xxx.xxx).
    A máquina onde está o Apache consegue acessar a Internet normalmente e pingar no Gateway, ou seja, a Firewall permite acesso à Internet normalmente.
    O problema está na necessidade de que as pessoas de fora da rede (pela Internet) possam acessar a página deste servidor WEB. Preciso para isso redirecionar os pedidos que chegarem na porta 80 do Gateway (200.xxx.xxx.xxx) para a porta 80 do Servidor WEB (192.168.20.2).
    Já fiz esse redirecionamente, mas não sei se o fiz corretamente, pois ao tentar acessar o IP do Gateway de uma máquina externa, surge a mensagem:
    Atingido o tempo limite de conexão
    O servidor 200.xxx.xxx.xxx está demorando muito para responder.
    O que poderia ser este problema?
    Abaixo posto o script de Firewall do Gateway da empresa. Ele é enorme, e entendo muito pouco de iptables para encontrar o problema.
    Quem puder ajudar, agradeço muito a imensa paciência e boa vontade!!!
    Última edição por felixleonardo; 26-06-2008 às 09:26.

  2. #!/bin/sh
    #
    # rc.firewall-2.4-stronger
    #
    FWVER=0.74s-4

    # An example of a stronger IPTABLES firewall with IP Masquerade
    # support for 2.4.x kernels.
    #
    # Log:
    # 0.74s - Changed the EXTIP command to work on NON-English distros
    # 0.73s - Added comments in the output section that DHCPd is optional
    # and changed the default settings to disabled
    # 0.72s - Changed the filter from the INTNET to the INTIP to be
    # stateful; moved the command VARs to the top and made the
    # rest of the script to use them
    # 0.70s - Added a disabled examples for allowing internal DHCP
    # and external WWW access to the server
    # 0.63s - Added support for the IRC module
    # 0.62s - Initial version based upon the basic 2.4.x rc.firewall


    echo -e "\nLoading STRONGER rc.firewall - version $FWVER..\n"


    # The location of various iptables and other shell programs
    #
    # If your Linux distribution came with a copy of iptables, most
    # likely it is located in /sbin. If you manually compiled
    # iptables, the default location is in /usr/local/sbin
    #
    # ** Please use the "whereis iptables" command to figure out
    # ** where your copy is and change the path below to reflect
    # ** your setup
    #
    IPTABLES=/sbin/iptables
    #
    LSMOD=/sbin/lsmod
    DEPMOD=/sbin/depmod
    INSMOD=/sbin/insmod
    GREP=/bin/grep
    AWK=/bin/awk
    SED=/bin/sed
    IFCONFIG=/sbin/ifconfig


    #Setting the EXTERNAL and INTERNAL interfaces for the network
    #
    # Each IP Masquerade network needs to have at least one
    # external and one internal network. The external network
    # is where the natting will occur and the internal network
    # should preferably be addressed with a RFC1918 private address
    # scheme.
    #
    # For this example, "eth0" is external and "eth1" is internal"
    #
    # NOTE: If this doesnt EXACTLY fit your configuration, you must
    # change the EXTIF or INTIF variables above. For example:
    #
    # EXTIF="ppp0"
    #
    # if you are a modem user.
    #
    EXTIF="eth0"
    INTIF="eth1"
    echo " External Interface: $EXTIF"
    echo " Internal Interface: $INTIF"
    echo " ---"

    # Specify your Static IP address here or let the script take care of it
    # for you.
    #
    EXTIP="200.xxx.xxx.xxx"
    echo " External IP: $EXTIP"
    echo " ---"


    # Assign the internal TCP/IP network and IP address
    INTNET="192.168.20.0/24"
    INTIP="192.168.20.1/24"
    echo " Internal Network: $INTNET"
    echo " Internal IP: $INTIP"
    echo " ---"




    # Setting a few other local variables
    #
    UNIVERSE="0.0.0.0/0"
    UP_PORTS="1024:"
    D_PORTS=":1024"

    #======================================================================
    #== No editing beyond this line is required for initial MASQ testing ==

    # Need to verify that all modules have all required dependencies
    #
    echo " - Verifying that all kernel modules are ok"
    $DEPMOD -a

    echo -en " Loading kernel modules: "

    # With the new IPTABLES code, the core MASQ functionality is now either
    # modular or compiled into the kernel. This HOWTO shows ALL IPTABLES
    # options as MODULES. If your kernel is compiled correctly, there is
    # NO need to load the kernel modules manually.
    #
    # NOTE: The following items are listed ONLY for informational reasons.
    # There is no reason to manual load these modules unless your
    # kernel is either mis-configured or you intentionally disabled
    # the kernel module autoloader.
    #

    # Upon the commands of starting up IP Masq on the server, the
    # following kernel modules will be automatically loaded:
    #
    # NOTE: Only load the IP MASQ modules you need. All current IP MASQ
    # modules are shown below but are commented out from loading.
    # ===============================================================

    #Load the main body of the IPTABLES module - "ip_tables"
    # - Loaded automatically when the "iptables" command is invoked
    #
    # - Loaded manually to clean up kernel auto-loading timing issues
    #
    echo -en "ip_tables, "
    #
    #Verify the module isn't loaded. If it is, skip it
    #
    if [ -z "` $LSMOD | $GREP ip_tables | $AWK {'print $1'} `" ]; then
    $INSMOD ip_tables
    fi


    #Load the IPTABLES filtering module - "iptable_filter"
    #
    # - Loaded automatically when filter policies are activated


    #Load the stateful connection tracking framework - "ip_conntrack"
    #
    # The conntrack module in itself does nothing without other specific
    # conntrack modules being loaded afterwards such as the "ip_conntrack_ftp"
    # module
    #
    # - This module is loaded automatically when MASQ functionality is
    # enabled
    #
    # - Loaded manually to clean up kernel auto-loading timing issues
    #
    echo -en "ip_conntrack, "
    #
    #Verify the module isn't loaded. If it is, skip it
    #
    if [ -z "` $LSMOD | $GREP ip_conntrack | $AWK {'print $1'} `" ]; then
    $INSMOD ip_conntrack
    fi


    #Load the FTP tracking mechanism for full FTP tracking
    #
    # Enabled by default -- insert a "#" on the next line to deactivate
    #
    echo -e "ip_conntrack_ftp, "
    #
    #Verify the module isn't loaded. If it is, skip it
    #
    if [ -z "` $LSMOD | $GREP ip_conntrack_ftp | $AWK {'print $1'} `" ]; then
    $INSMOD ip_conntrack_ftp
    fi


    #Load the IRC tracking mechanism for full IRC tracking
    #
    # Enabled by default -- insert a "#" on the next line to deactivate
    #
    echo -en " ip_conntrack_irc, "
    #
    #Verify the module isn't loaded. If it is, skip it
    #
    if [ -z "` $LSMOD | $GREP ip_conntrack_irc | $AWK {'print $1'} `" ]; then
    $INSMOD ip_conntrack_irc
    fi


    #Load the general IPTABLES NAT code - "iptable_nat"
    # - Loaded automatically when MASQ functionality is turned on
    #
    # - Loaded manually to clean up kernel auto-loading timing issues
    #
    echo -en "iptable_nat, "
    #
    #Verify the module isn't loaded. If it is, skip it
    #
    if [ -z "` $LSMOD | $GREP iptable_nat | $AWK {'print $1'} `" ]; then
    $INSMOD iptable_nat
    fi


    #Loads the FTP NAT functionality into the core IPTABLES code
    # Required to support non-PASV FTP.
    #
    # Enabled by default -- insert a "#" on the next line to deactivate
    #
    echo -e "ip_nat_ftp"
    #
    #Verify the module isn't loaded. If it is, skip it
    #
    if [ -z "` $LSMOD | $GREP ip_nat_ftp | $AWK {'print $1'} `" ]; then
    $INSMOD ip_nat_ftp
    fi

    echo " ---"

    # Just to be complete, here is a list of the remaining kernel modules
    # and their function. Please note that several modules should be only
    # loaded by the correct master kernel module for proper operation.
    # --------------------------------------------------------------------
    #
    # ipt_mark - this target marks a given packet for future action.
    # This automatically loads the ipt_MARK module
    #
    # ipt_tcpmss - this target allows to manipulate the TCP MSS
    # option for braindead remote firewalls.
    # This automatically loads the ipt_TCPMSS module
    #
    # ipt_limit - this target allows for packets to be limited to
    # to many hits per sec/min/hr
    #
    # ipt_multiport - this match allows for targets within a range
    # of port numbers vs. listing each port individually
    #
    # ipt_state - this match allows to catch packets with various
    # IP and TCP flags set/unset
    #
    # ipt_unclean - this match allows to catch packets that have invalid
    # IP/TCP flags set
    #
    # iptable_filter - this module allows for packets to be DROPped,
    # REJECTed, or LOGged. This module automatically
    # loads the following modules:
    #
    # ipt_LOG - this target allows for packets to be
    # logged
    #
    # ipt_REJECT - this target DROPs the packet and returns
    # a configurable ICMP packet back to the
    # sender.
    #
    # iptable_mangle - this target allows for packets to be manipulated
    # for things like the TCPMSS option, etc.


    #CRITICAL: Enable IP forwarding since it is disabled by default since
    #
    # Redhat Users: you may try changing the options in
    # /etc/sysconfig/network from:
    #
    # FORWARD_IPV4=false
    # to
    # FORWARD_IPV4=true
    #
    echo " Enabling forwarding.."
    echo "1" > /proc/sys/net/ipv4/ip_forward



  3. #############################################################################
    #
    # Enable Stronger IP forwarding and Masquerading
    #
    # NOTE: In IPTABLES speak, IP Masquerading is a form of SourceNAT or SNAT.
    #
    # NOTE #2: The following is an example for an internal LAN address in the
    # 192.168.1.x network with a 255.255.255.0 or a "24" bit subnet
    # mask connecting to the Internet on external interface "eth0".
    # This example will MASQ internal traffic out to the Internet
    # but not allow non-initiated traffic into your internal network.
    #
    #
    # ** Please change the above network numbers, subnet mask, and your
    # *** Internet connection interface name to match your setup
    #

    #Clearing any previous configuration
    #
    # Unless specified, the defaults for INPUT, OUTPUT, and FORWARD to DROP.
    #
    # You CANNOT change this to REJECT as it isn't a vaild setting for a
    # policy. If you want REJECT, you must explictly REJECT at the end
    # of a giving INPUT, OUTPUT, or FORWARD chain
    #
    echo " Clearing any existing rules and setting default policy to DROP.."
    $IPTABLES -P INPUT DROP
    $IPTABLES -F INPUT
    $IPTABLES -P OUTPUT DROP
    $IPTABLES -F OUTPUT
    $IPTABLES -P FORWARD DROP
    $IPTABLES -F FORWARD
    $IPTABLES -F -t nat

    #Not needed and it will only load the unneeded kernel module
    #$IPTABLES -F -t mangle
    #
    # Flush the user chain.. if it exists
    if [ -n "`$IPTABLES -L | $GREP drop-and-log-it`" ]; then
    $IPTABLES -F drop-and-log-it
    fi
    #
    # Delete all User-specified chains
    $IPTABLES -X
    #
    # Reset all IPTABLES counters
    $IPTABLES -Z


    #Configuring specific CHAINS for later use in the ruleset
    #
    # NOTE: Some users prefer to have their firewall silently
    # "DROP" packets while others prefer to use "REJECT"
    # to send ICMP error messages back to the remote
    # machine. The default is "REJECT" but feel free to
    # change this below.
    #
    # NOTE: Without the --log-level set to "info", every single
    # firewall hit will goto ALL vtys. This is a very big
    # pain.
    #
    echo " Creating a DROP chain.."
    $IPTABLES -N drop-and-log-it
    $IPTABLES -A drop-and-log-it -j LOG --log-level info
    $IPTABLES -A drop-and-log-it -j DROP

    echo -e "\n - Loading INPUT rulesets"


    #######################################################################
    # INPUT: Incoming traffic from various interfaces. All rulesets are
    # already flushed and set to a default policy of DROP.
    #

    # loopback interfaces are valid.
    #
    $IPTABLES -A INPUT -i lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT


    # local interface, local machines, going anywhere is valid
    #
    $IPTABLES -A INPUT -i $INTIF -s $INTNET -d $UNIVERSE -j ACCEPT


    # remote interface, claiming to be local machines, IP spoofing, get lost
    #
    $IPTABLES -A INPUT -i $EXTIF -s $INTNET -d $UNIVERSE -j drop-and-log-it


    # external interface, from any source, for ICMP traffic is valid
    #
    # If you would like your machine to "ping" from the Internet,
    # enable this next line
    #
    #$IPTABLES -A INPUT -i $EXTIF -p ICMP -s $UNIVERSE -d $EXTIP -j ACCEPT


    # Allow any related traffic coming back to the MASQ server in
    #
    $IPTABLES -A INPUT -i $EXTIF -s $UNIVERSE -d $EXTIP -m state --state \
    ESTABLISHED,RELATED -j ACCEPT


    # ----- Begin OPTIONAL Section -----
    #
    # HTTPd - Enable the following lines if you run an EXTERNAL WWW server
    #
    #echo -e " - Allowing EXTERNAL access to the WWW server"
    $IPTABLES -A INPUT -i $EXTIF -m state --state NEW,ESTABLISHED,RELATED \
    -p tcp -s $UNIVERSE -d $EXTIP --dport 80 -j ACCEPT
    #
    # echo -e " - Allowing sendmail for external mail "
    # $IPTABLES -A INPUT -i $EXTIF -m state --state NEW,ESTABLISHED,RELATED \
    # -p tcp -s $UNIVERSE -d $EXTIP --dport 25 -j ACCEPT

    #
    # SSHd - Enable the followin lines if you run an EXTERNAL SSH server
    #
    $IPTABLES -A INPUT -i $EXTIF -m state --state NEW,ESTABLISHED,RELATED \
    -p tcp -s $UNIVERSE -d $EXTIP --dport 22 -j ACCEPT
    #
    #
    # IMAPd - Enable the following lines if you run an EXTERNAL imap server
    #
    #echo -e " - Allowing EXTERNAL access to the IMAP server"
    # $IPTABLES -A INPUT -i $EXTIF -m state --state NEW,ESTABLISHED,RELATED \
    # -p tcp -s $UNIVERSE -d $EXTIP --dport 143 -j ACCEPT

    # Allow access to hight ports
    $IPTABLES -A INPUT -i $EXTIF -m state --state NEW,ESTABLISHED,RELATED \
    -p udp -s $UNIVERSE -d $EXTIP --dport $UP_PORTS -j ACCEPT
    $IPTABLES -A INPUT -i $EXTIF -m state --state NEW,ESTABLISHED,RELATED \
    -p tcp -s $UNIVERSE -d $EXTIP --dport $UP_PORTS -j ACCEPT
    # $IPTABLES -A INPUT -i $EXTIF -m state --state NEW,ESTABLISHED,RELATED \
    # -p tcp -s $UNIVERSE -d $EXTIP --dport 8080 -j ACCEPT
    # $IPTABLES -A INPUT -i $EXTIF -m state --state NEW,ESTABLISHED,RELATED \
    # -p tcp -s $UNIVERSE -d $EXTIP --dport 8090 -j ACCEPT

    #
    # ----- End OPTIONAL Section -----



    # Catch all rule, all other incoming is denied and logged.
    #
    $IPTABLES -A INPUT -s $UNIVERSE -d $UNIVERSE -j drop-and-log-it

    echo -e " - Loading OUTPUT rulesets"

    #######################################################################
    # OUTPUT: Outgoing traffic from various interfaces. All rulesets are
    # already flushed and set to a default policy of DROP.
    #

    # loopback interface is valid.
    #
    $IPTABLES -A OUTPUT -o lo -s $UNIVERSE -d $UNIVERSE -j ACCEPT


    # local interfaces, any source going to local net is valid
    #
    $IPTABLES -A OUTPUT -o $INTIF -s $EXTIP -d $INTNET -j ACCEPT


    # local interface, any source going to local net is valid
    #
    $IPTABLES -A OUTPUT -o $INTIF -s $INTIP -d $INTNET -j ACCEPT


    # outgoing to local net on remote interface, stuffed routing, deny
    #
    $IPTABLES -A OUTPUT -o $EXTIF -s $UNIVERSE -d $INTNET -j drop-and-log-it


    # anything else outgoing on remote interface is valid
    #
    $IPTABLES -A OUTPUT -o $EXTIF -s $EXTIP -d $UNIVERSE -j ACCEPT


    # Catch all rule, all other outgoing is denied and logged.
    #
    $IPTABLES -A OUTPUT -s $UNIVERSE -d $UNIVERSE -j drop-and-log-it


    echo -e " - Loading FORWARD rulesets"

    #######################################################################
    # FORWARD: Enable Forwarding and thus IPMASQ
    #

    echo " - FWD: Allow all connections OUT and only existing/related IN"
    $IPTABLES -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED \
    -j ACCEPT
    $IPTABLES -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT

    # Catch all rule, all other forwarding is denied and logged.
    #
    $IPTABLES -A FORWARD -j drop-and-log-it

    # Allow access to hight ports
    $IPTABLES -A FORWARD -i $EXTIF -o $INTIF -p tcp --dport $UP_PORTS -j ACCEPT
    $IPTABLES -A FORWARD -i $EXTIF -o $INTIF -p udp --dport $UP_PORTS -j ACCEPT

    echo " - NAT: Enabling SNAT (MASQUERADE) functionality on $EXTIF"
    #
    #More liberal form
    $IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE
    #
    #Stricter form
    #$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j SNAT --to $EXTIP

    echo "Redirecting WWW port to the internal network"
    $IPTABLES -t nat -A PREROUTING -p tcp -i $EXTIF --dport 80 -j DNAT --to 192.168.20.2
    $IPTABLES -t nat -A POSTROUTING -d 192.168.20.2 -j SNAT --to 192.168.20.1

    #######################################################################
    echo -e "\nStronger rc.firewall-2.4 $FWVER done.\n"

  4. Ola amigo,

    Olha bem grande esse script, e isso só dificulta a manutenção.
    Porém existe uma parte ali onde tem uma regra drop-and-log-it que está no final da chain forward! Tudo o que não foi identificado antes será dropado!

    Basicamente não é só colocar as regras nas chains PRE e POSTROUTING da tabela nat, é necessário aceitar esse trafego na chain FORWARD da tabela filter! E como a chain drop-and-log-it dropa tudo o que não estiver identificado você não consegue acessar o servidor!

    As suas regras de redirecionamento eu as deixaria assim:

    Código :
    $IPTABLES -t nat -A PREROUTING -p tcp -s <ip externo> --dport 80 -j DNAT --to 192.168.20.2
    $IPTABLES -t nat -A POSTROUTING -s 192.168.20.2 -j SNAT --to <ip externo>
    E além dessas regras falta essa para aceitar o trafego:

    Código :
    iptables -t filter -I FORWARD -d 192.168.20.2 -p tcp --dport 80 -j ACCEPT
    iptables -t filter -I FORWARD -s 192.168.20.2 -p tcp --sport 80 -j ACCEPT
    Testa aee



  5. Caro amigo zenun!!

    É, eu sei que está grande, mas como é da empresa, eu não quero mexer muito, sabe como é...

    Cara, faz muito sentido o que você me falou, não tinha reparado nessa regra. Vou tentar aplicar essas regras e respondo se deu certo ou não. Tomara que funcione.

    Só uma coisa: essas regras para aceitar o tráfego na porta 80, devem ser colocadas antes da drop-an-log-it ou pode ser depois das regras de redirecionamento?

    Muito obrigado mesmo!!!

    Um abraço.
    Última edição por felixleonardo; 28-06-2008 às 13:31.






Tópicos Similares

  1. Respostas: 2
    Último Post: 24-03-2007, 19:16
  2. redirecionar porta 80 p micro interno com servidor de cameras
    Por luciano555 no fórum Servidores de Rede
    Respostas: 5
    Último Post: 06-05-2006, 14:09
  3. Redirecionar porta 80 para porta do Proxy
    Por regiscechet no fórum Servidores de Rede
    Respostas: 6
    Último Post: 23-11-2005, 14:29
  4. redirecionar porta 80 para 3128
    Por lucianoruz no fórum Servidores de Rede
    Respostas: 8
    Último Post: 15-10-2004, 14:48
  5. Redirecionar porta 80 para 3128
    Por giuliano no fórum Servidores de Rede
    Respostas: 2
    Último Post: 22-01-2004, 18:51

Visite: BR-Linux ·  VivaOLinux ·  Dicas-L