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 04:26] – Continuing page after moving rant to blog. super_stunder | technical:remote_syslog_setup [2025/06/11 04:45] (current) – [Going against the Linux Gods] super_stunder | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | +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) ===== | ||
+ | |||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | I started this with the plans of using UFW to keep it simple things got pretty detailed pretty quick so I ended up switching directly to iptables. | ||
+ | |||
+ | Alright so now I am actually going to use a little bit of help from Google Gemini. | ||
+ | |||
+ | <cli> | ||
+ | -A INPUT -m state --state RELATED, | ||
+ | -A INPUT -p tcp -m tcp --dport 22 -j LOG --log-prefix " | ||
+ | -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT | ||
+ | -A INPUT -i lo -j ACCEPT | ||
+ | -A INPUT -j LOG --log-prefix " | ||
+ | -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. | ||
+ | |||
+ | <cli> | ||
+ | apt install iptables-persistent | ||
+ | </ | ||
+ | |||
+ | After iptables-persistent is install you can now run iptables-save to your policy file and it will load again after reboots. | ||
+ | |||
+ | <cli> | ||
+ | root@logger02: | ||
+ | </ | ||
+ | |||
+ | ==== Displaying iptables rules ==== | ||
+ | While digging into the rules I was just using the iptables -L command to list the policy. | ||
+ | |||
+ | |||
+ | < | ||
+ | Chain INPUT (policy DROP 14136 packets, 706K bytes) | ||
+ | pkts bytes target | ||
+ | 19294 4901K ACCEPT | ||
+ | | ||
+ | | ||
+ | | ||
+ | 247 11960 LOG all -- any any | ||
+ | |||
+ | Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) | ||
+ | pkts bytes target | ||
+ | |||
+ | Chain OUTPUT (policy ACCEPT 21944 packets, 5353K bytes) | ||
+ | pkts bytes target | ||
+ | | ||
+ | root@logger02: | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== The drama of logging in Linux ===== | ||
+ | I didn't know in this journey to consolidate logs to a centralized server I was going to end up blogging so much. Turns out I needed to start another post to talk about the usage of systemd' | ||
+ | |||
+ | ==== 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 | ||
- | So I am going to start this off and load rsyslog and UFW on the logger servers then I will go from there. I am using UFW for basic firewall configs it makes things way easier when building basic rules. | + | FIXME |
+ | Important considerations: | ||
- | < | + | Order of rules: The LOG rule must be at the very beginning of the chain to log all packets. |
+ | Log level: Adjust the --log-level to suit your needs and logging system. Levels range from 0 (highest severity) to 7 (debug). | ||
+ | Rate limiting: Logging all packets can generate a lot of log data. Use the --limit and --limit-burst options to rate-limit logging if needed. | ||
+ | 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. | ||
+ | [[: | ||
+ | |||