How to configure the so_keepalive property in Linux?
In Linux, the setsockopt function can be used to configure the SO_KEEPALIVE property.
You can use one of the following methods to set the SO_KEEPALIVE attribute:
- Setting up using the C language:
int optval = 1;
int optlen = sizeof(optval);
setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen);
- Set up using the command line.
sudo sysctl -w net.ipv4.tcp_keepalive_time=600
This will set the SO_KEEPALIVE property to 600 seconds (10 minutes).
Please note that the SO_KEEPALIVE attribute is used to detect idle connections to ensure they are still active, preventing them from being closed by intermediate devices such as firewalls.