3

Is there a log in centos servers that records every connection to/from?

so something like a centralized connections log

2 Answers 2

3

The only sure way to get a single centralized log of all TCP connections would be to add LOG rules to your iptables software firewall configuration that would log any packet with a SYN and ACK bits set, i.e. the second packet of any TCP connection. These would appear as kernel log messages in /var/log/messages by default.

Please see this question at Server Fault.SE.

Essentially you would want to add iptables rules like this:

iptables -A OUTPUT -p tcp --tcp-flags SYN,ACK SYN,ACK -j LOG --log-prefix "Inbound connection established: "
iptables -A INPUT -p tcp --tcp-flags SYN,ACK SYN,ACK -j LOG --log-prefix "Outbound connection established: "

(You may want to place these rules in your existing ruleset so that they won't apply to the loopback interface, as that might generate two entries for each local connection between application processes within the host.)

And yes, the rule in OUTPUT chain records inbound connections and vice versa, because this will only log connections that are actually being responded to: recording just the SYN packets would also record connection attempts that will be rejected. Because of port scans executed by malware-ridden systems on the internet, that would often give you a lot of useless log entries: you would have to cross-check with other logs, only to find out that either you don't have such a service running at all, or that the connection was rejected by another iptables rule or by the service in question.

For UDP protocols it's trickier, because UDP is connectionless and basically just a platform on which an application-specific protocol can be built. So there is no easy way to detect "the first packet of a connection" or anything like that, because all that will be entirely application-specific.

1

I think this should do it:

journalctl -fu sshd

or

journalctl -u sshd -n 100

That is, if you're running systemd, which I think is default. The former will keep a watch. The latter is equivalent to piping through tail.

(Reading around seems to indicate that the logs should actually be in /var/log/secure)

3
  • root@server1 [~]# journalctl -fu sshd -bash: journalctl: command not found root@server1 [~]# journalctl -u sshd -n 100 -bash: journalctl: command not found
    – Benn
    Commented Jun 11, 2016 at 8:02
  • and doesn't /var/log/secure only record ssh connections?
    – Benn
    Commented Jun 11, 2016 at 8:03
  • Yes on /var/log/secure. I wasn't paying enough attention. As for journalctl, what version centos do you run? See here. That would have been able to give you any connection.
    – Diagon
    Commented Jun 11, 2016 at 8:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .