Skip to main content

Raymii.org Logo (IEC resistor symbol)logo

Quis custodiet ipsos custodes?
Home | About | All pages | RSS Feed | Gopher

Syslog configuration for remote logservers for syslog-ng and rsyslog, both client and server

Published: 21-06-2018 | Author: Remy van Elst | Text only version of this article


Table of Contents


A Teletype ASR-33 printing system output

Syslog is the protocol, format (and software) linux and most networking devicesuse to log messages. All kinds of messages, system, authentication, login andapplications. There are multiple implementations of syslog, like syslog-ng andrsyslog. Syslog has the option to log to a remote server and to act as a remotelogserver (that receives logs). With a remote logging server you can archiveyour logs and keep them secure (when a machine gets hacked, if root iscompromised the logs on the machine are no longer trustworthy). This tutorialshows how to set up a syslog server with rsyslog and syslog-ng and shows how tosetup servers as a syslog client (that log to a remote server) with syslog-ngand rsyslog.

If you like this article, consider sponsoring me by trying out a Digital OceanVPS. With this link you'll get $100 credit for 60 days). (referral link)

Server: rsyslog

rsyslog is the default syslog service on Ubuntu, Debian, OpenSUSE and CentOS(next to systemd's journald). The configuration syntax is simpler than syslog-ng's, but complex configuration is more clear in syslog-ng. Bottom line theyboth work just as well. The below steps are to be taken to setup rsyslog as asyslog service to receive syslogs.

Edit the following file:

vim /etc/rsyslog.d/10-remote.conf 

Add the following:

$ModLoad imudp$UDPServerRun 514$AllowedSender UDP, 192.0.2.0/24$template RemoteStore, "/var/log/remote/%HOSTNAME%/%timegenerated:1:10:date-rfc3339%":source, !isequal, "localhost" -?RemoteStore:source, isequal, "last" ~

This will allow all hosts in the subnet 192.0.2.0/24 to log to this machine.

Restart rsyslog to make the changes active:

service rsyslog restart

The files will be placed in /var/log/remote, sorted on hostname. For example:

 ls -la /var/log/remote/server1.example.net/

Output:

total 10Gdrwxr-xr-x 2 syslog syslog 4.0K Jun 19 08:44 .drwxr-xr-x 4 syslog syslog 4.0K Jun 13 13:54 ..-rw-r----- 1 syslog adm    2.6G Jun 14 23:59 2018-06-14-rw-r----- 1 syslog adm    2.5G Jun 15 23:59 2018-06-15-rw-r----- 1 syslog adm    1.4G Jun 16 23:59 2018-06-16-rw-r----- 1 syslog adm    1.3G Jun 17 23:59 2018-06-17-rw-r----- 1 syslog adm    1.1G Jun 18 23:59 2018-06-18-rw-r----- 1 syslog adm    1.5G Jun 19 16:23 2018-06-19

When you just configured a client, it will take some time (a few minutes) beforethe logs and folder appear under /var/log/remote.

Logrotate

As you can see logging can take up some space, I recommend to setup logrotatefor this remote folder. You can do so on Ubuntu by creating the followinglogrotate config file:

vim /etc/logrotate.d/remote

Contents:

/var/log/remote/*/*{        rotate 90        daily        missingok        compress}

This will compress and rotate logs every day and keep them for 90 days (3months). To test your config, use the following command:

logrotate -d --force /etc/logrotate.d/remote

(that will rotate all your logs, don't CTRL+C it otherwise your log folder willbe messed up)

You don't have to restart a service since logrotate is ran via cron(/etc/cron.daily/logrotate).

Client: rsyslog (Ubuntu)

On Ubuntu or any rsyslog server, to log to a remote syslogserver, add thefollowing to rsyslog.conf:

    *.*   @192.0.2.10:514

(Replace 192.0.2.10 with the IP or hostname of your syslog server)

The file can be either:

Restart rsyslog to make the changes active:

service rsyslog restart

Server: syslog-ng

syslog-ng is the default on older versions of SUSE Enterprise Linux and OpenSUSEnext to systemd's journald and on HP-UX. Most older distro's use it aswell, Debian, Fedora and Arch all had it as their default years ago.

To set up syslog-ng as a remote log server that can receive logs, edit thefollowing file:

vim /etc/syslog-ng/syslog-ng.conf

Add or edit:

source net { udp(); };destination remote { file("/var/log/remote/${FULLHOST}"); };log { source(net); destination(remote); };

This file can also be in /etc/syslog-ng/conf.d/ under a different name.Restart syslog-ng to make the changes active:

service syslog-ng restart

This will place the logfiles in /var/log/remote. As far as I could find in thedocumentation, there is no option to limit on subnet like rsyslog has in theabove example. Use the firewall to allow access from different networks.

With syslog-ng it is also recommended to setup logrotate and compression. Seethe rsyslog server section on how to do that.

Client: syslog-ng

The setup for sending logs to a remote syslog server is simple. Edit thesyslog-ng.conf file:

vim /etc/syslog-ng/syslog-ng.conf

Add or edit the following:

destination remote { network("192.0.2.10" transport("udp") port(514)); };

Older versions do not support the network() syntax, you need to use the oldertcp() or udp() syntax:

destination remote { udp("192.0.2.10" port(514)); };

In both cases, replace 192.0.2.10 with your logserver's IP. (Unless you areusing TEST-NET-1 of course).

This file can also be in /etc/syslog-ng/conf.d/ under a different name.Restart syslog-ng to make the changes active:

service syslog-ng restart

What about systemd / journald?

Systemd and journald are taking over every part of your linux system includinglogging. Most distro's supply a syslog service which journald (systemd's binarylogging component) forwards logs to. If your system is not set up like that, youneed to install either rsyslog or syslog-ng and tell journald to forward thelogs to syslog:

vim /etc/systemd/journald.conf 

Add or change:

ForwardToSyslog=yes

Restart journald:

systemctl restart systemd-journald

If your syslog-ng or rsyslog version is recent enough, all journald logs willnow appear in syslog as well.

Tags: hp-ux, log, logging, opensuse, rsyslog, security, sles, suse, syslog, syslog-ng, tutorials