Linux sysklogd command
On Linux operating systems, sysklogd is a set of Linux system logging utilities.
Description
Sysklogd provides two system utilities which provide support for system logging and kernel message trapping. Support of both Internet and unix domain sockets enables this utility package to support both local and remote logging.
System logging is provided by a version of syslogd derived from BSD. Support for kernel logging is provided by the klogd utility that allows kernel logging to be conducted in either a standalone fashion or as a client of syslogd.
syslogd provides a kind of logging that many modern programs use. Every logged message contains at least a time and a hostname field, and normally a program name field, but it depends on the logging program.
The main configuration file /etc/syslog.conf or an alternative file, given with the -f option, is read at startup. Any lines that begin with the hash mark ("#") and empty lines are ignored. If an error occurs during parsing a line, the whole line is ignored.
Syntax
syslogd [ -a socket ] [ -d ] [ -f config-file ] [ -h ] [ -l hostlist ] [ -m interval ] [ -n ] [ -p socket ] [-r ] [ -s domainlist ] [ -u user ] [ -v ]
Options
-a socket | Using this argument, you can specify additional sockets from that syslogd has to listen to. This is needed if you're going to let some daemon run within a chroot() environment. You can use up to 19 additional sockets. If your environment needs even more, you have to increase the symbol MAXFUNIX in the syslogd.c source file. |
-d | Turns on debug mode. Using this the daemon will not proceed a fork to set itself in the background, but opposite to that stay in the foreground and write much debug information on the current tty. |
-f config-file | Specify an alternative configuration file instead of /etc/syslog.conf, which is the default. |
-h | By default, syslogd will not forward messages it receives from remote hosts. Specifying this switch on the command line causes the log daemon to forward any remote messages it receives to forwarding hosts which are defined. This can cause syslog loops that fill up hard disks quite fast and thus needs to be used with caution. |
-l hostlist | Specify a hostname that should be logged only with its simple hostname and not the fqdn. Multiple hosts may be specified using the colon (":") separator. |
-m interval | The syslogd logs a mark timestamp regularly. The default interval between two "-- MARK --" lines is 20 minutes. This can be changed with this option. Setting the interval to zero turns it off entirely. Depending on other log messages generated these lines may not be written consecutively. |
-n | Avoid auto-backgrounding. This is needed especially if the syslogd is started and controlled by init. |
-p socket | You can specify an alternative unix domain socket instead of /dev/log. |
-r | This option enables the facility to receive message from the network using an Internet domain socket with the syslog service. The default is to not receive any messages from the network. This option is introduced in version 1.3 of the sysklogd package. Please note that the default behavior is the opposite of how older versions behave, so you might have to turn this on this option. |
-s domainlist | Specify a domain name that should be stripped off before logging. Multiple domains may be specified using the colon (":") separator. Please be advised that no sub-domains may be specified but only entire domains. For example, if -s north.de is specified and the host logging resolves to satu.info-drom.north.de no domain would be cut, you have to specify two domains like: -s north.de:info-drom.north.de. |
-u user | The syslogd daemon runs with full root privileges by default. If you specify this option, the daemon will drop its privileges to the given user (and the primary group of this user) before starting up logging. This greatly reduces the potential impact of exploitable security holes in syslogd. syslogd opens all log files as root at startup. However, after receiving a SIGHUP signal (which causes the daemon to restart) the log files will be reopened as the non-privileged user which fails if the log files are only writeable by root. If you need to restart the daemon using the signal, then you have to adapt the permissions of your log files to be writeable by the specified user (or its primary group). |
-v | Print version and exit. |
Signals
Syslogd reacts to a set of signals. You may easily send a signal to syslogd using the following:
kill -SIGNAL `cat /var/run/syslogd.pid`
where SIGNAL is one of the following signals:
SIGHUP | This lets syslogd perform a re-initialization. All open files are closed, the configuration file (default is /etc/syslog.conf) will be reread and the syslog facility is started again. |
SIGTERM | Kills syslogd. |
SIGINT, SIGQUIT | If debugging is enabled these are ignored, otherwise syslogd will die. |
SIGUSR1 | Switch debugging on/off. This option can only be used if syslogd is started with the -d debug option. |
SIGCHLD | Wait for child processes (if some were spawned). |
Configuration file syntax
Syslogd uses a slightly different syntax for its configuration file than the original BSD sources. Originally all messages of a specific priority and above were forwarded to the log file.
For example, the following line caused ALL output from daemons using the daemon facilities (debug is the lowest priority, so everything higher also matches) to go into /usr/adm/daemons:
# Sample syslog.conf daemon.debug /usr/adm/daemons
Under the new scheme this behavior remains the same. The difference is the addition of four new specifiers, the asterisk (*) wildcard, the equal sign (=), the exclamation mark (!), and the minus sign (-).
The * specifies that all messages for the specified facility are to be directed to the destination. Note that this behavior is degenerate with specifying a priority level of debug. Users have indicated that the asterisk notation is more intuitive.
The = wildcard is used to restrict logging to the specified priority class. This allows, for example, routing only debug messages to a particular logging source.
For example, the following line in syslog.conf would direct debug messages from all sources to the /usr/adm/debug file.
# Sample syslog.conf *.=debug /usr/adm/debug
The ! is used to exclude logging of the specified priorities. This affects all (!) possibilities of specifying priorities.
For example, the following lines would log all messages of the facility mail except those with the priority info to the /usr/adm/mail file. And all messages from news.info (including) to news.crit (excluding) would be logged to the /usr/adm/news file.
# Sample syslog.conf mail.*;mail.!=info /usr/adm/mail news.info;news.!crit /usr/adm/news
You may use it intuitively as an exception specifier. The above mentioned interpretation is inverted. You may also use
mail.none
or
mail.!*
or
mail.!debug
to skip every message that comes with a mail facility.
The "-" may only be used to prefix a file name if you want to omit syncing the file after every write to it.
Remote logging support
To enable remote logging, specify the -r option on the command line. The default behavior is that syslogd won't listen to the network.
The strategy is to have syslogd listen on a unix domain socket for locally generated log messages. This behavior allows syslogd to interoperate with the syslog found in the standard C library. At the same time syslogd listens on the standard syslog port for messages forwarded from other hosts. To have this work correctly the services files (typically found in /etc) must have the following entry:
syslog 514/udp
If this entry is missing syslogd neither can receive remote messages nor send them, because the UDP port can't be opened. Instead syslogd will die immediately, and print an error message.
To cause messages to be forwarded to another host, replace the normal file line in the syslog.conf file with the name of the host where the messages is to be sent prepended with an @.
For example, to forward ALL messages to a remote host use the following syslog.conf entry:
# Sample syslogd configuration file to # messages to a remote host forward all. *.* @hostname
To forward all kernel messages to a remote host the configuration file would be as follows:
# Sample configuration file to forward all kernel # messages to a remote host. kern.* @hostname
If the remote hostname cannot be resolved at startup, because the name server might not be accessible (it may be started after syslogd) syslogd will retry to resolve the name ten times and then complain. Another possibility to avoid this is to place the hostname in /etc/hosts.
To avoid this, no messages received from a remote host are sent out to another (or the same) remote host anymore. If you experience are set up where you need this behavior, please use the -h command line switch. However, this option needs to be handled with caution since a syslog loop can fill up hard disks quite fast.
If the remote host is located in the same domain as the host, syslogd is running on, only the simple hostname will be logged instead of the whole fqdn.
In a local network, you may provide a central log server to have all the important information kept on one machine. If the network consists of different domains, you don't have to complain about logging fully qualified names instead of simple hostnames. You may want to use the strip-domain feature -s of this server. You can tell the syslogd to strip off several domains other than the one the server is located in and only log simple hostnames.
Using the -l option there's also a possibility to define single hosts as local machines. This, too, results in logging only their simple hostnames and not the fqdns.
The UDP socket used to forward messages to remote hosts or receive messages from them is only opened when it is needed. In releases before 1.3-23 it was opened every time but not opened for reading or forwarding respectively.
Security notes
There is the potential for the syslogd daemon to be used as a conduit for a denial of service attack. A rogue program (or programmer) could very easily flood the syslogd daemon with syslog messages resulting in the log files consuming all the remaining space on the filesystem. Activating logging over the inet domain sockets will of course expose a system to risks outside of programs or individuals on the local machine.
There are many methods of protecting a machine:
- Implement kernel firewalling to limit which hosts or networks can access the 514/UDP socket.
- Logging can be directed to an isolated or non-root filesystem which, if filled, will not impair themachine.
- The ext2 filesystem can be used which can be configured to limit a certain percentage of a filesystem to usage by root only. Note that this requires syslogd to run as a non-root process, and prevent usage of remote logging since syslogd cannot bind to the 514/UDP socket.
- Disabling inet domain sockets will limit risk to the local machine.
Debugging
When debugging is turned on using -d option, syslogd will be very verbose by writing much of what it does to stdout. Whenever the configuration file is reread and re-parsed you'll see a tabular, corresponding to the internal data structure. This tabular consists of four fields:
number | This field contains a serial number starting by zero. This number represents the position in the internal data structure (the array). If one number is left out then there might be an error in the corresponding line in /etc/syslog.conf. |
pattern | This field is represents the internal structure exactly. Every column stands for a syslog facility. As you can see, there are still some facilities left free for former use, only the left most are used. Every field in a column represents the priorities. |
action | This field describes the particular action that takes place whenever a message is received that matches the pattern. |
arguments | This field shows additional arguments to the actions in the last field. For file-logging this is the file name for the logfile; for user-logging this is a list of users; for remote logging this is the hostname of the machine to log to; for console-logging this is the used console; for tty-logging this is the specified tty. |
Related commands
dmesg — Print or control the kernel ring buffer.