Configuring Syslog Network Connections on Ubuntu
Syslog is a standard protocol for collecting and transmitting system logs, enabling centralized log management across multiple devices. On Ubuntu, rsyslog (the default logging daemon) and syslog-ng are commonly used to configure network-based log transmission (sending logs to a remote server) or reception (accepting logs from other devices). Below is a structured guide covering both scenarios.
Before configuring network connections, ensure the following:
sudo apt list --installed | grep rsyslog
or install via sudo apt update && sudo apt install rsyslog
.192.168.1.100
).ufw
(Ubuntu’s default firewall) to configure:sudo ufw allow 514/udp # For UDP
sudo ufw allow 514/tcp # For TCP (recommended for production)
To forward logs from your Ubuntu system to a central syslog server, follow these steps:
Edit the rsyslog Configuration File:
Open the default rsyslog configuration file (or create a custom one in /etc/rsyslog.d/
):
sudo nano /etc/rsyslog.conf
Uncomment or add the following line to send all logs (*.*
) to the remote server via UDP (port 514):
*.* @remote_server_ip:514
Replace remote_server_ip
with the actual IP address of the syslog server.
Restart rsyslog:
Apply changes by restarting the service:
sudo systemctl restart rsyslog
For guaranteed log delivery (e.g., over unreliable networks), use TCP instead of UDP. Modify the configuration line to:
*.* @@remote_server_ip:514
The double @
symbol indicates TCP. Restart rsyslog after saving changes.
If you prefer syslog-ng (install via sudo apt install syslog-ng
), edit its configuration file:
sudo nano /etc/syslog-ng/syslog-ng.conf
Add a destination for the remote server and a log rule:
destination d_remote { tcp("remote_server_ip" port(514)); }; # TCP
# OR destination d_remote { udp("remote_server_ip" port(514)); }; # UDP
source s_local { system(); internal(); }; # Collect local logs
log { source(s_local); destination(d_remote); }; # Forward local logs to remote server
Restart syslog-ng to apply changes:
sudo systemctl restart syslog-ng
To centralize logs from multiple devices (e.g., IoT devices, servers), configure Ubuntu to accept incoming syslog traffic:
Enable Remote Log Reception:
Edit the rsyslog configuration file:
sudo nano /etc/rsyslog.conf
Uncomment or add the following lines to enable UDP (and TCP for reliability):
module(load="imudp") # Load UDP module
input(type="imudp" port="514") # Listen on UDP port 514
module(load="imtcp") # Load TCP module (optional but recommended)
input(type="imtcp" port="514") # Listen on TCP port 514
Restrict Access (Optional but Secure):
To limit log reception to specific IP addresses (e.g., 192.168.1.0/24
), add rules before the input
lines:
$AllowedSender UDP, 192.168.1.0/24 # Restrict UDP to subnet
$AllowedSender TCP, 192.168.1.0/24 # Restrict TCP to subnet
Restart rsyslog:
sudo systemctl restart rsyslog
Enable Remote Log Reception:
Edit the syslog-ng configuration file:
sudo nano /etc/syslog-ng/syslog-ng.conf
Add a source for network traffic and a log rule to store received logs:
source s_network {
udp(ip(0.0.0.0) port(514)); # Listen on all interfaces (UDP)
tcp(ip(0.0.0.0) port(514)); # Listen on all interfaces (TCP, optional)
};
destination d_local { file("/var/log/remote.log"); }; # Store remote logs in a separate file
log { source(s_network); destination(d_local); }; # Forward network logs to the destination
Restart syslog-ng:
sudo systemctl restart syslog-ng
After configuration, verify that logs are being transmitted/received correctly:
Use the logger
command to send a test log to the remote server:
logger -t test "This is a test log message from the client"
/var/log/syslog
for the test message:sudo tail -f /var/log/syslog | grep "test"
journalctl
to view real-time logs:sudo journalctl -f | grep "test"
Check the designated log file (e.g., /var/log/syslog
for rsyslog or /var/log/remote.log
for syslog-ng) for incoming logs from the client. Use tail -f
to monitor in real time.
sudo systemctl status rsyslog # or syslog-ng
sudo chown syslog:adm /var/log/syslog
).By following these steps, you can successfully configure syslog network connections on Ubuntu for centralized log management or distributed logging.