This is a text-only version of the following page on https://raymii.org: --- Title : Syslog configuration for remote logservers for syslog-ng and rsyslog, both client and server Author : Remy van Elst Date : 21-06-2018 URL : https://raymii.org/s/tutorials/Syslog_config_for_remote_logservers_for_syslog-ng_and_rsyslog_client_server.html Format : Markdown/HTML --- ![][1] > A Teletype ASR-33 printing system output Syslog is the protocol, format (and software) linux and most networking devices use to log messages. All kinds of messages, system, authentication, login and applications. There are multiple implementations of syslog, like syslog-ng and rsyslog. Syslog has the option to log to a remote server and to act as a remote logserver (that receives logs). With a remote logging server you can archive your logs and keep them secure (when a machine gets hacked, if root is compromised the logs on the machine are no longer trustworthy). This tutorial shows how to set up a syslog server with rsyslog and syslog-ng and shows how to setup servers as a syslog client (that log to a remote server) with syslog-ng and rsyslog. <p class="ad"> <b>Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below:</b><br><br> <a href="https://leafnode.nl">I'm developing an open source monitoring app called Leaf Node Monitoring, for windows, linux & android. Go check it out!</a><br><br> <a href="https://github.com/sponsors/RaymiiOrg/">Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs.</a><br><br> <a href="https://www.digitalocean.com/?refcode=7435ae6b8212">You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $100 credit for 60 days. </a><br><br> </p> ### 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 they both work just as well. The below steps are to be taken to setup rsyslog as a syslog 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 10G drwxr-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) before the logs and folder appear under `/var/log/remote`. #### Logrotate As you can see logging can take up some space, I recommend to setup logrotate for this remote folder. You can do so on Ubuntu by creating the following logrotate 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 (3 months). 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 will be 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 the following 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: * `/etc/rsyslog.conf` * `/etc/rsyslog.d/99-remote.conf` 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 OpenSUSE next to systemd's journald and on [HP-UX][3]. Most older distro's use it as well, 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 the following 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 the documentation, there is no option to limit on subnet like rsyslog has in the above example. Use the firewall to allow access from different networks. With syslog-ng it is also recommended to setup logrotate and compression. See the rsyslog server section on how to do that. ### Client: syslog-ng The setup for sending logs to a remote syslog server is simple. Edit the `syslog-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 older `tcp()` 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 are using `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 including logging. Most distro's supply a syslog service which journald (systemd's binary logging component) forwards logs to. If your system is not set up like that, you need to install either rsyslog or syslog-ng and tell journald to forward the logs 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 will now appear in syslog as well. [1]: /s/inc/img/teletype_asr33.jpg [2]: https://www.digitalocean.com/?refcode=7435ae6b8212 [3]: https://raymii.org/s/tags/hp-ux.html --- License: All the text on this website is free as in freedom unless stated otherwise. This means you can use it in any way you want, you can copy it, change it the way you like and republish it, as long as you release the (modified) content under the same license to give others the same freedoms you've got and place my name and a link to this site with the article as source. This site uses Google Analytics for statistics and Google Adwords for advertisements. You are tracked and Google knows everything about you. Use an adblocker like ublock-origin if you don't want it. All the code on this website is licensed under the GNU GPL v3 license unless already licensed under a license which does not allows this form of licensing or if another license is stated on that page / in that software: This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. Just to be clear, the information on this website is for meant for educational purposes and you use it at your own risk. I do not take responsibility if you screw something up. Use common sense, do not 'rm -rf /' as root for example. If you have any questions then do not hesitate to contact me. See https://raymii.org/s/static/About.html for details.