Results 1 to 3 of 3

Thread: Simple firewall in CentOs

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Simple firewall in CentOs

    Hello Everybody!

    I need help to setup a simple firewall for my webserver.

    I have install httpd on my server make a index.html and so on.
    There are 2 pc's
    PC 1: ip range 192.168.4.0-63 | 255.255.255.192
    PC 2: ip range 192.168.4.64-127 | 255.255.255.192

    My plan with the firewall on the webserver is:

    PC 1 can se the index.html or rather is allowed on the webserver.

    PC 2 will be block/locked out from the webserver, so PC 2 can't se the index.html.

    Can someone make just a simple firewall for that with iptables..?

    Please say if you need some more information for helping me, i will hand it to you.

    In advance thank you very much

  2. #2
    Junior Member
    Join Date
    Mar 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Code:
    #!/bin/bash
    
    http_list="192.168.4.0/26"
    
    # Clean old firewall
    iptables -F
    iptables -X
    iptables -t nat -F
    iptables -t nat -X
    iptables -t mangle -F
    iptables -t mangle -X
    
    ### Default Policy ###
    iptables -P INPUT DROP
    iptables -P FORWARD DROP
    iptables -P OUTPUT ACCEPT
    
    ### Permit Loopback Trafic ###
    iptables -A INPUT -i lo -j ACCEPT
    iptables -A OUTPUT -o lo -j ACCEPT
    
    ### Permit established connections inbound communication ###
    iptables -A INPUT -m state --state "ESTABLISHED,RELATED" -j ACCEPT
    
    ### Permit SSH ###
    iptables -A INPUT -p tcp --syn --dport 22 -j ACCEPT
    
    ###  Permit HTTP ###
      for s in $http_list; do
        iptables -A INPUT -p tcp --syn --dport 80 -s $s -j ACCEPT
      done

    WARNING
    : This will drop everything except ssh acces and http from PC1 network , you should not issue service iptables restart after applying this rules or you'll get blocked out , instead use this reset script

    Code:
    #!/bin/bash
    
    ### Default Policy ###
    iptables -P INPUT ACCEPT
    iptables -P FORWARD ACCEPT
    iptables -P OUTPUT ACCEPT
    
    # Clean old firewall
    iptables -F
    iptables -X
    iptables -t nat -F
    iptables -t nat -X
    iptables -t mangle -F
    iptables -t mangle -X
    Last edited by TiTex; 2nd March 2013 at 10:24 AM.

  3. #3
    raj
    raj is offline
    Senior Member raj's Avatar
    Join Date
    Jun 2005
    Location
    Hyderabad
    Posts
    550
    Thanks
    55
    Thanked 39 Times in 36 Posts
    Rep Power
    12
    Raj
    Linux rulz.
    I have never turned back in my life ; I shall not do so today.. haha

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need Firewall for centOS 5.5
    By tanin007 in forum CentOS / RHEL / Fedora
    Replies: 2
    Last Post: 28th December 2011, 01:44 AM
  2. CentOS Linux Default Firewall Configuration
    By vamsi in forum CentOS / RHEL / Fedora
    Replies: 2
    Last Post: 9th March 2010, 04:22 PM
  3. Simple Image Browser PHP
    By eawedat in forum Coding in General
    Replies: 4
    Last Post: 14th June 2009, 09:40 PM
  4. Centos deactivate firewall
    By raj in forum Getting started tutorials
    Replies: 0
    Last Post: 2nd March 2009, 11:26 PM
  5. Simple Xen API programming
    By unixfoo in forum XEN
    Replies: 0
    Last Post: 28th December 2007, 11:00 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41