System Resource Limits and Protection
System Resource Limits and Protection
Configure system limits to prevent resource exhaustion attacks. Edit /etc/security/limits.conf
:
# Limit for web server user
www-data soft nproc 1024
www-data hard nproc 2048
www-data soft nofile 2048
www-data hard nofile 4096
Enable and configure sysctl parameters for network security in /etc/sysctl.conf
:
# IP Spoofing protection
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
# Ignore ICMP redirects
net.ipv4.conf.all.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
# Ignore send redirects
net.ipv4.conf.all.send_redirects = 0
# Disable source packet routing
net.ipv4.conf.all.accept_source_route = 0
net.ipv6.conf.all.accept_source_route = 0
# Log Martians
net.ipv4.conf.all.log_martians = 1
# Ignore ICMP ping requests
net.ipv4.icmp_echo_ignore_broadcasts = 1
# SYN flood protection
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_max_syn_backlog = 4096
# Increase system IP port limits
net.ipv4.ip_local_port_range = 1024 65535
# Increase TCP max buffer size
net.core.rmem_max = 8388608
net.core.wmem_max = 8388608
net.core.netdev_max_backlog = 5000
net.ipv4.tcp_rmem = 4096 87380 8388608
net.ipv4.tcp_wmem = 4096 65536 8388608
Apply sysctl settings: sudo sysctl -p