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 07-23-2010, 05:31 AM   #1
Emil M
LQ Newbie
 
Registered: Feb 2010
Posts: 25

Rep: Reputation: 0
Can't see source on first SSH entry in iptables


Now I managed to get iptables to work with my OpenVZ configurations and everything seems to work as it should. However when I run iptables -L I can only see source for the second SSH rule, why isn't the first ones source/IP shown?

Also if you have any comments about the setup feel free :-)
I'm running SSH, Apache and local MySQL

The xxx.xxx is simply to hide my IP's

Code:
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

iptables -F
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
iptables -F -t mangle
iptables -X

iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -d 127.0.0.0/8 -j REJECT

iptables -A INPUT -p tcp --dport 22 -s 77.213.xxx.xxx -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -s 62.198.xxx.xxx -j ACCEPT

iptables -A INPUT -p tcp --dport 80 -j ACCEPT

iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT

iptables -A INPUT -m state --state INVALID -j REJECT
iptables -A INPUT -j REJECT

iptables -A INPUT -j DROP
 
Old 07-23-2010, 05:58 AM   #2
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by Emil M View Post
Now I managed to get iptables to work with my OpenVZ configurations and everything seems to work as it should. However when I run iptables -L I can only see source for the second SSH rule, why isn't the first ones source/IP shown?

Also if you have any comments about the setup feel free :-)
I'm running SSH, Apache and local MySQL

The xxx.xxx is simply to hide my IP's

Code:
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

iptables -F
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
iptables -F -t mangle
iptables -X

iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -d 127.0.0.0/8 -j REJECT

iptables -A INPUT -p tcp --dport 22 -s 77.213.xxx.xxx -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -s 62.198.xxx.xxx -j ACCEPT

iptables -A INPUT -p tcp --dport 80 -j ACCEPT

iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT

iptables -A INPUT -m state --state INVALID -j REJECT
iptables -A INPUT -j REJECT

iptables -A INPUT -j DROP
run iptables -L -n -v (do not resolve ips & show packet counters)
why the drop rule after the reject? nothing will reach that rule anyway.
add a chain for logging anything that is dropped if you plan to go with the DROP. that is good for troubleshooting purposes.
 
Old 07-23-2010, 07:25 AM   #3
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by Emil M View Post
Also if you have any comments about the setup feel free :-)
You've got this rule:
Quote:
Code:
iptables -A INPUT -m state --state INVALID -j REJECT
...but some packets in INVALID state would already match the rules above it, so you're essentially filtering packets in state INVALID only if they weren't sent to ACCEPT. If your intention is to keep out all packets in state INVALID, you should move the rule upward. I'd also suggest adding a match for packets in state RELATED (to handle things such as ICMP errors, which can be very useful) and NEW, which would eliminate the need to match for state INVALID since they'll get caught at the end of the chain. BTW, I second centosboy's recommendation of logging everything that is filtered. Example of all of this:
Code:
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp -i eth0 --dport 22 -s 77.213.xxx.xxx -m state --state NEW -j ACCEPT
iptables -A INPUT -p tcp -i eth0 --dport 22 -s 62.198.xxx.xxx -m state --state NEW -j ACCEPT
iptables -A INPUT -p tcp -i eth0 --dport 80 -m state --state NEW -j ACCEPT
iptables -A INPUT -j LOG --log-prefix "INPUT DROP: "
iptables -A INPUT -j DROP
 
Old 07-23-2010, 08:23 AM   #4
unixfool
Member
 
Registered: May 2005
Location: Northern VA
Distribution: Slackware, Ubuntu, FreeBSD, OpenBSD, OS X
Posts: 782
Blog Entries: 8

Rep: Reputation: 158Reputation: 158
Quote:
Originally Posted by centosboy View Post
add a chain for logging anything that is dropped if you plan to go with the DROP. that is good for troubleshooting purposes.
I'd only do this if you have the resources. I've no idea where this FW is at and how much traffic it is processing, but in the professional world, logging of the catch-all rule is usually disabled to free up drive space and system logging resources (if logging is needed for troubleshooting purposes, it is enabled when needed). This is also sometimes helpful in the case of DoS or large scale events where the firewall is doing fine (acting within parameters) but the OS behind it is barely coping with the load of tracking each hit (logged or not). Sometimes the additional load of logging can negatively impact a FW.

This is more of a personal preference, I guess, but I find that if a FW admin always has 'best practices' as a focus, even with FWs monitoring small network segments, it helps a TON when the job of administrating FWs that track large network segments. Basically, it won't hurt to log on the deny rule, as long as there's proper system resources...just be prepared to be stupified when the system is acting quirky when trying to handle large loads.

Last edited by unixfool; 07-23-2010 at 08:35 AM.
 
Old 07-23-2010, 10:39 AM   #5
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Yeah, I'd recommend the use of the limit match module if performance and/or resource issues arise or are expected. Using DROP/REJECT rules within the chain (in order to filter certain packets while keeping them away from the LOG rule) is also an option.
 
Old 07-23-2010, 11:17 AM   #6
Emil M
LQ Newbie
 
Registered: Feb 2010
Posts: 25

Original Poster
Rep: Reputation: 0
Thanks for all the replies have got a better understanding now and think I've come up with a proper configuration

Code:
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

iptables -F
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
iptables -F -t mangle
iptables -X

iptables -A INPUT -m state --state INVALID -j REJECT

iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT

iptables -A INPUT -d 127.0.0.0/8 -j REJECT

iptables -A INPUT -p tcp --dport 22 -s 77.213.xxx.xxx -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -s 62.198.xxx.xxx -j ACCEPT


iptables -A INPUT -p tcp --dport 80 -j ACCEPT

iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -j DROP
.. however log says "No chain/target/match by that name" but that could be because I need to modprobe something on the host node, but if I don't plan to investigate log files that much, is it really something I should do?

Last edited by Emil M; 07-23-2010 at 11:18 AM.
 
Old 07-24-2010, 05:17 AM   #7
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by Emil M View Post
Thanks for all the replies have got a better understanding now and think I've come up with a proper configuration

Code:
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

iptables -F
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
iptables -F -t mangle
iptables -X

iptables -A INPUT -m state --state INVALID -j REJECT

iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT

iptables -A INPUT -d 127.0.0.0/8 -j REJECT

iptables -A INPUT -p tcp --dport 22 -s 77.213.xxx.xxx -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -s 62.198.xxx.xxx -j ACCEPT


iptables -A INPUT -p tcp --dport 80 -j ACCEPT

iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -j DROP
.. however log says "No chain/target/match by that name" but that could be because I need to modprobe something on the host node, but if I don't plan to investigate log files that much, is it really something I should do?


Code:
iptables -N LOG_DROP
iptables -A LOG_DROP -j LOG --log-prefix "dropped packet" --limit 5/min
iptables -A LOG_DROP -j DROP
logging 5 entries a minute would not bother your resources too much, but it is not really a requirement, just good for troubleshooting.
[/code]
 
  


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
need explanation on an iptables entry slackamp Fedora 4 11-07-2007 07:00 PM
eth0 -> wlan0 IPtables entry not working SekurityKlown Linux - Networking 1 07-30-2007 05:42 AM
Need help with LOG entry in IPTABLES sergio3986 Linux - Networking 5 12-12-2003 02:59 PM
strange iptables entry jimieee Linux - Networking 2 11-10-2003 10:31 AM
iptables log entry??? bulliver Linux - Security 2 02-15-2003 10:54 PM

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

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