keepalive

networkLinux
The keepalive command is one of the most frequently used commands in Linux/Unix-like operating systems. keepalive TCP keepalive configuration utility for network connections

Quick Reference

Command Name:

keepalive

Category:

network

Platform:

Linux

Basic Usage:

keepalive [options] [arguments]

Common Use Cases

    Syntax

    keepalive [options]

    Options

    Option Description
    status Show current TCP keepalive settings
    on Enable TCP keepalive
    off Disable TCP keepalive
    --time=SECONDS Set time (in seconds) before sending keepalive probes
    --interval=SECONDS Set interval (in seconds) between keepalive probes
    --probes=COUNT Set number of probes to send before considering connection dead
    --interface=INTERFACE Apply settings to a specific network interface
    --show-all Show detailed keepalive statistics
    --help Display help message
    --version Display version information

    Examples

    How to Use These Examples

    The examples below show common ways to use the keepalive command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    keepalive status
    Show current TCP keepalive settings.
    keepalive on
    Enable TCP keepalive on the system.
    # Advanced Examples Advanced
    keepalive --time=300 Set keepalive time to 300 seconds. keepalive --interval=60 Set keepalive interval to 60 seconds. keepalive --probes=10 Set keepalive probes to 10. keepalive --time=120 --interval=30 --probes=5 Set multiple keepalive parameters at once. keepalive --interface=eth0 on Enable keepalive on a specific network interface. keepalive --show-all Display detailed keepalive statistics.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The TCP keepalive mechanism is a feature that helps maintain and verify network connections, ensuring they remain active even during periods of inactivity. This is particularly useful for detecting disconnected clients or servers without relying on application-level heartbeats. The keepalive utility provides a convenient interface for configuring these settings at the system level. Key aspects of TCP keepalive: 1. Connection Maintenance: TCP keepalive prevents idle connections from being terminated by network devices like routers and firewalls that might drop inactive connections after a certain period. 2. Dead Peer Detection: It helps detect when the other end of a connection has become unavailable (e.g., due to a crash, network failure, or power outage) without requiring application-level checks. 3. Resource Conservation: By identifying and closing dead connections, keepalive helps free up system resources that would otherwise be tied up maintaining defunct connections. 4. Configurable Parameters: The utility allows adjustment of three critical parameters: - Time: How long a connection must be idle before the first keepalive probe is sent - Interval: The time between subsequent probes if no acknowledgment is received - Probes: How many unacknowledged probes are sent before declaring the connection dead 5. Network Optimization: Proper tuning of keepalive parameters can optimize network performance, reducing unnecessary traffic while ensuring prompt detection of connection failures. 6. Interface-Specific Settings: The ability to configure keepalive on specific interfaces allows for fine-grained control in multi-homed systems. Common use cases for keepalive include: - Maintaining persistent connections for services like SSH, database connections, and web services - Detecting and recovering from network failures in clustered environments - Preventing firewall or NAT timeouts for long-lived TCP connections - Ensuring reliable operation of critical network services - Troubleshooting network connectivity issues It's worth noting that while TCP keepalive operates at the transport layer, many applications also implement their own application-layer keepalive mechanisms. The system-level TCP keepalive provides a fundamental layer of connection management that works regardless of whether applications implement their own heartbeat mechanisms.

    Related Commands

    These commands are frequently used alongside keepalive or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the keepalive command works in different scenarios.

    $ keepalive
    View All Commands