LinuxQuestions.org
Review your favorite Linux distribution.
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 04-22-2012, 08:02 PM   #1
TigerIvy
LQ Newbie
 
Registered: Apr 2012
Posts: 1

Rep: Reputation: Disabled
iptable help please?


I am kinda a linux noob I guess (lol) and I am having problems wrriting my iptables. I either lock myself out or it doesn't work. What I am trying to do is only allow specific ip address to access ports 3306 and 22, everyone to access ports 80 and 29000 and block all other ports. This is what I have but there is an error (or 100) somewhere. Thanks in advance for the help!

-I INPUT --src 123.123.123.123 -m tcp -p tcp --dport 3306 -j DROP
-I INPUT --src 123.123.123.123 -m tcp -p tcp --dport 3306 -j DROP
-I INPUT --src 123.123.123.123 -m udp -p tcp --dport 3306 -j DROP
-I INPUT --src 123.123.123.123 -m udp -p tcp --dport 3306 -j DROP
-I INPUT --src 123.123.123.123 -m tcp -p tcp --dport 22 -j DROP
-I INPUT --src 123.123.123.123 -m tcp -p tcp --dport 22 -j DROP
-I INPUT --src 123.123.123.123 -m udp -p tcp --dport 22 -j DROP
-I INPUT --src 123.123.123.123 -m udp -p tcp --dport 22 -j DROP
-A INPUT -p tcp -i eth0 -s ! 123.123.123.123 --dport 22 -j DROP
-A INPUT -p tcp -i eth0 -s ! 123.123.123.123 --dport 3306 -j DROP
-A INPUT -p udp -i eth0 -s ! 123.123.123.123 --dport 53 -j DROP
-A INPUT -p tcp -i eth0 -s ! 123.123.123.123 --dport 53 -j DROP
-A INPUT -m state --state NEW -m tcp -p tcp --dport 0:79 -j DROP
-A INPUT -m state --state NEW -m tcp -p tcp --dport 81:3305 -j DROP
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3307:28999 -j DROP
-A INPUT -m state --state NEW -m tcp -p tcp --dport 29000:65535 -j DROP
-A INPUT -m state --state NEW -m udp -p tcp --dport 0:79 -j DROP
-A INPUT -m state --state NEW -m udp -p tcp --dport 81:3305 -j DROP
-A INPUT -m state --state NEW -m udp -p tcp --dport 3307:28999 -j DROP
-A INPUT -m state --state NEW -m udp -p tcp --dport 29000:65535 -j DROP
-A INPUT -p icmp --icmp-type 0 -j ACCEPT
-A INPUT -p icmp --icmp-type 3 -j ACCEPT
-A INPUT -p icmp --icmp-type 5 -j ACCEPT
-A INPUT -p icmp --icmp-type 11 -j ACCEPT
-A INPUT -p icmp -j DROP
COMMIT
 
Old 04-22-2012, 09:23 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Iptables will use the first rule that a packet matches, going by your post you want to DROP everything except icmp. Using DROP as a target means to throw away the matching packet and not to respond to the source - try changing some of your DROP's to ACCEPT's.
 
Old 04-23-2012, 04:47 AM   #3
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
Based upon your post, here is an example of what I think you are trying to achieve (based upon a policy set to accept, which is safer against self lockout):
Code:
-A INPUT --src 123.123.123.123 -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT --src 123.123.123.123 -m tcp -p tcp --dport 22   -j ACCEPT
-A INPUT --src 456.456.456.456 -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT --src 456.456.456.456 -m tcp -p tcp --dport 22   -j ACCEPT
-A INPUT -m tcp -p tcp --dport 80   -j ACCEPT
-A INPUT -m tcp -p tcp --dport 2900 -j ACCEPT
-j DROP
This will allow '123' and '456' to access 3306 and 22, everyone to access 80 and 2900, everything else is denied.
 
  


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
iptable how many rule iptable can manage toure32 Linux - Networking 1 05-13-2010 04:34 AM
what is an iptable? & how to seperate the network on the basis of iptable vinod.wagh Linux - Networking 1 09-11-2008 01:28 AM
IPTable help tsaravan Linux - Networking 3 08-05-2008 04:05 AM
what is an iptable? Baran Linux - Newbie 7 02-07-2005 05:14 PM
iptable cristi1979 Linux - Networking 4 06-29-2003 05:54 PM

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

All times are GMT -5. The time now is 06:49 PM.

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