Files
shell-scripts/v2ray示例/路由转发内核优化.sh

35 lines
1.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
kernel_config_file=/etc/sysctl.d/import_kernel.conf
cat >> ${kernel_config_file} <<EOF
# 开启bbr
net.ipv4.tcp_fastopen = 3
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
#增加缓冲区大小可以提高吞吐量
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
#缩短超时时间可以提高响应速度。
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_intvl = 15
# 避免IP碎片化可以提高性能。
net.ipv4.ipfrag_low_thresh = 65536
net.ipv4.ipfrag_high_thresh = 131072
# TCP SACK选择确认在路由器环境中通常不必要。
net.ipv4.tcp_sack = 0
# 快速转发可以提高转发性能。
net.ipv4.ip_forward_fast_path = 1
# 禁用日志记录可以节省资源。
net.ipv4.conf.all.log_martians = 0
net.ipv4.conf.default.log_martians = 0
net.ipv4.route.flush=1
# 缩短ARP超时时间可以提高ARP响应速度。
net.ipv4.neigh.default.gc_stale_time = 120
# 增加哈希表大小可以提高路由查找性能。
net.ipv4.neigh.default.hash_buckets = 1024
EOF
sysctl -p ${kernel_config_file}