Re: Problems with IPTABLES

From: Richard (ikke@nospam.no-ip.com)
Date: 03/03/02

  • Next message: John Holder: "Re: Was somebody in my box?"

    From: Richard <ikke@nospam.no-ip.com>
    Date: Sat, 2 Mar 2002 21:36:28 -0800
    
    

    In article <3C810A6A.ABDCD998@hot.ee>, kirotarp@hot.ee says...
    > Hi,
    >
    > I have problem with my firewall setings (RH7.2/iptables)! When I enable
    > rules, all computers on local network can access internet and send mail
    > but cant login to samba and cant ping server IP and cant connect through
    > local windows networking ! When I clear all rules, then computers can
    > see server and login to samba domain, but cant see internet anymore!
    > :(

    Try the followin firewall script:

    ipt=/sbin/iptables
    extip=1.2.3.4
    intip=192.168.100.1
    extif=eth0
    intif=eth1

    # SYN-cookies
    echo 1 > /proc/sys/net/ipv4/tcp_syncookies

    # Enable IP-forwarding
    echo 1 > /proc/sys/net/ipv4/ip_forward

    # Enable broadcast echo protection
    echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

    # Enable bad error message protection
    echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses

    # Enable IP-spoofing protection
    for i in /proc/sys/net/ipv4/conf/*/rp_filter
    do
            echo 1 > $i
    done

    # Disable ICMP Redirect accpetance
    for i in /proc/sys/net/ipv4/conf/*/accept_redirects
    do
            echo 0 > $i
    done

    # Disable source routed packets
    for i in /proc/sys/net/ipv4/conf/*/accept_source_route
    do
            echo 0 > $i
    done

    # Protect against ICMP echo flooding
    echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all

    # Load modules
    modprobe ip_conntrack
    modprobe ip_conntrack_ftp

    # Default policies
    $ipt -P INPUT DROP
    $ipt -P OUTPUT DROP
    $ipt -P FORWARD DROP

    # Flush tables
    $ipt -F
    $ipt -t nat -F
    $ipt -t mangle -F

    # Drop invalid packets
    $ipt -t mangle -A PREROUTING -m state --state INVALID -j DROP

    # DO NAT
    $ipt -t nat -A POSTROUTING -o $extif -j SNAT --to-source $extip

    # Allow local traffic
    $ipt -A INPUT -i lo -j ACCEPT
    $ipt -A OUTPUT -o lo -j ACCEPT

    # Allow replies
    $ipt -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    $ipt -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
    $ipt -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

    #INPUT
    $ipt -A INPUT -i $intif -p tcp --dport 53 -j ACCEPT # DNS
    $ipt -A INPUT -i $intif -p udp --dport 53 -j ACCEPT # DNS
    $ipt -A INPUT -i $intif -p tcp --dport 67 -j ACCEPT # DHCP
    $ipt -A INPUT -i $intif -p udp --dport 67 -j ACCEPT # DHCP
    $ipt -A INPUT -p tcp --dport 80 -j ACCEPT # WWW
    $ipt -A INPUT -p tcp --dport 443 -j ACCEPT # HTPS
    $ipt -A INPUT -p tcp --dport 25 -j ACCEPT # SMTP
    $ipt -A INPUT -i $intif -p tcp --dport 143 -j ACCEPT # IMAP
    $ipt -A INPUT -i $intif -p udp --dport 143 -j ACCEPT # IMAP
    $ipt -A INPUT -i $intif -p tcp --dport 137:139 -j ACCEPT # SMB
    $ipt -A INPUT -i $intif -p udp --dport 137:139 -j ACCEPT # SMB
    $ipt -A INPUT -p tcp --dport 22 -j ACCEPT # SSH
    $ipt -A INPUT -i $intif -p tcp --dport 3128 -j ACCEPT # SQUID
    $ipt -A INPUT -p icmp -j ACCEPT # PING
    $ipt -A INPUT -i $intif -d ! $intif -j REJECT # These will reject
    $ipt -A INPUT -i $extif -f ! $extif -j REJECT # broadcasts

    #OUTPUT
    $ipt -A OUTPUT -i $extif -p tcp --dport 53 -j ACCEPT # DNS
    $ipt -A OUTPUT -i $extif -p udp --dport 53 -j ACCEPT # DNS
    $ipt -A OUTPUT -i $extif -p tcp --dport 80 -j ACCEPT # HTTP
    $ipt -A OUTPUT -i $extif -p tcp --dport 443 -j ACCEPT # HTTPS
    $ipt -A OUTPUT -i $extif -p tcp --dport 25 -j ACCEPT # SMTP
    $ipt -A OUTPUT -i $intif -p udp --dport 137:139 -j ACCEPT # SMB
    $ipt -A OUTPUT -i $intif -p tcp --dport 137:139 -j ACCEPT # SMB
    $ipt -A OUTPUT -p icmp -j ACCEPT

    #FORWARD

    # if your own machine isn't the mail server uncomment this line:
    # $ipt -A FORWARD -p tcp --dport 25 -j ACCEPT
    $ipt -A FORWARD -p tcp --dport 20:21 -j ACCEPT # Don't know the exact
    thing for ftp have a ftp-proxy I can recommend that you do this als
    $ipt -A FORWARD -p tcp --dport 137:139 -j DROP
    $ipt -A FORWARD -p udp --dport 137:139 -j DROP

    #Catch all... DENY and log
    $ipt -A INPUT -j LOG
    $ipt -A OUTPUT -j LOG
    $ipt -A FORWARD -j LOG

    This should do the trick and if something is still not working check
    /var/log/messages for what the things that the firewall is denying.

    To use --dport you must first do -p (icmp for example don't have a
    destination port)

    iptables -A INPUT -s 0/0 -p tcp -d 0/0 --dport 1024:65535 -j ACCEPT
    the -d option is not needed if you want everybody. This rule isn't
    necessary anymore because you accept related and established connections

    iptables -A INPUT -i eth0 -p tcp -s $CLASS_A -j DROP
    iptables -A INPUT -i eth0 -p tcp -s $CLASS_B -j DROP
    iptables -A INPUT -i eth0 -p tcp -s $CLASS_C -j DROP
    You should not get packages with this ipaddress

    iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
    This rule is weird, why should your machine must forward thins on the
    same network??

    iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
    This rule will open all ports for your internal network to the internet
    and if you have windows you proberbly won't want this (in case with the
    viruses etc.)



    Relevant Pages

    • RE: can ping but not browse
      ... I have stopped the firewall. ... # are safed from all (security) hazards. ... firewall/bastion host to the internet ... # internet and to an internal network, ...
      (Fedora)
    • Re: Using a Linksys router, should I also use Zonealarm?
      ... public internet to access corporate network. ... In the "old days" when people used to use Dial-In instead of VPN you ware ... protected by corporate Firewall -- since there was no public Internet ...
      (microsoft.public.security)
    • RE: Hidden Ports
      ... this is done by the firewalls to prevent authenticated files from being replaced by trojans and connecting to the internet. ... kerio firewall ... or a program that already had network access attempted to ... > Depending on the Access setting for a component, ZoneAlarm Pro ...
      (Security-Basics)
    • Re: Entire Network
      ... Internet access is different and just because a firewall isn't ... Second, if it isn't the firewall, then often it is a case of the system ... any way a network guru. ... > The network connection works just fine from both computers for internet ...
      (microsoft.public.windowsxp.basics)
    • Re: Using a Linksys router, should I also use Zonealarm? Internet Acceptable Use Policy
      ... my browser's access to the Internet is restricted. ... I thought it was the company's firewall extending a slap on my ... > public internet to access corporate network. ... > NAT is Network Address Translation. ...
      (microsoft.public.security)