DAILY DOCDAILY DOC
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
Rust
Node
Notes
Ubuntu
Leetcode
  • it-tools
  • excalidraw
  • linux-command
  • linux
  • bash alias
  • chmod
  • linux useful command
  • date
  • extract translation from git diff
  • fail2ban
  • globbing
  • localhost
  • mail
  • memo 内存测试
  • nohup(no hang up)
  • setup env
  • ssh

    • ssh 教程
    • github clone
    • ssh.localhost.run 端口转发
    • ssh 安全
  • systemd service
  • 分析ubuntu系统登录日志文件
  • vpn

    • vpn 教程
    • Algo
    • clashX
    • firezone
    • lantern
    • pac 代理配置
    • Setup vpn
    • shadowsocks
    • VPN
    • VPN 速度优化
    • wireguard cron
    • 修改wireguard端口
  • webhook

VPN 速度优化

以ubuntu 机器为例

DNS 解析

Cloudflare 测试后丢包率最低 OpenDNS 速度最快

# OpenDNS Cloudflare
1.1.1.1, 1.0.0.1, 208.67.222.222, 208.67.220.220
# 208.67.222.222, 208.67.220.220, 1.1.1.1, 1.0.0.1
# google 
8.8.8.8, 8.8.4.4
# Cloudflare
1.1.1.1, 1.0.0.1
# OpenDNS
208.67.222.222, 208.67.220.220
# Quad9
9.9.9.9, 149.112.112.112
# AdGuard DNS
94.140.14.14, 94.140.15.15
# 或者其他自定义的

修改 MTU 的值

ip link show 
ip link set dev <interface-name> mtu 1500 
# ip link set dev wg0 mtu 1500 

# verify 
ip link show wg0

增加并发链接数量

增加打开文件数限制 /etc/security/limits.conf

* soft nofile 65535
* hard nofile 65535

系统资源配置

wireguard 用的是 udp 协议 shadowsocks 用的是tcp 协议

编辑/etc/sysctl.conf

# Increase the number of simultaneous connections: 
net.ipv4.tcp_tw_reuse = 1 # 启用 TIME_WAIT 状态的 socket 可以重用。
net.ipv4.tcp_tw_recycle = 1 # 启用 TIME_WAIT 状态的 socket 可以被快速回收
net.ipv4.tcp_fin_timeout = 30 # 设置 TIME_WAIT 状态的 socket 的等待时间为 30 秒
net.ipv4.tcp_max_syn_backlog = 65536 # 设置最大 SYN 等待队列的长度为 65536。
net.core.somaxconn = 65535 # 设置系统的最大并发连接数为 65535

# Enable TCP Fast Open
net.ipv4.tcp_fastopen = 3 # 启用 TCP 快速打开

# Optimize TCP buffer sizes
net.core.rmem_max = 16777216 # 设置接收缓存区的最大大小为 16 MB
net.core.wmem_max = 16777216 # 设置发送缓存区的最大大小为 16 MB
net.ipv4.tcp_rmem = 4096 87380 16777216 # 设置接收缓存区的初始大小、最小大小和最大大小为 4096、87380 和 16777216 字节
net.ipv4.tcp_wmem = 4096 65536 16777216 # 设置发送缓存区的初始大小、最小大小和最大大小为 4096、65536 和 16777216 字节



# net.core.default_qdisc = fq  # 配置指定了内核使用的默认队列管理算法(qdisc)。它表示使用 fair queuing(FQ)算法。FQ是一种流量控制算法,用于平均分配带宽,以避免一个连接占用所有带宽的情况
# net.ipv4.tcp_congestion_control = bbr # 配置指定了内核使用的 TCP 拥塞控制算法。它表示使用 BBR(Bottleneck Bandwidth and RTT)拥塞控制算法。BBR 是一种比较新的 TCP 拥塞控制算法,用于在计算机网络中提高网络性能。BBR 具有较高的速率,能够利用网络带宽最大化。


# udp
# Increase the maximum number of datagrams that can be sent and received in a single operation
net.core.rmem_default = 87380
net.core.wmem_default = 87380


Apply the changes

sudo sysctl -p 

Last Updated:
Contributors: rosendo
Prev
VPN
Next
wireguard cron