Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • BackTrack 5 R2
  • Wine 1.4 / 1.5.5
  • Mozilla Firefox 12...
  • Ubuntu 11.04
  • Angry Birds 1.1.2.1
  • Ubuntu 10.04.4 LTS
  • Linux Kernel 3.4
  • Ubuntu Manual 10.10
  • Adobe Flash Player...
  • Pidgin 2.10.4
  • Home > Linux > System > Networking

    NAT and blocking all but Port 22 1.0

    Download button

    No screenshots available
    Downloads: 375  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Peter Rektorschek | More programs
    GPL / FREE
    February 14th, 2007, 17:34 GMT
    ROOT / System / Networking

     Read user reviews (0)  Refer to a friend  Subscribe

    NAT and blocking all but Port 22 description

    NAT and blocking all but Port 22 is a simple iptables firewall script.

    NAT and blocking all but Port 22 is a simple iptables firewall script.

    Sample:

    # Internal and External Devices
    dev_world=ppp0
    dev_int=eth0

    # Firewall IP
    addr_int=192.168.1.1

    # Internal Net
    net_int=192.168.1.0/24

    ###################################################
    # Load Modules
    insmod ip_tables
    insmod ip_conntrack
    insmod ip_conntrack_ftp
    insmod ipt_state
    insmod iptable_nat
    insmod ipt_MASQUERADE

    ###################################################
    # Delete all Rules in Filtertable
    iptables -F

    ###################################################
    # Define new chains
    iptables -N BLOCK
    iptables -N EXT-INT
    iptables -N INT-EXT
    iptables -N ICMP-DENY
    iptables -N INT-IF
    iptables -N EXT-IF

    ###################################################

    iptables -A BLOCK -m state --state ESTABLISHED,RELATED -j ACCEPT
    iptables -A BLOCK -m state --state NEW -i ! $dev_world -j ACCEPT
    iptables -A BLOCK -j DROP

    iptables -A INPUT -j BLOCK
    iptables -A FORWARD -j BLOCK

    ###################################################
    # Point to chains
    iptables -A INPUT -i lo -j ACCEPT
    iptables -A INPUT -i $dev_int -s $net_int -j INT-IF
    iptables -A INPUT -d ! $addr_int -i $dev_world -s ! $net_int -j EXT-IF
    iptables -A INPUT -j DROP

    iptables -A FORWARD -d ! $net_int -i $dev_world -s $net_int -j INT-EXT
    iptables -A FORWARD -d $net_int -i $dev_int -s ! $net_int -j EXT-INT
    iptables -A FORWARD -j DROP

    iptables -A OUTPUT -j ACCEPT

    ###################################################
    # Chain Rules
    iptables -A EXT-INT -j DROP

    iptables -A EXT-IF -i ! $dev_world -j DROP
    iptables -A EXT-IF -p tcp --dport 22 -j ACCEPT
    iptables -A EXT-IF -p tcp --dport 5901 -j ACCEPT
    iptables -A EXT-IF -p tcp --dport 1024: -j ACCEPT
    iptables -A EXT-IF -p udp --dport 1024: -j ACCEPT
    iptables -A EXT-IF -j DROP

    iptables -A INT-IF -j ACCEPT

    ###################################################
    # NAT Rules
    # Standard Routing
    iptables -A POSTROUTING -t nat -o $dev_world -j MASQUERADE -s $net_int

    # Port Forwarding
    #iptables -A PREROUTING -t nat -p tcp -d 192.168.1.1 --dport 5901 --to 192.168.1.2:5901 -j DNAT

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

    Product's homepage

      


    TAGS:

    NAT firewall | iptables firewall | netfilter firewall | NAT | blocking | iptables



    HTML code for linking to this page:


    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM