There are two ways to configure keepalive parameters inside the kernel via
userspace commands:
We mainly discuss how this is accomplished on the procfs interface because
it's the most used, recommended and the easiest to understand. The sysctl
interface, particularly regarding the
sysctl(2) syscall and not the
sysctl(8)
tool, is only here for the purpose of background knowledge.
3.1.1. The procfs interface
This interface requires both sysctl and
procfs to be built into the kernel, and procfs
mounted somewhere in the filesystem (usually on
/proc, as in the examples below). You can read the values for
the actual parameters by "catting" files in
/proc/sys/net/ipv4/ directory:
The first two parameters are expressed in seconds, and the last is the
pure number. This means that the keepalive routines wait for two hours
(7200 secs) before sending the first keepalive probe, and then resend it
every 75 seconds. If no ACK response is received for nine consecutive
times, the connection is marked as broken.
Modifying this value is straightforward: you need to write new values
into the files. Suppose you decide to configure the host so that
keepalive starts after ten minutes of channel inactivity, and then send
probes in intervals of one minute. Because of the high instability of
our network trunk and the low value of the interval, suppose you also
want to increase the number of probes to 20.
Here's how we would change the settings:
To be sure that all succeeds, recheck the files and confirm these new
values are showing in place of the old ones.
Remember that procfs handles special files, and you
cannot perform any sort of operation on them because they're just an interface within the kernel space, not real
files, so try your
scripts before using them, and try to use simple access methods as in
the examples shown earlier.
You can access the interface through the
sysctl(8) tool, specifying what you want to read or write.
Note that sysctl names are very close to
procfs paths. Write is performed using the -w
switch of sysctl
(8):
Note that sysctl
(8) doesn't use
sysctl(2) syscall, but reads and writes
directly in the procfs subtree, so you will need
procfs enabled in the kernel and mounted in the
filesystem, just as you would if you directly accessed the files within
the procfs interface.
Sysctl(8) is just a different way to do the same thing.
3.1.2. The sysctl interface
There is another way to access kernel variables: sysctl(2
) syscall. It can be useful when you don't
have procfs available because the communication with
the kernel is performed directly via syscall and not through the
procfs subtree. There is currently no program that
wraps this syscall (remember that
sysctl(8)
doesn't use it).
For more details about using
sysctl(2)
refer to the manpage.