{"id":1877,"date":"2024-09-28T17:39:48","date_gmt":"2024-09-28T15:39:48","guid":{"rendered":"https:\/\/bergs.biz\/blog\/?p=1877"},"modified":"2024-09-28T17:42:24","modified_gmt":"2024-09-28T15:42:24","slug":"rsyslog-configuration-for-remote-logging","status":"publish","type":"post","link":"https:\/\/bergs.biz\/blog\/2024\/09\/28\/rsyslog-configuration-for-remote-logging\/","title":{"rendered":"rsyslog Configuration for remote Logging"},"content":{"rendered":"\n<p>I want all the network devices in my house to log to a central location, so that log messages can be<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>stored permanently (if I switch off an access point, normally all logs are gone), and<\/li>\n\n\n\n<li>automatically checked for interesting events.<\/li>\n<\/ul>\n\n\n\n<p>So I needed to set up my internal Ubuntu-based server to receive log messages from these devices via the <code>syslog<\/code> protocol.<\/p>\n\n\n\n<p>My requirements were:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Logs from different devices should go into a dedicated file each.<\/li>\n\n\n\n<li>Logs from the local machine should <em>not<\/em> go into any of these files, but the standard Ubuntu logging should be continued to be observed.<\/li>\n<\/ul>\n\n\n\n<p>It took me a while to figure out how the &#8220;ultimate&#8221; configuration should be, but here&#8217;s the result in case anybody else has similar requirements:<\/p>\n\n\n\n<!--more-->\n\n\n\n<pre class=\"wp-block-code\"><code># Define a template for the remote log file\ntemplate(name=\"TmplRemote\" type=\"list\") {\n    constant(value=\"\/var\/log\/remote\/\")\n    property(name=\"hostname\" SecurePath=\"replace\")\n    constant(value=\".log\")\n}\n\n# provides UDP syslog reception\nmodule(load=\"imudp\")\n\n# provides TCP syslog reception\nmodule(load=\"imtcp\")\n\nruleset(name=\"remote\"){\n    # Filter messages from remote hosts and write to the dedicated file\n    if ($fromhost-ip != '127.0.0.1') then {\n        action(type=\"omfile\" dynafile=\"TmplRemote\")\n    } else {\n        # Prevent local messages from being written to the remote log file\n        stop\n    }\n}\n\ninput(type=\"imudp\" port=\"514\" ruleset=\"remote\")\ninput(type=\"imtcp\" port=\"514\" ruleset=\"remote\")<\/code><\/pre>\n\n\n\n<p>Put the above into a file called <code><kbd>\/etc\/rsyslog.d\/99-local.conf<\/kbd><\/code>, create directory <kbd>\/var\/log\/remote\/<\/kbd>, then restart <code><kbd>rsyslog<\/kbd><\/code> as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo systemctl restart rsyslog.service<\/code><\/pre>\n\n\n\n<p>BTW, in case you wonder about the <kbd>SecurePath<\/kbd> property for the remote host name, this is a security measure.<\/p>\n\n\n\n<p>At home with your own trusted equipment this is not really required. But in &#8220;hostile&#8221; environments with untrusted traffic it could happen that somebody tries an attack by &#8220;crafting&#8221; a host name that would then be used as path name on your logging server and potentially create files that you didn&#8217;t foresee.<\/p>\n\n\n\n<p>Did this help? Then let me know, please.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I want all the network devices in my house to log to a central location, so that log messages can be So I needed to set up my internal Ubuntu-based server to receive log messages from these devices via the syslog protocol. My requirements were: It took me a while to figure out how the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,34,122,33,84,134,86],"tags":[388,387],"class_list":["post-1877","post","type-post","status-publish","format-standard","hentry","category-computers","category-debian","category-english","category-linux-computers","category-networking-computers","category-routers","category-ubuntu","tag-logging","tag-syslog"],"_links":{"self":[{"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/posts\/1877","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/comments?post=1877"}],"version-history":[{"count":3,"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/posts\/1877\/revisions"}],"predecessor-version":[{"id":1881,"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/posts\/1877\/revisions\/1881"}],"wp:attachment":[{"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/media?parent=1877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/categories?post=1877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/tags?post=1877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}