Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Wed Sep 28, 2011 12:03 pm 
Offline
Senior Member

Joined: Fri May 20, 2011 2:45 am
Posts: 63
Location: Spain
What firewall would you install for a LAMP server?


Top
   
PostPosted: Wed Sep 28, 2011 12:39 pm 
Offline
Senior Member

Joined: Fri Feb 18, 2005 4:09 pm
Posts: 594
fernandoch wrote:
What firewall would you install for a LAMP server?


I use iptables, blocking all but ports 80 and 443 - with an SSH brute force blocker. Here is my boot script:

#!/bin/sh
iptables -P FORWARD DROP
iptables -P INPUT ACCEPT
iptables -A INPUT -i eth0 -p tcp --syn --destination-port 0:79 -j DROP
iptables -A INPUT -i eth0 -p tcp --syn --destination-port 81:442 -j DROP
iptables -A INPUT -i eth0 -p tcp --syn --destination-port 444: -j DROP
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -m recent --update --seconds 60 --hitcount 4 --rttl --name SSH -j LOG --log-prefix "SSH_brute_force "
iptables -A INPUT -p tcp --dport 22 -m recent --update --seconds 60 --hitcount 4 --rttl --name SSH -j DROP


James


Top
   
 Post subject:
PostPosted: Wed Sep 28, 2011 12:44 pm 
Offline
Senior Member

Joined: Fri May 20, 2011 2:45 am
Posts: 63
Location: Spain
Thanks, but never liked iptables, they are too complicated :(

Your script then also blocks port 22 for ssh?

What about ufw?


Top
   
 Post subject:
PostPosted: Wed Sep 28, 2011 12:49 pm 
Offline
Senior Member

Joined: Fri May 20, 2011 2:45 am
Posts: 63
Location: Spain
According to this http://library.linode.com/security/fire ... ific-ports your line 2 is wrong it should be like that

iptables -P INPUT DROP

Why?


Top
   
 Post subject:
PostPosted: Wed Sep 28, 2011 2:00 pm 
Offline
Senior Member

Joined: Mon Dec 20, 2010 11:37 pm
Posts: 76
fernandoch wrote:
According to this http://library.linode.com/security/fire ... ific-ports your line 2 is wrong it should be like that

iptables -P INPUT DROP

Why?


Basically there are 2 methods:
- drop everything and open what you need
- accept everything and drop what you don't want

Linode library uses first one, the preferable.


Top
   
 Post subject:
PostPosted: Wed Sep 28, 2011 2:04 pm 
Offline
Senior Member

Joined: Mon Dec 20, 2010 11:37 pm
Posts: 76
fernandoch wrote:
Thanks, but never liked iptables, they are too complicated :(

Your script then also blocks port 22 for ssh?

What about ufw?


I use ufw in my Debian box because I don't like "plain" iptables too. You should try ufw and look at this (http://vincom2.wordpress.com/2010/04/07/logging-ufw-to-a-seperate-logfile/) if you don't want to see many ufw entries in your syslog file.


Top
   
 Post subject:
PostPosted: Wed Sep 28, 2011 4:23 pm 
Offline
Senior Member

Joined: Wed Jul 21, 2010 8:04 pm
Posts: 119
drpks wrote:
fernandoch wrote:
Thanks, but never liked iptables, they are too complicated :(

Your script then also blocks port 22 for ssh?

What about ufw?


I use ufw in my Debian box because I don't like "plain" iptables too. You should try ufw and look at this (http://vincom2.wordpress.com/2010/04/07/logging-ufw-to-a-seperate-logfile/) if you don't want to see many ufw entries in your syslog file.

+1 for UFW


Top
   
 Post subject:
PostPosted: Wed Sep 28, 2011 5:31 pm 
Offline
Senior Member
User avatar

Joined: Sat Aug 30, 2008 1:55 pm
Posts: 1739
Location: Rochester, New York
Under the hood, remember: it's all iptables.

On zunzun's example, I believe the first three rules (--syn --destination-port ...) are a stateless (and necessarily TCP-only) equivalent of the common stateful pattern (as seen in the library article). Basically, it says "drop any new connections to a port that isn't kosher, and accept everything else"; the stateful pattern says "accept any existing connections, accept any new connections to a port that is kosher, and drop everything else".

Technically, zunzun's approach is probably more efficient, as it does not need to maintain a connection tracking table to be checked on every incoming packet. However, for a new design, I'd go stateful and perhaps notch out exceptions if you are doing something like handling ~500 NTP queries per second.

(My local router, based on Linux and powered by an Atheros AR7242 CPU at 400 MHz, has 250 connections in its tracking table and is handling about 430 packets/second, and is at about 8% CPU load. That's probably more than most Linodes...)


Top
   
 Post subject:
PostPosted: Wed Sep 28, 2011 10:42 pm 
Offline
Senior Member

Joined: Sun May 23, 2010 1:57 pm
Posts: 315
Website: http://www.jebblue.net
hoopycat wrote:
Under the hood, remember: it's all iptables.


ufw is an automatic transmission. For most stuff it's great. When you have a tough hill to climb you break out iptables.

I'd never again (never say never) use a manual transmission in city traffic.


Top
   
 Post subject:
PostPosted: Wed Sep 28, 2011 11:44 pm 
Offline
Senior Member
User avatar

Joined: Sat Aug 30, 2008 1:55 pm
Posts: 1739
Location: Rochester, New York
Yup, totally. But I ain't installing an automatic transmission on the lawn mower. :-)

(My other analogy is a CVT.)


Top
   
 Post subject:
PostPosted: Thu Sep 29, 2011 12:29 am 
Offline
Senior Member

Joined: Wed Oct 20, 2010 12:11 pm
Posts: 142
What's with all the car analogies? Is this /. all of a sudden? ;p


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group