Open In App

Linux command lines for TCP variables

Last Updated : 27 Apr, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will discuss the Linux command lines for TCP variables.

Find default TCP used in the Linux

  • Checking the default TCP in the Linux Kernel
$ sysctl net.ipv4.tcp_congestion_control

Output:

$ net.ipv4.tcp_congestion_control = cubic
  • Changing the default TCP in the Linux Kernel to Reno
$ sudo sysctl -w net.ipv4.tcp_congestion_control=reno

Output:

$ net.ipv4.tcp_congestion_control = reno tcp_congestion_control

Switching back to CUBIC as the default TCP in the Linux Kernel

$ sudo sysctl -w net.ipv4.tcp_congestion_control=cubic

Output:

$ net.ipv4.tcp_congestion_control = cubic

Enable TCP Fastopen

  • Checking the default setting of TFO in the Linux Kernel
$ sysctl net.ipv4.tcp_fastopen

Output

$ net.ipv4.tcp_fastopen = 1
  • Enabling TFO if your machine is a Server
$ sudo sysctl -w net.ipv4.tcp_fastopen=2

Output:

$ net.ipv4.tcp_fastopen = 2
  • Enabling TFO if your machine is a Client as well as a Server
$ sudo sysctl -w net.ipv4.tcp_fastopen=3

Output

$ net.ipv4.tcp_fastopen = 3
  • Disabling TFO
$ sudo sysctl -w net.ipv4.tcp_fastopen=0

Output

$ net.ipv4.tcp_fastopen = 0 

Enable Slow Start Restart congestion control algorithm

  • Checking the default setting of SSR in the Linux Kernel
$ sysctl net.ipv4.tcp_slow_start_after_idle

Output

$ net.ipv4.tcp_slow_start_after_idle = 1
  • Disable Slow Start Restart (important for Servers, not so much for Clients)
$ sudo sysctl -w net.ipv4.tcp_slow_start_after_idle=0

Output:

$ net.ipv4.tcp_slow_start_after_idle = 0

Enable window scaling

  • Checking the default setting of TCP Window Scaling in the Linux Kernel
$ sysctl net.ipv4.tcp_window_scaling

Output

$ net.ipv4.tcp_window_scaling = 1
  • Disable TCP Window Scaling (not recommended, but try it to learn and re-enable)
$ sudo sysctl -w net.ipv4.tcp_window_scaling=0

Output:

$ net.ipv4.tcp_window_scaling = 0

How to find default window scaling in Linux kernel

Checking the default value of  Window Scaling Factor in the Linux Kernel

$ sysctl net.ipv4.tcp_adv_win_scale

Output

net.ipv4.tcp_adv_win_scale = 1 

This is shift.cnt=1, scaling factor=2shift.cnt = 2

tcp_adv_win_scale

Enable the SACK option

  • Checking the default setting of SACK in the Linux Kernel
$ sysctl net.ipv4.tcp_sack

Output:

net.ipv4.tcp_sack=1
  • Disabling the default setting of SACK in the Linux Kernel
$ sudo sysctl -w net.ipv4.

Output:

net.ipv4.tcp_sack=0 tcp_sack

Check timestamp setting

  • Check the default setting of TIMESTAMPS in the Linux kernel
$ sysctl net.ipv4.tcp_timestamps

Output

net.ipv4.tcp_timestamps=1
  • Disable the TIMESTAMPS in the Linux kernel
$ sudo sysctl -w net.ipv4.tcp_timestamps=0

Output

net.ipv4.tcp_timestamps=0 

Check Low Latency setting:

  • Check the default setting of Low Latency in the Linux kernel
$ sysctl net.ipv4.tcp_low_latency

Output

net.ipv4.tcp_low_latency=1
  • Disable Low Latency in the Linux kernel
$ sudo sysctl -w net.ipv4.tcp_low_latency=0

Output

net.ipv4.tcp_low_latency=0 

Check the default Buffer Size

  • Check the default setting of Buffer Size in the Linux kernel
$ sysctl net.ipv4.tcp_rmem

Output

net.ipv4.tcp_rmem=4096    131072    6291456 

Values are in the order: min default max. 131072 Bytes = 128 KB, is the default buffer size.

default buffer size

Check the available and allowed TCP in the Linux kernel:

  • To see the available TCPs:
sysctl net.ipv4.tcp_available_congestion_control 

Output

net.ipv4.tcp_allowed_congestion_control= reno cubic
  • To see the allowed TCPs:
sysctl net.ipv4.tcp_allowed_congestion_control 

Output

net.ipv4.tcp_allowed_congestion_control= reno cubic 

Check the default base MSS in the Linux kernel

  • To see the default base MSS value:
sysctl net.ipv4.tcp_base_mss

Output

net.ipv4.tcp_base_mss = 1024 

tcp_base_mss

Check the default value of DUP-ACK for fast retransmit of the lost packet

  • To see the default value of DUP-ACK:
sysctl net.ipv4.tcp_early_retrans

Output

net.ipv4.tcp_early_retrans = 3 

See the default timeout for blackholing the TFO

  • Blackhole timeout for TFO:
sysctl net.ipv4.tcp_fastopen_blackhole_timeout_sec 

Output

net.ipv4.tcp_fastopen_blackhole_timeout_sec = 3600

tcp_fastopen_blackhole_timeout_sec

Number of retransmissions

  • The number of packet retransmission without involving the network layer:
sysctl net.ipv4.tcp_retries1

Output

net.ipv4.tcp_retries1 = 3
  • The maximum number of retransmissions of a lost packet before giving up:
sysctl net.ipv4.tcp_retries2

Output

sysctl net.ipv4.tcp_retries2 = 15 

Default KeepAlive parameters in Linux kernel

  • Default keepalive timeout value:
sysctl net.ipv4.tcp_keepalive_time

Output

net.ipv4.tcp_keepalive_time=7200

When a client is not actively sending the request to the server, then the server waits for 7200 seconds. If no response is coming from the client then it sends the confirmatory packets to the client. For 7200 seconds server just waits and does not disconnect the connection. 

  • The default frequency of keepalive probes:
sysctl net.ipv4.tcp_keepalive_probes

Output

net.ipv4.tcp_keepalive_probes=9

When 7200 seconds are over, the server sends the first probe message to see whether the client is still connected or not. If no response comes before the second probe is sent then the server again sends the probe message. When all 9 probes are sent and no confirmation is received from the client. Then server disconnects the client and the socket is available for other clients to use.

  • The default time interval of each keepalive probe:
sysctl net.ipv4.tcp_keepalive_intvl

Output

net.ipv4.tcp_keepalive_intvl=75 

The server will send the next probe after an interval of 75 seconds. Thus, the total time of inactivity to disconnect the connection by the server is:- 7200+9*75 = 7875 seconds.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads