I'm sorry to hear that you're having trouble getting rsyslog to forward Suricata's logs from Server A to Server B. Let's work through the configuration step by step to identify and resolve the issue.
Step 1: Verify Suricata's Syslog Configuration
First, ensure that Suricata is correctly configured to send logs to syslog.
In suricata.yaml, check the eve-log configuration:
outputs:
- eve-log:
enabled: yes
filetype: syslog # Ensure this is set to 'syslog'
level: info # Set the desired logging level
facility: local1 # Choose an appropriate syslog facility (local0-local7)
# Optionally set identity and priority
identity: suricata
priority: notice
types: # Specify the event types to log
- alert
- http
- dns
# Add other types as needed
Key Points:
filetype must be set to syslog.
facility should be one of the local0 to local7 facilities to avoid conflicts.
identity helps identify the service in logs.
priority sets the syslog severity level.
Step 2: Ensure Suricata Is Running as a Daemon
If Suricata is printing logs to the console, it might be running in the foreground. Make sure Suricata is running as a daemon.
Start Suricata as a Service:
sudo systemctl start suricata
Enable Suricata at Boot:
sudo systemctl enable suricata
Step 3: Verify rsyslog Configuration on Server A (Sender)
Rsyslog needs to be configured to capture Suricata's logs and forward them to Server B.
3.1: Create a Custom Rsyslog Configuration File
Create a new configuration file for Suricata in /etc/rsyslog.d/.
sudo nano /etc/rsyslog.d/30-suricata.conf
Add the Following Configuration:
# Load necessary modules
$ModLoad imuxsock # for receiving local syslog messages
$ModLoad omfwd # for forwarding messages
# Template for forwarding messages
$template SuricataFormat,"<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogtag%%msg:::sp-if-no-1st-sp%%msg%\n"
# Define the action to forward messages from Suricata
if $programname == 'suricata' then {
action(type="omfwd"
Target="serverB" # Replace with Server B's hostname or IP
Port="514" # Replace with the appropriate port
Protocol="tcp" # Use "udp" if appropriate
Template="SuricataFormat"
)
stop
}
Notes:
- Replace
serverB with the actual IP address or hostname of Server B.
- Ensure the port matches what rsyslog is listening on Server B (default is 514).
- The
stop action prevents further processing of these messages.
3.2: Restart rsyslog
sudo systemctl restart rsyslog
Step 4: Verify rsyslog Configuration on Server B (Receiver)
Server B must be configured to accept and store the forwarded logs.
4.1: Enable Remote Logging in rsyslog
Edit the main rsyslog configuration file.
sudo nano /etc/rsyslog.conf
Uncomment or add the following lines to enable TCP reception:
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514 # Ensure this port matches what's configured on Server A
For UDP reception, use:
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
4.2: Create a Custom Rsyslog Configuration File for Suricata
Create a new configuration file.
sudo nano /etc/rsyslog.d/30-suricata.conf
Add the Following Configuration:
# Template for Suricata logs
$template SuricataLog,"/var/log/suricata/%HOSTNAME%/suricata.log"
# Save Suricata logs from Server A
if $programname == 'suricata' then {
action(type="omfile" FileCreateMode="0644" DirCreateMode="0755" File="$SuricataLog")
stop
}
Notes:
- This configuration saves logs in
/var/log/suricata/<hostname>/suricata.log.
- Adjust permissions and paths as needed.
4.3: Create the Log Directory
Ensure the directory exists and has proper permissions.
sudo mkdir -p /var/log/suricata/ServerAHostname
sudo chown -R syslog:adm /var/log/suricata
Replace ServerAHostname with the actual hostname of Server A.
4.4: Restart rsyslog
sudo systemctl restart rsyslog
Step 5: Verify Network Connectivity
Ensure that Server A can reach Server B on the syslog port.
telnet serverB 514
If telnet is not installed, you can use nc:
nc -zv serverB 514
If Connection Fails:
- Check firewalls on both servers (e.g.,
ufw, iptables) to allow traffic on port 514.
- Ensure there are no network issues between the two servers.
Step 6: Test the Setup
6.1: Generate a Test Message on Server A
Use the logger command to send a test message.
logger -p local1.notice -t suricata "Test message from Suricata"
6.2: Check Logs on Server B
Look for the test message in the log file.
sudo cat /var/log/suricata/ServerAHostname/suricata.log
You should see the "Test message from Suricata".
Step 7: Check for Errors
7.1: On Server A
Check rsyslog's error logs.
sudo grep rsyslog /var/log/syslog
Look for messages indicating problems with forwarding or syntax errors in configuration files.
7.2: On Server B
Check rsyslog's error logs.
sudo grep rsyslog /var/log/syslog
Ensure that rsyslog is running without errors and is listening on the correct port.
Additional Considerations
- Permissions: Ensure that the user running rsyslog (
syslog on many systems) has permission to write to the log directory.
- SELinux/AppArmor: If these security modules are enabled, they might block network traffic or file writes. Consider adding appropriate policies or temporarily disabling them for testing.
- Syslog Facilities: Make sure the facility (
local1 in the example) is consistent across Suricata and rsyslog configurations.
- Rsyslog Syntax: Rsyslog has different syntax versions. The above configurations use the newer RainerScript syntax. If your rsyslog version is older, you might need to adjust the syntax.
Example Configurations
Suricata suricata.yaml:
outputs:
- eve-log:
enabled: yes
filetype: syslog
level: info
facility: local1
identity: suricata
priority: notice
types:
- alert
- dns
- http
Rsyslog /etc/rsyslog.d/30-suricata.conf on Server A:
$ModLoad imuxsock
$ModLoad omfwd
$template SuricataFormat,"<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogtag%%msg%\n"
if $programname == 'suricata' then {
action(type="omfwd"
Target="serverB"
Port="514"
Protocol="tcp"
Template="SuricataFormat"
)
stop
}
Rsyslog /etc/rsyslog.d/30-suricata.conf on Server B:
$template SuricataLog,"/var/log/suricata/%HOSTNAME%/suricata.log"
if $programname == 'suricata' then {
action(type="omfile" FileCreateMode="0644" DirCreateMode="0755" File="$SuricataLog")
stop
}
If Issues Persist
Please provide the following for further assistance:
- The content of your
suricata.yaml file.
- The rsyslog configuration files from both Server A and Server B.
- Any relevant logs or error messages from
/var/log/syslog or /var/log/messages.
This information will help diagnose the issue more precisely.
I hope this helps you get rsyslog to forward Suricata's logs correctly. Let me know if you have any questions or need further assistance!