LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-26-2011, 12:35 PM   #1
x201s
Member
 
Registered: Dec 2010
Posts: 67

Rep: Reputation: 0
IPTables- revisited


I have been learning these tricks recently, often the hard way. More than often, I am locked out from accessing the remote server.

I have the following lines in my iptables. I think I need to add some ins and outs, because right now, I am allowing all outbound traffic.

I want to add a line somewhere that makes sure that I have ssh access (local access) even if I screw up things in the following lines.

I am using RHEL 5.6.

(1) What line, and where do I add? Gurus, please help.

Code:
*filter
:INPUT DROP [0:0]
:OUTPUT DROP [0:0]
:FORWARD DROP [0:0]
:myFirewall_Input - [0:0]
-A INPUT -j myFirewall_Input


#### Output Chain add ###
:myFirewall_Output - [0:0]
-A OUTPUT -j myFirewall_Output 

#loopback
-A myFirewall_Input -i lo -j ACCEPT

#ping 
-A myFirewall_Input -p icmp --icmp-type 8 -s <IP> -j ACCEPT
-A myFirewall_Output -p icmp --icmp-type 8 -s <IP> -j ACCEPT


#ssh local only
-A myFirewall_Input -m tcp -p tcp -s <IP> --dport 22 -j ACCEPT
-A myFirewall_Input -m tcp -p tcp -s <IP> --dport 22 -j ACCEPT



#80 is ok from all
-A myFirewall_Input -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT


#outgoing is unrestricted
-A myFirewall_Output -m tcp -p tcp -s <IP> -j ACCEPT
(2)
I do not know if I have things that is not necessary and/or things I better have considering security.

I mean, if I have this for ping:
-A myFirewall_Input -p icmp --icmp-type 8 -s <IP> -j ACCEPT
do I need this?
-A myFirewall_Output -p icmp --icmp-type 8 -s <IP> -j ACCEPT

same for the ssh.

(3)I want to define a variable for IP and use that variable throughout. Currently, I am using real numbers for <IP>

I want to define like:
hostIP = "nnn.nnn.nnn.nnn"
and later on, say,
-A myFirewall_Output -p icmp --icmp-type 8 -s $hostIP -j ACCEPT

Question (1) is very important for me-- I don't want to go to the server room everytime I make mistake. (3) is just for convenience, nice to have, but can do w/o. (2) is in between.

Thank you for taking time to read.
 
Old 02-26-2011, 12:56 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
1) What is "local" access? you have your "ssh" part already, so you'd just add in the right source network for whatever suits "local" I guess. Actually you might be wanting a separate point of entry here, and so I'd suggest putting this outside of your "MyFirewall" chains, if you put the accept at the top of the INPUT chain then you have a nice logical separation from that and your experiments.

2) Well normally your OUTPUT policy would be a default ACCEPT, so is probably not required because of that.

3) that's not a question.. yes you can do that, it's just bash though, nothing to do with iptables itself.

you're firewall is, as I'm sure you'll appreciate, pretty crude. There's no connection tracking at all, you should really only be allowing NEW connections on these certain services, and from then on all existing connections.
 
Old 02-26-2011, 04:14 PM   #3
x201s
Member
 
Registered: Dec 2010
Posts: 67

Original Poster
Rep: Reputation: 0
(1) by local, I mean, allow ssh only from withing our LAN.
>I'd suggest putting this outside of your "MyFirewall" chains
yes, that's what I want to do, but
(a) where do I put it? just before :INPUT DROP [0:0]? or even before *filter?
(b) and how do I write it?
iptables -A INPUT -p tcp -s <local lan IP> --dport 22 -j ACCEPT?

(2) yes, I have also read many times, that outgoing defauts to ACCEPT, but our people here want to run a tighter ship, so I will be adding a lot of OUTPUT chains.
(3) since this is not a bash script, then I am out of luck?
(4) connection tracking: do you mean I add "-m state --state NEW" for ping, ssh (access through port 80 already has this string)?

Thank you for comments.
 
Old 02-26-2011, 04:27 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
ahh right, ok so literally the line before the INPUT that sends everything to your own chain. That format seems fine, it should be only for state NEW packets though.

I would think that filtering outbound access is generally pointless even in most "tighter ships". Presumably all outbound traffic will hit either a physical firewall or the INPUT on another box. Those are the places to filter.

ah, yeah, not possible there, but you can do things like use other chains to fire certain traffic at, and in them define that IP address minimal times, if that logic holds true.

checking the NEW state is half of it yes, the other half is then to permit ESTABLISHED and RELATED as a first rule in the INPUT chain, to quickly allow all traffic that you've previously allowed to be created.
 
Old 02-27-2011, 12:00 AM   #5
x201s
Member
 
Registered: Dec 2010
Posts: 67

Original Poster
Rep: Reputation: 0
Added:
-A INPUT -m state --state NEW -p tcp -s <local lan IP> --dport 22 -j ACCEPT
just after * filter. so far so good.

Yes, I do have
-A myFirewall_Input -m state --state ESTABLISHED -j ACCEPT, which I had forgotton to include in the first post.

Thanks again.
 
  


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
Linux revisited ! iknight LinuxQuestions.org Member Intro 4 08-08-2006 01:20 PM
Redundancy revisited... again. itsjustme General 1 12-14-2005 10:13 AM
boot disk revisited.... nitk Linux - Newbie 5 10-20-2003 11:25 PM
Advertising (no doubt revisited) jkcunningham LQ Suggestions & Feedback 2 06-16-2003 11:35 AM
Fonts...revisited! rootlinux Linux - General 1 03-31-2002 10:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:58 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