Install and setup rsyslog server on Debian 10<\/a><\/p>\n\n\n\nInstall Rsyslog on Ubuntu 22.04<\/h3>\n\n\n\n Rsyslog is the default syslogd on Debian systems and is usually installed on Ubuntu 22.04 by default.<\/p>\n\n\n\n
You can verify this by checking the version of installed rsyslog.<\/p>\n\n\n\n
apt list -a rsyslog<\/code><\/pre>\n\n\n\nListing... Done\nrsyslog\/jammy,now 8.2112.0-2ubuntu2 amd64 [installed,automatic]<\/code><\/pre>\n\n\n\nIf for any reasons it is not installed, run the command below to install it.<\/p>\n\n\n\n
sudo apt update<\/code><\/pre>\n\n\n\nsudo apt install rsyslog -y<\/code><\/pre>\n\n\n\nOnce the installation is done, start and enable the rsyslog service.<\/p>\n\n\n\n
sudo systemctl enable --now rsyslog<\/code><\/pre>\n\n\n\nSetup Rsyslog server on Ubuntu 22.04<\/h3>\n\n\n\n Rsyslog can be configured as client to sent logs to a central logging server or a server to receive and store logs from other systems.<\/p>\n\n\n\n
In this guide, we setup Rsyslog as a server on an Ubuntu 22.04 box.<\/p>\n\n\n\n
Open the ryslog configuration file for editing;<\/p>\n\n\n\n
sudo vim \/etc\/rsyslog.conf<\/code><\/pre>\n\n\n\nDefine Rsyslog Server Protocol and Port<\/h3>\n\n\n\n To begin with, define the protocol and port you want to receive logs on.<\/p>\n\n\n\n
You can choose to use UDP or TCP and any port number of your choice.<\/p>\n\n\n\nNote that TCP syslog reception is way more reliable than UDP syslog and still pretty fast. The main reason is, that UDP might suffer of message loss. This happens when the syslog server must receive large bursts of messages. If the system buffer for UDP is full, all other messages will be dropped. With TCP, this will not happen. But sometimes it might be good to have a UDP server configured as well. That is, because some devices (like routers) are not able to send TCP syslog by design. In that case, you would need both syslog server types to have everything covered.<\/p><\/blockquote><\/figure>\n\n\n\n
In this setup, we will configure Rsyslog to use both UDP and TCP protocols for logs reception over the ports 514 and 50514 respectively.<\/p>\n\n\n\n
By default UDP syslog is received on port 514\/UDP.<\/p>\n\n\n\n
\nThus, to enable UDP syslog reception:<\/li>\n<\/ul>\n\n\n\nWithin the \/etc\/rsyslog.conf<\/strong> configuration file, uncomment the lines for UDP syslog reception in the MODULES<\/strong> section as shown below;<\/p>\n\n\n\n...\n#################\n#### MODULES ####\n#################\n...\n\n# provides UDP syslog reception\nmodule(load=\"imudp\")\ninput(type=\"imudp\" port=\"514\")<\/strong>\n...\n<\/code><\/pre>\n\n\n\n\nEnable TCP syslog reception:<\/li>\n<\/ul>\n\n\n\nTCP syslog may need to use a different port because often the RPC service is using port 514 as well.<\/p>\n\n\n\n
To set rsyslog to run on a different TCP port, say TCP port, 50514<\/strong>, uncomment the TCP reception lines and change the port as shown below;<\/p>\n\n\n\n# provides TCP syslog reception\nmodule(load=\"imtcp\")<\/strong>\ninput(type=\"imtcp\" port=\"50514\")<\/strong><\/code><\/pre>\n\n\n\nSave and exit the file;<\/p>\n\n\n\n
Restart rsyslog service;<\/p>\n\n\n\n
sudo systemctl restart rsyslog<\/code><\/pre>\n\n\n\nVerify that rsyslog is now listening on two ports;<\/p>\n\n\n\n
sudo ss -4altunp | grep 514<\/code><\/pre>\n\n\n\nudp UNCONN 0 0 0.0.0.0:514 0.0.0.0:* users:((\"rsyslogd\",pid=3893,fd=5)) \ntcp LISTEN 0 25 0.0.0.0:50514 0.0.0.0:* users:((\"rsyslogd\",pid=3893,fd=7))<\/code><\/pre>\n\n\n\nYou may notice that UDP port has no LISTEN state because it is connectionless and has no concept of \u201clistening\u201d, \u201cestablished\u201d, \u201cclosed\u201d, or anything like that.<\/strong><\/p>\n\n\n\nAllow Rsyslog through Firewall<\/h5>\n\n\n\n If firewall is running, open rsyslog through it.<\/p>\n\n\n\n
sudo ufw allow 514\/udp<\/code><\/pre>\n\n\n\nsudo ufw allow 50514\/tcp<\/code><\/pre>\n\n\n\nDefine Allowed Senders<\/h5>\n\n\n\n You may also want to explicitly set the remote clients that are allowed to to send syslog messages to rsyslogd. To achieve this, you can set a global directive using the $AllowedSender<\/strong> directive.<\/p>\n\n\n\nAllowed sender lists can be defined for UDP and TCP senders separately. The syntax to specify them is:<\/p>\n\n\n\n
$AllowedSender [UDP\/TCP], ip[\/bits], ip[\/bits]<\/strong><\/code><\/p>\n\n\n\n\nip[\/bits]<\/strong> is a machine or network ip address as in \u201c192.0.2.0\/24\u201d or \u201c192.0.2.10\u201d. If the \/bits<\/strong> part is omitted, a single host is assumed. \u201c\/0\u201d is not allowed, because that would match any sending system.<\/li>\n\n\n\nHostnames<\/strong>, with and without wildcards, may also be provided. If so, the result of revers DNS resolution is used for filtering.<\/li>\n\n\n\nMultiple allowed senders can be specified in a comma-delimited list.<\/li>\n<\/ul>\n\n\n\nIt is good to specify senders with high traffic volume before those with lower volume.<\/p>\n\n\n\n
To allow specific hosts for either UDP or TCP logging, enter the following lines;<\/p>\n\n\n\n
vim \/etc\/rsyslog.conf<\/code><\/pre>\n\n\n\n...\n###########################\n#### GLOBAL DIRECTIVES ####\n###########################\n# $AllowedSender - specifies which remote systems are allowed to send syslog messages to rsyslogd\n$AllowedSender UDP, 192.168.58.0\/24, [::1]\/128, *.example.net, servera.example.com\n$AllowedSender TCP, 192.168.59.0\/24, [::1]\/128, *.example.net, serverb.example.com<\/strong>\n<\/code><\/pre>\n\n\n\n\nThe hostnames must be resolvable since before ACL is updated, they will be resolved into their individual IPs.<\/li>\n\n\n\n Also note that the above directives only allow UDP reception from 192.168.58.0\/24<\/strong> and TCP reception from 192.168.59.0\/24<\/strong> networks.<\/li>\n<\/ul>\n\n\n\nAs much as allowing specific hosts via this directive, a good idea to impose allowed sender limitations via firewalling.<\/p>\n\n\n\n
For example, to allow hosts from the 192.168.58.0\/24<\/strong> and 192.168.59.0\/24<\/strong> networks;<\/p>\n\n\n\nufw allow from 192.168.58.0\/24<\/strong> to any port 514 proto udp\nufw allow from 192.168.58.0\/24<\/strong> to any port 50514 proto tcp<\/code><\/pre>\n\n\n\nufw allow from 192.168.59.0\/24<\/strong> to any port 514 proto udp\nufw allow from 192.168.59.0\/24<\/strong> to any port 50514 proto tcp<\/code><\/pre>\n\n\n\nTemplates are a key feature of rsyslog. Any output that is generated by rsyslog can be modified and formatted according to your needs with the use of templates.<\/p>\n\n\n\n
To create a template use the following syntax in \/etc\/rsyslog.conf<\/strong>:<\/p>\n\n\n\n$template TEMPLATE_NAME<\/em>,\"text %PROPERTY% more text<\/em>\", [OPTION<\/em>]<\/code><\/pre>\n\n\n\nThus, we can create our template like;<\/p>\n\n\n\n
# provides TCP syslog reception\nmodule(load=\"imtcp\")\ninput(type=\"imtcp\" port=\"50514\")\n\n#Custom template to generate the log filename dynamically based on the client's IP address.\n$template RemInputLogs, \"\/var\/log\/remotelogs\/%FROMHOST-IP%\/%PROGRAMNAME%.log\"<\/strong>\n*.* ?RemInputLogs<\/strong>\n<\/code><\/pre>\n\n\n\nThis will categorize logs received from remote host into log files for specific programs responsible for the generation of that log.<\/p>\n\n\n\n
Once you are done with configuration, save and exit the file;<\/p>\n\n\n\n
You can now restart the rsyslog<\/code> service by running the command below. Before you can restart rsyslogd, run a configuration check.<\/p>\n\n\n\nsudo rsyslogd -f \/etc\/rsyslog.conf -N1<\/code><\/pre>\n\n\n\nIf all is well, proceed to restart rsyslog.<\/p>\n\n\n\n
sudo systemctl restart rsyslog<\/code><\/pre>\n\n\n\nRsyslogd is now ready to receive logs from remote hosts.<\/p>\n\n\n\n
Now it is time to configure the remote client to send syslog messages to the remote syslog server. Login and proceed as follows.<\/p>\n\n\n\n
Verify Remote Rsyslog Server Ports Connection<\/h4>\n\n\n\n To verify connectivity to remote rsyslog server TCP port 50514, run the command below;<\/p>\n\n\n\n
telnet 192.168.59.38 50514<\/code><\/pre>\n\n\n\nTrying 192.168.59.38...\nConnected to 192.168.59.38.\nEscape character is '^]'.\n^]\ntelnet><\/code><\/pre>\n\n\n\nVerify connectivity to UDP port 514. Since you cannot telnet to UDP port 514, use netcat command. On the server, run the command below;<\/p>\n\n\n\n
sudo nc -ul 514<\/code><\/pre>\n\n\n\nOn the client, run the command below;<\/p>\n\n\n\n
nc -u 192.168.59.38 514<\/code><\/pre>\n\n\n\nNext, press ENTER and type anything. You should be able to see what you type on the server.<\/p>\n\n\n\n
If all is good, edit the client system rsyslog configuration file and configure it to push the logs to the syslog server;<\/p>\n\n\n\n
vim \/etc\/rsyslog.conf<\/code><\/pre>\n\n\n\nFor example, to send authentication logs over port 514\/UDP, add the following line at the end of the file. Note, this should be done from hosts under the 192.168.57.0\/24<\/strong> as per the AllowedSender<\/code><\/strong> directive.<\/p>\n\n\n\n# Send logs to remote syslog server over UDP\nauth,authpriv.* @192.168.59.38:514<\/strong><\/code><\/pre>\n\n\n\nTo send all logs over port 50514\/TCP, add the following line at the end of the file. Note, this should be done from hosts under the 192.168.58.0\/24<\/strong> as per the AllowedSender directive.<\/p>\n\n\n\n# Send logs to remote syslog server over TCP 50514\n*.* @@192.168.59.38:50514<\/strong><\/code><\/pre>\n\n\n\nAs a cushion just in case the remote rsyslog server goes down and your logs are so important you don\u2019t want to loose, set the rsyslog disk queue for buffering in the rsyslog configuration file as shown below;<\/p>\n\n\n\n
# Define Disk Queue Buffer in case the server goes down\n$ActionQueueFileName queue<\/strong> # define a file name for disk assistance.\n$ActionQueueMaxDiskSpace 1g<\/strong> # The maximum size that all queue files together will use on disk.\n$ActionQueueSaveOnShutdown on<\/strong> # specifies that data should be saved at shutdown\n$ActionQueueType LinkedList<\/strong> # holds enqueued messages in memory which makes the process very fast. \n$ActionResumeRetryCount -1<\/strong> # prevents rsyslog from dropping messages when retrying to connect if server is not responding,<\/code><\/pre>\n\n\n\nRestart the rsyslog service on the client.<\/p>\n\n\n\n
systemctl restart rsyslog<\/code><\/pre>\n\n\n\nYou can now log out of the client and login again. The authentication logs should be available on rsyslog server.<\/p>\n\n\n\n
Verify Syslog Log Reception on Rsyslog Server<\/h3>\n\n\n\n Login to the Rsyslog server and verify the same.<\/p>\n\n\n\n
sudo ls -1 \/var\/log\/remotelogs\/<\/code><\/pre>\n\n\n\n127.0.0.1\n192.168.58.35<\/code><\/pre>\n\n\n\nIn our case, we send only authentication logs to remote rsyslog server.<\/p>\n\n\n\n
sudo ls -1 \/var\/log\/remotelogs\/192.168.58.35\/<\/code><\/pre>\n\n\n\nCRON.log\nsshd.log\nsudo.log\nsu.log<\/code><\/pre>\n\n\n\nAnd that is how simple it is to install and setup Rsyslog server on Ubuntu for central remote logging.<\/p>\n\n\n\n
Other Tutorials<\/h3>\n\n\n\n Forward Apache Logs to Central Log Server with Rsyslog<\/a><\/p>\n\n\n\nConfigure NXLog to Forward System Logs to Rsyslog Server on Ubuntu 18.04<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"In this tutorial, you will learn how to install and setup rsyslog server on Ubuntu 22.04. Rsyslog is a multi-threaded implementation of syslogd (a system utility providing<\/p>\n","protected":false},"author":1,"featured_media":8502,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,191,39],"tags":[3317,4795,4802,4801,3316],"class_list":["post-12015","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-rsyslog","category-storage","tag-central-logging-with-rsyslog-on-ubuntu","tag-install-rsyslog-server-ubuntu-22-04","tag-rsyslog-server-tcp","tag-rsyslog-server-udp","tag-setup-rsyslog-server-on-ubuntu-20-04","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12015"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=12015"}],"version-history":[{"count":6,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12015\/revisions"}],"predecessor-version":[{"id":20420,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12015\/revisions\/20420"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/8502"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=12015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=12015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=12015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}