Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2011
    Location
    Dallas, TX
    Posts
    31
    Thanks
    0
    Thanked 8 Times in 3 Posts
    Rep Power
    10

    Post Basic Firewall with iptables

    This how-to is about making a basic firewall.

    1. You will need root priviledges (one way to become root is to run the command su from a terminal and then type the root password).

    Now, open the file /etc/rc.d/rc.local in a text editor. Add the text /etc/rc.d/rc.firewall on a new line at the end of the file. Save the file.
    Note that this entry makes the firewall start on your computer at boot. If you want to disable the firewall, just remove or comment this line (put a # at the start of the line).

    2. Now create a new file called rc.firewall in the /etc/rc.d directory and put the text below
    Code:
    #!/bin/sh
    
    
    #Change the part after the = to the where you IPTABLES is on your system
    IPTABLES=/sbin/iptables
    
    #flush existing rules
    $IPTABLES -F INPUT
    
    #This allows all data that has been sent out for the computer running the firewall
    # to come back 
    #(for all of ICMP/TCP/UDP).
    #For example, if a ping request is made it will allow the reply back
    $IPTABLES -A INPUT -j ACCEPT -m state --state ESTABLISHED -i eth0 -p icmp
    $IPTABLES -A INPUT -j ACCEPT -m state --state ESTABLISHED -i eth0 -p tcp
    $IPTABLES -A INPUT -j ACCEPT -m state --state ESTABLISHED -i eth0 -p udp
    
    
    #Allow traffic from ethernet adapter eth1 to pass through if 
    #you have a network, or 
    #as using linux as a router for internet etc. 
    #Your first ethernet card is eth0 and the second would be eth1 etc. 
    #$IPTABLES -A INPUT -i eth1 -j ACCEPT
    
    
    #Allow incoming FTP requests
    #$IPTABLES -A INPUT -p tcp --dport 20 -j ACCEPT
    #$IPTABLES -A INPUT -p tcp --dport 21 -j ACCEPT
    
    #Allow incoming SSH requests
    $IPTABLES -A INPUT -p tcp --dport 22 -j ACCEPT
    
    #Allow incoming HTTP requests (to Web server)
    #$IPTABLES -A INPUT -p tcp --dport 80 -j ACCEPT
    
    
    #Allow Ping echo
    #I have commented this line, so ping from an outside machine will not work.
    #Uncomment the next line to make ping from outside work.
    #$IPTABLES -A INPUT -p icmp -j ACCEPT
    
    
    #Drop and log all other data
    #The logging is set so if more than 5 packets are dropped in 
    #three seconds they will be ignored. This helps to prevent a DOS attack
    #Crashing the computer the firewall is running on 
    $IPTABLES -A INPUT -m limit --limit 3/second --limit-burst 5 -i ! lo -j LOG
    $IPTABLES -A INPUT -i ! lo -j DROP
    
    #The logs from the firewall are put into your system log file, which can be found at #/var/log/syslog

    Save the file.

    Note
    Note that every line that starts with a # is only a comment.


    3. Run the command chmod 755 /etc/rc.d/rc.firewall to make the script executable.

    4. Run the command /etc/rc.d/rc.firewall to start the firewall.

    Remember this firewall is by no means perfect, but it does provide a basic level of protection and make you "stealthed". (Stealthed means that your computer is invisible to most kinds of tests, but again this is not perfect)
    Last edited by steelmanronald06; 05-15-2012 at 03:53 PM.
    Visit my MySQL Forum at MySQLExchange.com for MySQL help, articles, tutorials, tips and tricks.




  2. #2
    Join Date
    Nov 2011
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    2
    Personally I use CSF, which I find great for a free firewall. Guess something like this is handy if you want to work from scratch, with no third party software.

  3. #3
    Join Date
    Mar 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Very nice tutorial. Thanks for sharing. I was looking for a way to make a firewall on my Mint system, and this looks perfect. Once again, thank you very much for sharing.

  4. #4
    Join Date
    Mar 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Nicely done!

  5. #5
    Join Date
    Jan 2012
    Location
    Bahrain
    Posts
    187
    Thanks
    4
    Thanked 1 Time in 1 Post
    Rep Power
    2
    Very nice! A basic level of protection is always better than not being protected in the first place. At present i use CSF & LFD and they're really performing well.

    But a couple of months ago when i was setting up a VPN i had to play around with IPtables and temporarily have CSF disabled to test the VPN's functionality.

    I figured that i had to set Pre and Post Routing rules as well as allow IPv4 Forwarding and the routing had to be done via IPtables which i found was very impressive.

  6. #6
    Join Date
    Mar 2012
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Firewall is really important when it comes to ensuring security for your computer, but I am still a bit iffy on the topic of iptables. What exactly is it? Is it some sort of firewall software? It is used to enhance the security?

  7. #7
    Join Date
    Apr 2012
    Posts
    124
    Thanks
    5
    Thanked 1 Time in 1 Post
    Rep Power
    2
    Smart I need to complete some firewalls on a couple of machines so I will be taking a good look at this.

  8. #8
    Join Date
    May 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Seems a free tutorial and useful for many of the professionals. Even though, I never tried out to turn on the firewall by typing commands, as such I was in doubt that making the use of a "#" may not create any other request to run rather than that of firewall, as I am a slight weak in linux.

 

 

Similar Threads

  1. Basic Debain LAMP setup
    By tomfmason in forum Linux-Howtos
    Replies: 7
    Last Post: 08-19-2012, 03:58 PM
  2. Basic Debain LAMP setup
    By Fred in forum Linux News
    Replies: 0
    Last Post: 11-10-2011, 06:06 PM
  3. General tips for working with iptables
    By Fred in forum Linux News
    Replies: 0
    Last Post: 11-10-2011, 09:21 AM
  4. General tips for working with iptables
    By Elliot in forum Linux-Howtos
    Replies: 0
    Last Post: 11-09-2011, 02:16 PM
  5. Creating Firewall Rules for Freshclam
    By Fred in forum Linux News
    Replies: 0
    Last Post: 11-08-2011, 12:47 PM

Bookmarks

Posting Permissions

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








Check out Linux Central for Linux software and other goodies!





» Stats

Members: 3,573
Threads: 3,920
Posts: 9,442
Top Poster: Fred (1,486)
Welcome to our newest member, Ronald de Souza

» Links



Powered by vBadvanced CMPS