IPTables Question

From: James Purser (purserj_at_optusnet.com.au)
Date: 11/29/04

  • Next message: Grahame Cooper: "Re: how to update ldap directory?"
    Date: Mon, 29 Nov 2004 22:23:47 +1100
    
    

    Okay this is going to probably come across as a newbie question but it
    really is bugging me.

    I have a machine running as a gateway between my local network and the
    internet. The internet is accessed via dialup (I know but DSL costs big
    ones at the moment). Everything works fine except for the port forwarding.
    Below is the script I have knocked together to build the firewall, if some
    one could have a look at it and tell me what I am doing wrong that would
    be great.

    #!/bin/sh
                                                                                    
    # Diable forwarding
    echo 0 > /proc/sys/net/ipv4/ip_forward
                                                                                    
                                                                                    
    LAN_IP_NET='192.168.0.1/24'
    LAN_NIC='eth0'
    WAN_NIC='ppp0'
    FORWARD_IP='192.168.0.1'
                                                                                    
    #Get External IP
    WAN_IP="`ifconfig $WAN_NIC | grep 'inet addr' | awk '{print $2}' | sed -e
    's/.*://'`"
                                                                                    
    # load some modules (if needed)
                                                                                    
    # Flush
    iptables -t nat -F POSTROUTING
    iptables -t nat -F PREROUTING
    iptables -t nat -F OUTPUT
    iptables -F
                                                                                    
    iptables -P INPUT DROP
    iptables -P FORWARD DROP
    iptables -P OUTPUT ACCEPT
                                                                                    
    # enable Masquerade and forwarding
    iptables -t nat -A POSTROUTING -s $LAN_IP_NET -j MASQUERADE iptables -A
    FORWARD -j ACCEPT -i $LAN_NIC -s $LAN_IP_NET iptables -A FORWARD -m state
    --state ESTABLISHED,RELATED -j ACCEPT
                                                                                    
    # STATE RELATED for router
    iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
                                                                                    
    # Open ports for local network
    iptables -A INPUT -i eth0 -j ACCEPT -p tcp --dport 10000 iptables -A INPUT
    -i eth0 -j ACCEPT -p tcp --dport 3128 iptables -A INPUT -i ppp0 -j ACCEPT
    -p tcp --dport 8081 # Open ports to server on LAN iptables -A FORWARD -i
    ppp0 -p tcp --syn -m state --state NEW,ESTABLISHED,RELATED -d 192.168.0.1
    -j ACCEPT iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j
    ACCEPT iptables -A FORWARD -p tcp -i ppp0 -o eth0 -d 192.168.0.1 --dport
    80 --sport 1024:65535 -m state --state NEW -j ACCEPT iptables -A FORWARD
    -t filter -i eth0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
    iptables -A FORWARD -t filter -i ppp0 -m state --state ESTABLISHED,RELATED
    -j ACCEPT
                                                                                    
    #Enable Port Forward
    iptables -t nat -A PREROUTING -i ppp0 -d $WAN_IP -p tcp --dport 8081
    --sport 80:65535 -j DNAT --to-destination $FORWARD_IP:80
                                                                                    
    iptables -A FORWARD -j LOG
    # Enable forwarding
    echo 1 > /proc/sys/net/ipv4/ip_forward echo "1" >
    /proc/sys/net/ipv4/ip_dynaddr


  • Next message: Grahame Cooper: "Re: how to update ldap directory?"

    Relevant Pages

    • respawn java process
      ... I run a small java program called jredirect for forwarding a port. ... problem is after a while the process halts. ... I've also tried to get port forwarding working with iptables, ...
      (Fedora)
    • Re: iptables rules forletting overnet/edonkey through
      ... >> what would be the rules for IPTABLES to let edonkey traffic through ... I've never used NAT or Masq before. ... >80 and make one exactly the same but for that tcp port, and udp port, etc. ... INPUT chain only goes to the FW machine itself and my overnet traffic ...
      (comp.security.firewalls)
    • Re: Bridging wifi to ethernet
      ... What follows is for Ubuntu Breezy but the issues are the same: ... The iptables in Breezy come unset. ... Forwarding accomplished by: ... However, I had to pull down the Firestarter forwarding/firewall to enable the use of an FTP server on the laptop (again, an Ubuntu box - I did get dual boot on FC4 on this box yesterday but have not tried the NAT thing on FC4 there yet) on its ethernet path to another desktop FC4 box on the ethernet wire. ...
      (Fedora)
    • Re: Azureus and the TCP port 6881
      ... NAT howto and I was scared... ... following message: "Testing port 6881... ... More than likely you'll need to setup a NAT rule in iptables. ...
      (Debian-User)
    • Re: set up NAT (network address translation) on local server
      ... (shows whether your snat rule is implemented correctly) ... iptables -vnL -t nat ... (tells if ip forwarding is on) ...
      (Fedora)