22. June 2013 3 min read
Fine tuning TCP IP network in Linux
TCP/IP stack in Linux is very well tuned for everyday web-browsing user, but you might want to consider re-tweaking it if you experience and problems with WiFi or just congested Ethernet network. Also different parameters will help with faster network rates and bandwidths for certain applications, while congesting others. I will try to describe each important parameter a bit, and present how it effected mixed WiFi and Ethernet network with common PCs.
Kernel Socket Buffers
Do not just change this settings if you do not know what you want to achieve. This should be the first warning here as you might even corrupt loading simple webpage on your computer. Settings have been optimized since kernel 2.6.17 with TCP Autotuning. Kernel has 4MB maximum buffer size defined by default.
Now you want to find sysctl.conf (usually located in /etc/sysctl.conf) and add lines on bottom. This will save your settings even after reboot.
Some useful commands to operate with sysctl.conf
# this will list all commands you have entered into your sysctl.conf
sudo sysctl -p
# get your current settings and save them somewhere nice
sudo sysctl -p | grep mem
# TCP flush will make all FOLLOWING connections to use sysctl.conf settings.
# This does NOT apply for existing ones
sysctl -w net.ipv4.route.flush=1
Add below settings into /etc/sysctl.conf
# set max OS receive buffer for all types of connections
net.core.rmem_max = 16777216
# set max OS send buffer for all types of connections
net.core.wmem_max = 16777216
# set tcp-autotuning range of receive buffer: with first number being minimum
# (this is amount of buffer that system will not go under even under very heavy
# loads), second is default (this is the default amount of each tcp socket ->
# this value overrides value used by other protocols in
# /proc/sys/net/core/rmem_default ) and third number specifies the maximum
# amount of buffer after which TCP will not either send or receive any
# additional packets. TCP operates so that it does not send out a packet if
# receive buffer is full!!!
net.ipv4.tcp_rmem = 32768 87380 16777216
# same thing as above: TCP autotuning but send buffer. Again same min,
# default, max principle as above.
net.ipv4.tcp_wmem = 32768 65536 16777216
# Enable TCP window scaling
net.ipv4.tcp_window_scaling = 1
# Disable TCP timestamp (makes for smaller packages)
net.ipv4.tcp_timestamps = 0