TCP-Optimize is a script designed for in-depth TCP/UDP network tuning on Linux VPS systems. It is primarily used to optimize system parameters, congestion control, buffers, connection queues, and connection tracking capabilities when a VPS is used as a network relay server.
For cross-border connections, high-latency links, and networks with high packet loss, the default Linux network parameters are often unsuitable for scenarios involving high concurrency or high-traffic forwarding. This script performs multiple kernel-level optimizations with a single click, lowering the barrier to manual configuration. It is suitable for use in scenarios such as transit nodes, proxy servers, cross-border business nodes, and remote connection acceleration.
Features
IPv4 Priority Resolution
The script can set the DNS resolution priority to IPv4-first by adjusting gai.conf.
In some VPS environments, if the quality of the default IPv6 route is poor, issues such as slow connection handshakes, stuttering access, or route detours may occur. Enabling IPv4 priority can reduce connection problems caused by abnormal IPv6 routing and improve access stability.
BBR + FQ Congestion Control
The script supports enabling the Google BBR congestion control algorithm in conjunction with Fair Queue scheduling.
BBR is better suited for network environments such as high-latency and cross-border links; it can mitigate the impact of packet loss and retransmission to some extent, thereby improving single-threaded throughput performance. FQ queue scheduling helps improve packet queuing efficiency, making network forwarding more stable.
Production-Grade Kernel Parameter Tuning
TCP-Optimize dynamically calculates buffer parameters based on the server’s memory status—for example, setting the upper limit of network buffers as a percentage of total memory—while expanding the connection queue, optimizing TCP parameters, enabling IP forwarding, and adjusting the conntrack connection tracking table.
These parameters are crucial for VPS servers acting as relay servers, particularly in scenarios involving a large number of connections, extended forwarding periods, or mixed UDP/TCP traffic, as they help reduce connection bottlenecks and improve system capacity.
Multi-core RPS Distribution on Network Cards
The script supports enabling RPS, or Receive Packet Steering.
Once enabled, soft interrupts generated when the network card receives packets can be distributed across multiple CPU cores for processing, reducing the issue of excessive SoftIRQ consumption by a single core. For VPS instances with 2 or more cores, enabling RPS is generally more beneficial and is suitable for high-forwarding, high-concurrency network scenarios.
One-Click Configuration Rollback
TCP-Optimize also provides a one-click rollback feature, which cleans up the standalone configuration files generated by the script and restores memory-related parameters to their system defaults.
If you discover incompatibilities with certain services after optimization, or if you need to restore the system to its original state, you can quickly revert the configuration using the rollback feature to minimize testing risks.
Deployment Method
Method 1: Installation via GitHub Raw Link
We recommend using the GitHub Raw link for installation:
bash <(curl -sL https://raw.githubusercontent.com/Madhatter2099/TCP-Optimize/main/tcp.sh)
Once installation is complete, the script will automatically save to:
/usr/local/bin/tcp.sh
A shortcut command will also be created. In the future, simply enter the following command to open the script panel:
t
Method 2: Installing via jsDelivr CDN Acceleration
If raw.githubusercontent.com is inaccessible, you can use the jsDelivr CDN mirror for installation:
bash <(curl -sL https://cdn.jsdelivr.net/gh/Madhatter2099/TCP-Optimize@main/tcp.sh)
This method is suitable for server environments where GitHub Raw connections are unstable or access speeds are slow.
Method 3: Manual Download and Deployment
You can also manually download the script and create a shortcut command:
wget -O /usr/local/bin/tcp.sh https://raw.githubusercontent.com/Madhatter2099/TCP-Optimize/main/tcp.sh
chmod +x /usr/local/bin/tcp.sh
ln -sf /usr/local/bin/tcp.sh /usr/local/bin/t
t
Recommended Execution Order
When using for the first time, it is recommended to execute in the following order:
1. First, perform production-level kernel tuning
Priority:
選項 3:生產級內核調優
This option automatically includes core parameters such as BBR + FQ, buffer optimization, conntrack optimization, connection queue expansion, and IP forwarding; it is the most important optimization step in the entire script.
2. Enable IPv4 priority based on your network environment
If IPv6 is enabled on the VPS but the quality of the IPv6 egress routing is poor, we recommend continuing with:
選項 1:IPv4 優先
This will help avoid issues such as detours, slow handshakes, or unstable connections that may occur when some connections default to using IPv6.
3. For multi-core VPSs, it is recommended to enable RPS
If your VPS is configured with 2 cores or more, you can proceed to select:
選項 4:網卡多核分發
Once enabled, network interface software interrupts can be distributed across multiple CPU cores, reducing single-core bottlenecks and improving stability during high-concurrency forwarding.
Applicable Scenarios
TCP-Optimize is best suited for the following scenarios:
- VPS used as a network relay server;
- Optimization for cross-border connections with high latency and high packet loss;
- TCP/UDP forwarding services;
- Proxy nodes, tunnel nodes, and remote connection acceleration;
- High-concurrency connection or scenarios with a large number of long-running connections;
- Linux servers requiring optimization of BBR, conntrack, buffer, and queue parameters.
Please note that network optimization results may be affected by factors such as the VPS data center’s network lines, ISP routing, evening peak-hour congestion, and the quality of the target network. The script can optimize system-side parameters but cannot alter the quality of the upstream network lines themselves.
Usage Recommendations
We recommend running the script first on a brand-new server or in a test environment to ensure that services operate normally before deploying it to a production environment. If the VPS is already hosting critical services, we recommend backing up the current system configuration in advance, especially related configuration files such as /etc/sysctl.conf, /etc/sysctl.d/, and /etc/security/limits.conf.
For VPSs with limited memory, it is not recommended to blindly increase buffer parameters; for single-core VPSs, RPS optimization has limited value, so you should prioritize implementing BBR + FQ and basic kernel optimizations.
Open Source Page
Project URL:
https://github.com/Madhatter2099/TCP-Optimize
Brief Comments
TCP-Optimize has a clear focus, primarily targeting VPS network transit, cross-border link optimization, and high-concurrency connection scenarios. Compared to enabling BBR on its own, this script covers multiple key parameters—including IPv4 priority, BBR + FQ, kernel buffers, conntrack, connection queues, IP forwarding, and RPS multi-core distribution—making it ideal for users who want to quickly optimize their network.
If your VPS is primarily used for hosting websites and does not experience high traffic, the default network parameters are usually sufficient; however, if your VPS is used for cross-border relaying, proxy forwarding, remote connections, or transmission over high-latency links, then this type of optimization script will be more practical.
Overall, TCP-Optimize is better suited as a VPS network optimization tool. We recommend running it on a test node first and deploying it to production servers only after confirming stability.






















