Install a syslog server on Ubuntu (rsyslog)
When to use this: You want a free, reliable syslog server on Ubuntu that stores each device's logs in its own daily file.
Before you start
Steps
-
Install rsyslog (it is usually preinstalled)
terminalsudo apt update sudo apt install -y rsyslogUbuntu normally ships rsyslog already. This makes sure it is present and current.
-
Create the folder for remote logs
terminalsudo mkdir -p /var/log/remote sudo chown syslog:adm /var/log/remote sudo chmod 750 /var/log/remotersyslog runs as user
syslogand cannot create folders directly under/var/log, so create it first. -
Add the receiver configuration
terminalsudo tee /etc/rsyslog.d/10-remote.conf > /dev/null <<'EOF' # Listen for syslog from the network module(load="imudp") input(type="imudp" port="514") module(load="imtcp") input(type="imtcp" port="514") # One folder per sender IP, one file per day template(name="PerHostDaily" type="string" string="/var/log/remote/%fromhost-ip%/%$year%-%$month%-%$day%.log") # Keep arrival time and sender IP, then the original line template(name="LineFmt" type="string" string="%timegenerated:::date-rfc3339% %fromhost-ip% %rawmsg%\n") # Everything not from this machine goes to the per-host files and stops there if $fromhost-ip != '127.0.0.1' then { action(type="omfile" dynaFile="PerHostDaily" template="LineFmt" dirCreateMode="0750" fileCreateMode="0640") stop } EOFOpens UDP and TCP 514, writes each sender to
/var/log/remote/<sender-ip>/<date>.log, and keeps those messages out of the local/var/log/syslog. The file starts with10-so it runs before Ubuntu's default rules.Check the heredoc kept its indentation. If you pasted with leading spaces, rsyslog still accepts them, but the
EOFline must be at the start of the line. -
Check the configuration syntax
terminalsudo rsyslogd -N1Validates the config without restarting. Fix any error before continuing.
Expected output
rsyslogd: version 8.x, config validation run (level 1), master config /etc/rsyslog.conf rsyslogd: End of config validation run. Bye.
-
Restart and confirm it is listening
terminalsudo systemctl restart rsyslog sudo ss -lunp | grep ':514' sudo ss -ltnp | grep ':514'-lunlists UDP listeners and-ltnTCP ones. You should see rsyslogd on port 514 in both. -
Open the firewall for your senders only
terminalsudo ufw allow from 192.168.1.1 to any port 514 proto udp sudo ufw allow from 192.168.1.1 to any port 514 proto tcp sudo ufw statusReplace
192.168.1.1with each sender's IP. Skip this ifufwis not enabled, but then make sure another firewall limits access. -
Send a test message from another machine
terminallogger -n 192.168.1.10 -P 514 -d "syslog test from $(hostname)"Run it on any Linux box (replace the server IP).
-duses UDP. Then read the file on the server in the next step. -
Read the received logs
terminalls /var/log/remote/ sudo tail -f /var/log/remote/*/$(date +%Y-%m-%d).logYou should see a folder per sender IP and new lines arriving. Press Ctrl+C to stop.
-
Set up retention (compress after 1 day, delete after 90)
terminalsudo tee /etc/cron.daily/remote-logs-clean > /dev/null <<'EOF' #!/bin/sh find /var/log/remote -type f -name '*.log' -mtime +1 -exec gzip -q {} \; find /var/log/remote -type f -name '*.gz' -mtime +90 -delete EOF sudo chmod +x /etc/cron.daily/remote-logs-cleanChange
90to your retention in days. Text logs typically compress very well, which saves disk.
How to verify it worked
ssshows rsyslogd on port 514 (UDP and TCP).- A test message creates
/var/log/remote/<sender-ip>/<today>.log. - The real device (for example the FortiGate) shows up with its own folder.
How to undo it
Disable remote reception and restart:
sudo rm /etc/rsyslog.d/10-remote.conf
sudo systemctl restart rsyslogCommon errors and fixes
sudo rsyslogd -N1 and journalctl -u rsyslog -n 50. Usually a typo in the config or another syslog service holds the port. ufw status), the device's source IP, and watch the wire with sudo tcpdump -ni any port 514. See the 'no logs arriving' scenario. sudo chown -R syslog:adm /var/log/remote. du -sh /var/log/remote/*, reduce retention, or add disk. Consider a separate disk mounted on /var/log/remote. Q&A
Why put the file in rsyslog.d/10-remote.conf?
Files in rsyslog.d are read in name order. A low number makes your rule run before the defaults, so remote messages are handled (and stopped) before they land in the local syslog file.
Why use the sender IP for the folder name?
Many network devices do not put a proper hostname in the syslog header, so %HOSTNAME% can be wrong or blank. The source IP is always known.
UDP or TCP?
The config accepts both. Let each device choose. Use TCP where losing messages matters.