LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-21-2016, 03:20 PM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
iptables troubleshooting icmp and best place to log /var/log/messages or /var/log/iptables


So I'm trying monitoring iptables logging (iptables v1.3.5) and troubleshoot icmp issues. I've setup logging with the following:

Code:
iptables -I RH-Firewall-1-INPUT 2 -m limit --limit 1/minute -j LOG --log-prefix ' ## IPTABLES LOGGED ## '
From there, using tail -f messages with the following:

Code:
tail -f /var/log/messages
Currently, the logs are going into /var/log/messages. I've seen others setup logging into /var/log/iptables.

Do I have to create a directory under /var/log for this if I want to switch to this? Create files too, or are those created automatically?

In addition to modifying /etc/syslog.conf with the following

Code:
kern.=debug /var/log/iptables
Is there anything, such as level of logging that needs to be added?


And then I've added a drop rule at the bottom of RH-Firewall-1-INPUT
Code:
iptables -A RH-Firewall-1-INPUT -j DROP
Once I add this, I'm unable to ping servers in my subnet and the various servers and users can't ping back to this server. All other services (SSH/Oracle) work ok.

Here are the rules
Code:
Chain INPUT (policy ACCEPT 0 packets, 0 bytes) 
num pkts bytes target     prot opt in out source  destination 
1   26433 3489k RH-Firewall-1-INPUT all *  *      0.0.0.0/0   0.0.0.0/0 

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) 
num pkts bytes target prot opt in out source destination 
1    0    0    RH-Firewall-1-INPUT all -  *  *   0.0.0.0/0    0.0.0.0/0


Chain OUTPUT (policy ACCEPT 27333 packets, 3733k bytes) 
num  pkts  bytes target  prot opt in out source destination 
1     10   840    ACCEPT  icmp --  *  *  0.0.0.0/0  0.0.0.0/0   icmp type 8 
2     85 23268    ACCEPT  tcp  --  8 eth0 0.0.0.0/0 0.0.0.0/0    multiport sport 22,1158,1521 state ESTABLISHED

Chain RH-Firewwall-1-INPUT (2 references) 
num  pkts  bytes  target  prot opt in out   source       destination 
1    28712  4091k  ACCEPT  all  --  lo  *   0.0.0.0/0    0.0.0.0/0 
2       46  5767   LOG     all  --  *   *   0.0.0.0/0    0.0.0.0/0            limit: avg 1/min burst 5 LOG flags 0 level 4 prefix ' ***IPTABLES LOGGED ****' 
3       0    0     ACCEPT  icmp --  *   *   0.0.0.0/0    0.0.0.0/0            icmp type 0 
4       1   100    ACCEPT   tcp  -- *   *   0.0.0.0/0    0.0.0.0/0            state NEW tcp dpt:22
5     131  9644    ACCEPT   tcp --  eth0 *  192.168.10.0/24 0.0.0.0/0        multiport dports 22,1158,1521 state NEW, ESTABLISHED
6       0   0      ACCEPT    tcp  -- *   *  xxx.xx.xxx.xx  0.0.0.0/0          state NEW,ESTABLISHED tcp dpt:1521 
7     613  59410   DROP     all  --  *   *  0.0.0.0/0      0.0.0.0/0
UPDATE: The logging is picking up alot of broadcast traffic. I believe this traffic is normal, correct?

Last edited by JockVSJock; 01-21-2016 at 03:24 PM.
 
Old 01-22-2016, 11:01 AM   #2
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Can you post your firewall config file /etc/sysconf/iptables?
It is a lot easier to read that file and see the mistakes.

Also what document/web page are you following to log iptables dropped packets?
This one might be of interest to you.
 
Old 01-22-2016, 12:24 PM   #3
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Here is the output from /etc/sysconfig/iptables (forgot about that option for better looking output)

Code:
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [2202:303920]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A OUTPUT -p icmp -m icmp -icmp-type 8 -j ACCEPT 
-A OUTPUT -s 192.168.10.0/255.255.255.0 -o eth0 -p tcp -m multiport --sports 22,1158,1521 -m state --state ESTABLISHED -j ACCEPT 
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -m limit --limit 1/min -j LOG --log-prefix " *** IPTABLES LOGGED ***" 
-A RH-Firewall-1-INPUT -p icmp -m icmp --icmp-type 0 -j ACCEPT 
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT 
-A RH-Firewall-1-INPUT -s 192.168.10.0/255.255.255.0 -i eth0 -p tcp -m multiport --dports 22,1158,1521 -m state --state NEW,ESTABLISHED -j ACCEPT 
-A RH-Firewall-1-INPUT -s xxx.xx.xxx.xx -p tcp -m state --state NEW,ESTABLISHED -m tcp --dport 1521 -j ACCEPT 
-A RH-Firewall-1-INPUT -j DROP 
COMMIT
 
Old 01-25-2016, 03:58 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by JockVSJock View Post
And then I've added a drop rule at the bottom of RH-Firewall-1-INPUT
Code:
iptables -A RH-Firewall-1-INPUT -j DROP
Once I add this, I'm unable to ping servers in my subnet and the various servers and users can't ping back to this server. All other services (SSH/Oracle) work ok.
Best easiest way to post a firewall rule set is to post 'iptables-save' output as any rule file may not reflect the rules currently loaded in memory. Best easiest way to troubleshoot firewall problems is to make specific "-j LOG" rules precede any DROP or REJECT rules. A rule like '-A RH-Firewall-1-INPUT -m limit --limit 1/min -j LOG --log-prefix " *** IPTABLES LOGGED ***"' is not placed logically (though sure you may just want to log everything) and has no filter (remote address, protocol, port, etc, etc) so will catch way too much. Your rule set could be improved I think.
 
Old 01-25-2016, 05:02 PM   #5
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Quote:
Originally Posted by unSpawn View Post
Best easiest way to troubleshoot firewall problems is to make specific "-j LOG" rules precede any DROP or REJECT rules. A rule like '-A RH-Firewall-1-INPUT -m limit --limit 1/min -j LOG --log-prefix " *** IPTABLES LOGGED ***"' is not placed logically (though sure you may just want to log everything) and has no filter (remote address, protocol, port, etc, etc) so will catch way too much. Your rule set could be improved I think.
I thought that putting this rule upfront would be the best that way I could see what packets were hitting up against it.

The odd thing too is that there is alot of broadcast traffic that is getting picked up in /var/log/messages.

I'm always open to feedback for IPTables, how else does one improve?

thanks
 
Old 01-26-2016, 12:49 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Try this?:
Code:
:INPUT ACCEPT [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j REJECT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.10.0/255.255.255.0 -p tcp -m multiport --dports 22,1158,1521 -m state --state NEW -j ACCEPT 
-A RH-Firewall-1-INPUT -s xxx.xx.xxx.xx -p tcp -m state --state NEW -m tcp --dport 1521 -j ACCEPT 
-A RH-Firewall-1-INPUT -s 192.168.10.0/255.255.255.0 -p icmp -m icmp --icmp-type 0 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.10.0/255.255.255.0 -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.10.0/255.255.255.0 -p icmp -m limit --limit 1/sec -j LOG --log-prefix "other_ICMP" 
-A RH-Firewall-1-INPUT -j DROP 
COMMIT
 
Old 02-01-2016, 03:17 PM   #7
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Hers is the current iptables.

Code:
:INPUT ACCEPT [2699:278262]
: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 OUTPUT -p icmp -m icmp --icmp--type 8 -j ACCEPT 
-A OUTPUT -s 192.168.10.0/255.255.255.0 -o eth0 -p tcp -m multiport --sports 22,1158,1521 -m state --state ESTABLISHED -j ACCEPT 
-A OUTPUT -d xxx.xxx.xxx.xxx -p tcp -m state --state NEW,ESTABLISHED -m tcp --dport 1521 -j ACCEPT 
-A RH-Firewall-1-INPUT -i lo -j ACCEPT 
-A RH-Firewall-1-INPUT -p icmp -m icmp --icmp-type 0 -j ACCEPT 
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT 
-A RH-Firewall-1-INPUT -s 192.168.10.0/255.255.255.0 -i eth0 -p tcp -m multiport --dports 22,1158,1521 -m state --state NEW,ESTABLISHED -j ACCEPT 
-A RH-Firewall-1-INPUT -s xxx.xx.xxx.xx -p tcp -m state --state NEW,ESTABLISHED -m tcp --dport 1521 -j ACCEPT 
-A RH-Firewall-1-INPUT -m limit --limit 1/min -j LOG --log-prefix " *** IPTABLES LOGGED **** " 
COMMIT
Come to find out, it wss an issue with VMWare. We have a NIC that faces a public internet, and this system is in a test environment. Daily we turn on the NIC and once we are done for the day, we turn off the NIC. Doing this seems to cause an issue. So we are going to turn off the interface and then the NIC and vice versa daily to see if that will fix the issue.
 
Old 02-02-2016, 12:20 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by JockVSJock View Post
Come to find out, it wss an issue with VMWare. We have a NIC that faces a public internet, and this system is in a test environment. Daily we turn on the NIC and once we are done for the day, we turn off the NIC. Doing this seems to cause an issue.
Why would you turn off that NIC?
 
Old 02-02-2016, 01:29 PM   #9
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Quote:
Originally Posted by unSpawn View Post
Why would you turn off that NIC?
Because it going into our production environment and this server is in our development environment. We want to keep both separate and pure and so when we are doing working with this server, we turn off the NIC in vCenter that points into production. The "xxx.xxx.xxx.xxx" represents the IP address from prod to dev and we want to regulate traffic to only that server only. We are pulling data from production to dev. I've been running Wireshark to monitor the traffic to make sure no one or processes can't get in.

Hopefully thought, you can look at the IPTables that I wrote up and provide feedback.

Last edited by JockVSJock; 02-02-2016 at 01:36 PM.
 
Old 02-03-2016, 04:12 PM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by JockVSJock View Post
provide feedback.
Sure but as I have posted a (what I think would be a sane rule set) rule set I have to first ask you to post your motivation for changing it the way you did.
 
Old 02-03-2016, 06:03 PM   #11
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Here is my motivation per each rule

Code:
-A OUTPUT -p icmp -m icmp --icmp--type 8 -j ACCEPT  #allow icmp echo-reply traffic 
-A OUTPUT -s 192.168.10.0/255.255.255.0 -o eth0 -p tcp -m multiport --sports 22,1158,1521 -m state --state ESTABLISHED -j ACCEPT  #allow for ssh and oracle traffic connections in the development env.  
-A OUTPUT -d xxx.xxx.xxx.xxx -p tcp -m state --state NEW,ESTABLISHED -m tcp --dport 1521 -j ACCEPT  #allow for only oracle traffic from this one server in our production env.  I've since channged NEW, ESTABLISHED to ESTABLISHED, RELATED 
-A RH-Firewall-1-INPUT -i lo -j ACCEPT #allow loopback traffic
-A RH-Firewall-1-INPUT -p icmp -m icmp --icmp-type 0 -j ACCEPT #allow icm echo-request 
-A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT #allow new ssh connections
-A RH-Firewall-1-INPUT -s 192.168.10.0/255.255.255.0 -i eth0 -p tcp -m multiport --dports 22,1158,1521 -m state --state NEW,ESTABLISHED -j ACCEPT  #from the dev environment, allow ssh and oracle traffice 
-A RH-Firewall-1-INPUT -s xxx.xx.xxx.xx -p tcp -m state --state NEW,ESTABLISHED -m tcp --dport 1521 -j ACCEPT #from production, only allow oracle traffic from this one ip address
-A RH-Firewall-1-INPUT -m limit --limit 1/min -j LOG --log-prefix " *** IPTABLES LOGGED **** " #log iptable to /var/log/messages, however I'm finding this is even logging broadcast traffic and other traffic from other servers
COMMIT
 
Old 02-05-2016, 12:29 AM   #12
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by JockVSJock View Post
Here is my motivation per each rule
Thanks for the insight. Here's my rule set explained:

Code:
# 3 lines below are default policies:
:INPUT ACCEPT [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
# 1 line below is a custom chain:
:RH-Firewall-1-INPUT - [0:0]
# this line is typically stock RHEL / CentOS. Serves no purpose here, could filter everything in the "INPUT" chain to simplify things...
-A INPUT -j RH-Firewall-1-INPUT
# You're not (knowingly?) forwarding anything, so let remote hosts know you're not accepting:
-A FORWARD -j REJECT
# Netfilter uses "first rule match" so best order in what traffic is expected to hit the table the most often.
# In essence that's not the loop back device but once you get "lo" out of the way you need not specify the Ethernet
# device name on consecutive rules if you're only running one:
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
# Get any connections already known to Netfilter out of the way:
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# New connections to allow:
-A RH-Firewall-1-INPUT -s 192.168.10.0/255.255.255.0 -p tcp -m multiport --dports 22,1158,1521 -m state --state NEW -j ACCEPT 
-A RH-Firewall-1-INPUT -s xxx.xx.xxx.xx -p tcp -m state --state NEW -m tcp --dport 1521 -j ACCEPT 
# Ping and pong:
-A RH-Firewall-1-INPUT -s 192.168.10.0/255.255.255.0 -p icmp -m icmp --icmp-type 0 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.10.0/255.255.255.0 -p icmp -m icmp --icmp-type 8 -j ACCEPT
# Log any ICMP traffic only that's not type 0 or 8:
-A RH-Firewall-1-INPUT -s 192.168.10.0/255.255.255.0 -p icmp -m limit --limit 1/sec -j LOG --log-prefix "other_ICMP" 
# DROP anything else in the chain:
-A RH-Firewall-1-INPUT -j DROP 
# OUTPUT chain is empty as default policy already is ACCEPT:
COMMIT
If there's two things you should take away from this it's that rule ordering matters and that you need to apply filters carefully. This rule is what you could call a "greedy match" filter as it doesn't limit to either remote addresses or protocols and therefore matches everything:
Code:
-A RH-Firewall-1-INPUT -m limit --limit 1/min -j LOG --log-prefix " *** IPTABLES LOGGED **** "
(+ in your case due to rule ordering: matches everything that isn't already dealth with by ACCEPT, REJECT or DROP targets.)
 
1 members found this post helpful.
Old 02-08-2016, 03:15 PM   #13
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
So I took your advice:

- dropped reject statement from the Forward Rule, because it makes no sense to reply to something that is not being forwarded


However, more questions.

- it sounds like the important traffic (22, 1521), those rules should be closer to the top, correct?

- the rules for loopback and icmp, should be closer to the bottom. The traffic is important, however it can lower to the bottom, correct?

- A INPUT -j RH-Firewall-1-INPUT. I'm confused. I believe that I've asked this question on here, however it sounds like the RH-Firewall-1-INPUT rule is redundant and can be handled by INPUT. If so, how does one fix this in the future? Can you just delete the RH-Firewall-1-INPUT and all rules that were under this, just move under the INPUT rule? Also deleted any references of RH-Firewall-1-INPUT in FORWARD and OUTPUT?

- I don't understand your statement on the logging that I have setup, can you please clarify?

thanks

Last edited by JockVSJock; 02-08-2016 at 03:20 PM.
 
Old 02-09-2016, 09:03 AM   #14
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
RH-Firewall-1-INPUT is Redhat's way of trying to be fancy. You can move all your rules to INPUT and then delete the entire chain of RH-Firewall-1-INPUT from your rules.

The first rule should always be ESTABLISHED,RELATED as this is the rule that is always hit after a connection is established. I try to order my rules in numerical order make for finding things a lot easier. I usually place the lo rule right after the ESTABLISHED,RELATED rule followed by the ICMP rules as they is no established connection for them.
 
Old 02-10-2016, 12:23 PM   #15
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by JockVSJock View Post
it sounds like the important traffic (22, 1521), those rules should be closer to the top, correct?
Yes but below the loopback and the ESTABLISHED,RELATED rule.


Quote:
Originally Posted by JockVSJock View Post
the rules for loopback and icmp, should be closer to the bottom.
Not if you look at my rule set. Loop back should be first. I explained that. If you can't wrap your head around that just take it as a given.


Quote:
Originally Posted by JockVSJock View Post
it sounds like the RH-Firewall-1-INPUT rule is redundant and can be handled by INPUT.
Yes, as said by lazydog. BTW "move" just means 'sed -i "s|RH-Firewall-1-||g" /etc/sysconfig/iptables && iptables-restore < /etc/sysconfig/iptables;' (your choice of making a backup or not).


Quote:
Originally Posted by JockVSJock View Post
Also deleted any references of RH-Firewall-1-INPUT in FORWARD and OUTPUT?
What do you not "get" from the "OUTPUT chain is empty as default policy already is ACCEPT" explanation? If you accept all traffic then explicit "ACCEPT" rules make no sense. They accomplish nothing.


Quote:
Originally Posted by JockVSJock View Post
I don't understand your statement on the logging that I have setup, can you please clarify?
You are interested in ICMP messages. However your logging rule does not filter anything. If you do not filter then you get all traffic.
 
  


Reply

Tags
icmp, iptables, logging



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
Log iptables drop packet to file but not /var/log/messages? kikilinux Linux - Security 1 10-02-2012 09:42 AM
[SOLVED] No /var/log/messages , syslog , kern.log -but cat /var/spool/octopussy/octo_fifo masuch Linux - Newbie 4 06-13-2012 08:05 PM
Deleted /var/log/messages, can't log any files-iptables chingyenccy Linux - Newbie 7 02-27-2005 04:03 PM
iptables and /var/log/messages Obie Linux - Security 5 08-18-2004 02:02 AM
iptables, changing log file from /var/log/messages acid2000 Linux - Networking 3 03-11-2003 08:38 PM

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

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