WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: {SOLVED] How can iptables log what it blocks in a TC gateway  (Read 3248 times)

Offline Ulysses_

  • Full Member
  • ***
  • Posts: 232
{SOLVED] How can iptables log what it blocks in a TC gateway
« on: October 18, 2011, 04:19:17 PM »
Starting with TC's CD and installing the iptables extension. What should be added to /opt/bootlocal.sh in order for iptables to log everything that it blocks? 

TC is set up fine as a whitelisting gateway with these in /opt/bootlocal:

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -I FORWARD -p tcp -j DROP
iptables -I FORWARD -p tcp -d 1.1.1.1 -j ACCEPT
iptables -I FORWARD -p tcp -s 1.1.1.1 -j ACCEPT
syslogd

1.1.1.1 is the only IP allowed to connect to/from through this gateway. Everything else is blocked and must be logged. How do you get iptables to log what it blocks above?
« Last Edit: October 21, 2011, 05:13:04 PM by Ulysses_ »

Offline Ulysses_

  • Full Member
  • ***
  • Posts: 232
Re: How can iptables log what it blocks in a TC gateway
« Reply #1 on: October 18, 2011, 06:05:00 PM »
If this is of any use, syslogd is known to be running alright - dnsmasq.tcz can run while logging to /var/log/messages.

What else is needed?  Tried the following line after the DROP line but nothing appeared at /var/log/messages:

iptables -I FORWARD -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: How can iptables log what it blocks in a TC gateway
« Reply #2 on: October 19, 2011, 03:27:20 AM »
It should be ok. Perhaps the limit interferes, or some other rule. When you list the rules (iptables -L -v -n), does the log target counter get hits?
The only barriers that can stop you are the ones you create yourself.

Offline Ulysses_

  • Full Member
  • ***
  • Posts: 232
Re: How can iptables log what it blocks in a TC gateway
« Reply #3 on: October 19, 2011, 04:15:14 PM »
Every time I type "iptables -L -v -n" the output changes by only the INPUT line, that line shows more packets and bytes.  No change in the LOG line.  Is this what you mean?

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: How can iptables log what it blocks in a TC gateway
« Reply #4 on: October 19, 2011, 04:18:10 PM »
Yes. That means there's nothing to be logged; either no such hits, or they are dropped before logging.
The only barriers that can stop you are the ones you create yourself.

Offline Ulysses_

  • Full Member
  • ***
  • Posts: 232
Re: How can iptables log what it blocks in a TC gateway
« Reply #5 on: October 19, 2011, 04:27:20 PM »
Here's the complete output of iptables -L -v -n.  Is it saying that something should appear in /var/log/messages?


Offline Ulysses_

  • Full Member
  • ***
  • Posts: 232
Re: How can iptables log what it blocks in a TC gateway
« Reply #6 on: October 19, 2011, 04:40:30 PM »
When the LOG line starts with 2 20, doesn't that mean that 2 packets or 120 bytes were logged? Logged before iptables -L -v -n was run, some time when the gateway was being used by another pc?
« Last Edit: October 19, 2011, 04:42:50 PM by Ulysses_ »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: How can iptables log what it blocks in a TC gateway
« Reply #7 on: October 20, 2011, 06:00:33 AM »
There should've been two lines logged. The byte count is irrelevant to logging.

The counts don't get zeroed by listing them, there's another iptables flag for that.

edit: I tried your log rule, it worked fine for me, got the right output in /var/log/messages.
« Last Edit: October 20, 2011, 06:06:23 AM by curaga »
The only barriers that can stop you are the ones you create yourself.

Offline Ulysses_

  • Full Member
  • ***
  • Posts: 232
Re: How can iptables log what it blocks in a TC gateway
« Reply #8 on: October 20, 2011, 01:40:18 PM »
Did you get it working in FORWARD ie in a gateway?

Was it the TC 3.8.4 it worked on?

Did you put any options in the syslogd command when you launched it?

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: How can iptables log what it blocks in a TC gateway
« Reply #9 on: October 20, 2011, 02:01:34 PM »
TC 4.0.2, clean rules table, and in the output chain for easy testing. I used the syslog bootcode.

edit: Ah, I see now. You're not running klogd, and iptables logs go there.
The only barriers that can stop you are the ones you create yourself.

Offline Ulysses_

  • Full Member
  • ***
  • Posts: 232
[SOLVED] Re: How can iptables log what it blocks in a TC gateway
« Reply #10 on: October 21, 2011, 05:12:43 PM »
Sorted. It was klogd that had to be running.

So the syslog bootcode activates klogd too, together with syslogd and who knows what else.

Using the logs a script has now been completed that turns a gateway into a whitelisting firewall where the rules are either domain-name-based or IP-based.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: {SOLVED] How can iptables log what it blocks in a TC gateway
« Reply #11 on: October 22, 2011, 05:54:32 AM »
tc-config:
Quote
if [ -n "$SYSLOG" ]; then
         /sbin/syslogd && echo "${GREEN}syslog started.${NORMAL}"
         /sbin/klogd && echo "${GREEN}klog started."
fi
The only barriers that can stop you are the ones you create yourself.