Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| technical:remote_syslog_setup [2025/06/04 18:42] – nugget | technical:remote_syslog_setup [2025/06/11 04:45] (current) – [Going against the Linux Gods] super_stunder | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | FIXME I have been working on a simple SYSLOG project to gather scanning data off of host around the internet and centralize it. The no telling what I will do with the data at that point. | + | ====== Remote Syslog - IPTables - Tigers and Bears OH MY ====== |
| + | |||
| + | |||
| + | I have been working on a simple SYSLOG project to gather scanning data off of host around the internet and centralize it. The no telling what I will do with the data at that point. | ||
| < | < | ||
| digraph MyGraph { | digraph MyGraph { | ||
| - | | + | |
| - | | + | |
| + | label = "Basic Concept" | ||
| } | } | ||
| </ | </ | ||
| Line 16: | Line 20: | ||
| ---- | ---- | ||
| + | ===== Configuring iptables (the hell of logging denies) ===== | ||
| + | |||
| < | < | ||
| Line 33: | Line 39: | ||
| -A OUTPUT -o lo -j ACCEPT | -A OUTPUT -o lo -j ACCEPT | ||
| </ | </ | ||
| + | |||
| + | ==== Saving iptables config and setting persistence after reboots ==== | ||
| After you have tested access back into your device over SSH you can now issue the persistent command to maintain the rules at startup. Turns on iptables-persistent isn't installed by default. | After you have tested access back into your device over SSH you can now issue the persistent command to maintain the rules at startup. Turns on iptables-persistent isn't installed by default. | ||
| Line 46: | Line 54: | ||
| </ | </ | ||
| + | ==== Displaying iptables rules ==== | ||
| While digging into the rules I was just using the iptables -L command to list the policy. | While digging into the rules I was just using the iptables -L command to list the policy. | ||
| Line 68: | Line 77: | ||
| </ | </ | ||
| - | Alright | + | ===== The drama of logging in Linux ===== |
| + | I didn't know in this journey to consolidate logs to a centralized server | ||
| + | ==== Going against the Linux Gods ==== | ||
| + | Now we need to shut off kernel logging in the journald. I go into details about this in the blog posting mentioned above, but I don't like the idea of cutting off kernel logs going to journald. | ||
| + | |||
| + | === Install rsyslog and disable kernal logging in journald === | ||
| + | Basic rsyslog install is fine | ||
| + | <cli> | ||
| + | apt install rsyslog | ||
| + | </ | ||
| + | |||
| + | Here is a my / | ||
| + | < | ||
| + | # / | ||
| + | # | ||
| + | # For more information install rsyslog-doc and see | ||
| + | # / | ||
| + | |||
| + | |||
| + | ################# | ||
| + | #### MODULES #### | ||
| + | ################# | ||
| + | |||
| + | module(load=" | ||
| + | module(load=" | ||
| + | # | ||
| + | |||
| + | # provides UDP syslog reception | ||
| + | # | ||
| + | # | ||
| + | |||
| + | # provides TCP syslog reception | ||
| + | # | ||
| + | # | ||
| + | |||
| + | |||
| + | ########################### | ||
| + | #### GLOBAL DIRECTIVES #### | ||
| + | ########################### | ||
| + | |||
| + | # | ||
| + | # Set the default permissions for all log files. | ||
| + | # | ||
| + | $FileOwner root | ||
| + | $FileGroup adm | ||
| + | $FileCreateMode 0640 | ||
| + | $DirCreateMode 0755 | ||
| + | $Umask 0022 | ||
| + | |||
| + | # | ||
| + | # Where to place spool and state files | ||
| + | # | ||
| + | $WorkDirectory / | ||
| + | |||
| + | # | ||
| + | # Include all config files in / | ||
| + | # | ||
| + | $IncludeConfig / | ||
| + | |||
| + | |||
| + | ############### | ||
| + | #### RULES #### | ||
| + | ############### | ||
| + | |||
| + | # Forward messages with " | ||
| + | :msg, contains, " | ||
| + | |||
| + | # This will forward all of the Firewall Logs to the syslog01 server from /etc/hosts over UDP 514 | ||
| + | :msg, contains, " | ||
| + | |||
| + | # Discard messages with the " | ||
| + | :msg, contains, " | ||
| + | |||
| + | # Send all other messages to the journald socket - not sure this is needed I am doing it all in syslog now might remove later. | ||
| + | *.* action(type=" | ||
| + | |||
| + | # | ||
| + | # Log anything besides private authentication messages to a single log file | ||
| + | # | ||
| + | *.*; | ||
| + | |||
| + | # | ||
| + | # Log commonly used facilities to their own log file | ||
| + | # | ||
| + | auth, | ||
| + | cron.* -/ | ||
| + | kern.* -/ | ||
| + | mail.* -/ | ||
| + | user.* -/ | ||
| + | |||
| + | # | ||
| + | # Emergencies are sent to everybody logged in. | ||
| + | # | ||
| + | *.emerg : | ||
| + | </ | ||
| + | |||
| + | |||
| + | Then edit / | ||
| + | |||
| + | <cli> | ||
| + | root@logger02: | ||
| + | </ | ||
| + | |||
| + | <code title=journald.conf el=true hl=34> | ||
| + | # Use ' | ||
| + | # | ||
| + | # See journald.conf(5) for details. | ||
| + | |||
| + | [Journal] | ||
| + | # | ||
| + | # | ||
| + | #Seal=yes | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | ForwardToSyslog=yes | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | MaxLevelSyslog=warn | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | ReadKMsg=no | ||
| + | #Audit=no | ||
| + | </ | ||
| + | |||
| + | Once you have rsyslog configured and logging disabled going to journald you need to restart both logging services. | ||
| + | |||
| + | <cli> | ||
| + | systemctl restart systemd-journald.service | ||
| + | systemctl restart rsyslog.service | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | Alright I have the basics running now but need to address a couple of things. | ||
| + | |||
| + | === The Syslog Server - syslog01 === | ||
| + | FIXME | ||
| + | |||
| + | Now you should see both servers " | ||
| + | < | ||
| + | 2025-06-11T04: | ||
| + | 2025-06-11T04: | ||
| + | </ | ||
| + | |||
| + | - < | ||
| + | - Even though I have loaded RSYSLOG all logs are still going to the systemd logs. I want to keep the system logs pointed to systemd (let it do its thing) and have all of the firewalls logs sent to /var/log for text based processing. :!: I thought this was going to be an option, turns out log flexibility has gone away now that the world of Linux has push to systemd | ||
| FIXME | FIXME | ||
| Line 80: | Line 252: | ||
| By implementing this iptables policy, a firewall that allows SSH on port 22, denies all other inbound traffic, and logs both accepted and denied packets with the desired prefix can be created. | By implementing this iptables policy, a firewall that allows SSH on port 22, denies all other inbound traffic, and logs both accepted and denied packets with the desired prefix can be created. | ||
| - | + | [[: | |