LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 08-05-2009, 05:09 PM   #1
forrie
Member
 
Registered: Sep 2003
Distribution: RedHat
Posts: 41

Rep: Reputation: 15
Fumbling with Iptables


I've been having a difficult time trying to get this configuration to work properly. I'm learning iptables, from FreeBSD/PF. I've read tutorials, books, etc, and I can't seem to figure out why this isn't working.

The primary motivation behind this was to to limit access to port 22 (we're getting slammed with dictionary attacks) - but generally, we need the below configuration to work.

With this file, installed in /etc/sysconfig/iptables, people from the outside can get to port 22.

It's possible the sheer amount of time I've spent on this has me overlooking something very simple. So a second, more experienced pair of eyes is needed.

I'd appreciate any feedback.

When I removed the line:

-A RH-Firewall-1-INPUT -i eth0 -j ACCEPT

It seemed to work, but we ended up having troubles with the other ports, so I just reverted to this version.

Thanks!

(obviously, the x's and W's are here for illustrative purposes ;-))

Code:
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT 
-A FORWARD -j RH-Firewall-1-INPUT 
-A RH-Firewall-1-INPUT -i lo -j ACCEPT 
-A RH-Firewall-1-INPUT -i eth0 -j ACCEPT 
-A RH-Firewall-1-INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT 
-A RH-Firewall-1-INPUT -s x.x.x.0/255.255.255.0 -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT 
-A RH-Firewall-1-INPUT -s x.x.x.0/255.255.255.0 -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT 
-A RH-Firewall-1-INPUT -d x.x.x.x -p tcp -m state --state NEW -m tcp --dport XXXX -j ACCEPT 
-A RH-Firewall-1-INPUT -d x.x.x.x -p tcp -m state --state NEW -m tcp --dport XXXX -j ACCEPT 
-A RH-Firewall-1-INPUT -s x.x.x.0/255.255.255.0 -p tcp -m state --state NEW -m tcp --dport 3333 -j ACCEPT 
-A RH-Firewall-1-INPUT -s x.x.x.x -p tcp -m state --state NEW -m tcp --dport VVVV -j ACCEPT 
-A RH-Firewall-1-INPUT -s x.x.x.x -p tcp -m state --state NEW -m tcp --dport WWWW -j ACCEPT 
-A RH-Firewall-1-INPUT -j DROP 
COMMIT
 
Old 08-05-2009, 05:24 PM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Your objective is to allow inbound connections to port 22 only from certain IPs, right? That eth0 rule would send to ACCEPT any packet which arrives on that interface, thereby making all the other ACCEPT rules redundant as far as that interface is concerned. I'd get rid of that rule, then add some DROP rules after every exception IP rule. Example:
Code:
-A RH-Firewall-1-INPUT -s x.x.x.0/255.255.255.0 -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT 
-A RH-Firewall-1-INPUT -s x.x.x.0/255.255.255.0 -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT 
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j DROP
 
Old 08-05-2009, 05:27 PM   #3
forrie
Member
 
Registered: Sep 2003
Distribution: RedHat
Posts: 41

Original Poster
Rep: Reputation: 15
You are correct. I noticed that and when I dropped that rule, suddenly other people couldn't get in (even from the named networks we want to allow).

The other ports are for some video stuff.


Thanks for your help!
 
Old 08-10-2009, 12:25 PM   #4
forrie
Member
 
Registered: Sep 2003
Distribution: RedHat
Posts: 41

Original Poster
Rep: Reputation: 15
The rules were auto-created via the system-config-firewall too, or something before me.

If I place an allow rule for each port in the chain, then end it with:

-A RH-Firewall-1-INPUT -j DROP

Shouldn't that take care of the problem. I wouldn't think I'd need to add DROP for each rule in between.

I think removing that -i eth0 rule may solve the problem... but we had some issues with video not rolling before when I made that change.
 
Old 08-10-2009, 05:14 PM   #5
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by forrie View Post
The rules were auto-created via the system-config-firewall too, or something before me.

If I place an allow rule for each port in the chain, then end it with:

-A RH-Firewall-1-INPUT -j DROP

Shouldn't that take care of the problem. I wouldn't think I'd need to add DROP for each rule in between.

I think removing that -i eth0 rule may solve the problem... but we had some issues with video not rolling before when I made that change.
Yeah, it's nice to be able to handle everything with ACCEPT rules, and only a DROP rule at the end (or a DROP policy). In the example I posted, the DROP only serves to make sure that any other rules after that don't need to deal with the unauthorized 22/TCP packets. This was due to the symptoms you seemed to be describing (that unauthorized IPs were still able to connect to port 22) being indicative of the 22/TCP packets being sent to ACCEPT by later rules. Since you've replaced the port numbers in the other rules with weird letters, I couldn't really be sure what exactly was going on, so I played it safe.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
An error occured getting IPtables status from the command /etc/rc.d/init.d/iptables s CrazyMAzeY Linux - Newbie 10 08-12-2010 05:25 AM
iptables v1.2.9: Unknown arg `/sbin/iptables' Try `iptables -h' or 'iptables --help' Niceman2005 Linux - Security 4 12-29-2005 08:20 PM
IPtables Log Analyzer from http://www.gege.org/iptables/ brainlego Linux - Software 0 08-11-2003 06:08 AM
iptables book wich one can you pll recomment to be an iptables expert? linuxownt Linux - General 2 06-26-2003 04:38 PM
My iptables script is /etc/sysconfig/iptables. How do i make this baby execute on boo ForumKid Linux - General 3 01-22-2002 07:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 07:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration