Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Limited Network bandwidth in Linux system

2025-03-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use limited network bandwidth in Linux system", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "How to use limited network bandwidth in Linux system"!

Limiting the rate of an application in Linux

One way to limit network traffic rates is through a command-line tool called trickle. Trickle allows you to change the traffic of any particular program by preloading a rate-limiting socket library while the program is running. A nice feature of the trick command is that it runs only in user space, which means that you don't need root privileges to limit bandwidth usage for a program. To be able to control the bandwidth of a program using a trickle program, the program must use a socket interface that is not a static link library. Trickle can help when you want to rate limit a program that doesn't have built-in bandwidth control.

Install trickle in Ubuntu, Debian and their derivatives:

The code is as follows:

$ sudo apt-get install trickle

In Fdora or CentOS/RHEL (with EPEL software repository):

The code is as follows:

$ sudo yum install trickle

The basic usage of trickles is as follows. Simply put the trick command (and the rate parameter) before the command you want to run.

The code is as follows:

$ trickle -d -u

This limits the download and upload rates of to certain values (in KBytes/s).

For example, set the maximum upload bandwidth for your SCP session to 100 KB/s:

The code is as follows:

$ trickle -u 100 scp backup.tgz alice@remote_host.com:

If you want, you can set the maximum download rate for your Firefox browser (e.g., 300 KB/s) by creating a custom launcher using the command below.

The code is as follows:

trickle -d 300 firefox %u

Finally, trickle can also run in daemon mode, where it limits the total bandwidth of all running programs started by trickle. Start trickle as a daemon (for example, trickled):

The code is as follows:

$ sudo trickled -d 1000

Once the trickled daemon is running in the background, you can start other programs with the trickle command. If you launch a program via trick, the maximum download rate for that program will be 1000 KB/s, if you launch another program via trick, the rate limit for each program will be limited to 500 KB/s, and so on.

Limiting the rate of a network interface in Linux

Another way to control your bandwidth resources is to limit bandwidth on each interface. This is especially useful when you share the upstream bandwidth of your network connection with others. Like everything else, Linux has a tool to do this for you. Wondershapers do that.

Wondershaper is actually a shell script that uses tc to define traffic shaping commands and QoS to handle specific network interfaces. Outgoing traffic is placed in queues of different priority levels to achieve the purpose of limiting the rate of outgoing traffic, while incoming traffic is rate limited by packet loss.

In fact, wondershaper's stated goal is not just to cap the bandwidth of an interface; it also tries to keep the latency of interactive sessions such as SSH low while bulk downloads or uploads are in progress. Similarly, it also controls batch uploads (e.g. Dropbox syncing) so downloads don't "choke" and vice versa.

Install wondershaper in Ubuntu Debian and its derivatives:

The code is as follows:

$ sudo apt-get install wondershaper

Install wondershaper in Fdora or CentOS/RHEL with EPEL software repository:

The code is as follows:

$ sudo yum install wondershaper

The basic use of wondershapers is as follows:

The code is as follows:

$ sudo wondershaper

For example, set the maximum download/upload bandwidth of eth0 to 1000Kbit/s and 500Kbit/s respectively:

The code is as follows:

$ sudo wondershaper eth0 1000 500

You can also remove the speed limit by running the following command:

The code is as follows:

$ sudo wondershaper clear eth0

If you're interested in how wondershaper works, you can read its shell script source file (/sbin/wondershaper).

At this point, I believe that everyone has a deeper understanding of "how to use limited network bandwidth in Linux systems," so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report