The cart is empty

In today's interconnected world, managing network traffic and effectively utilizing available bandwidth is crucial for maintaining stable and fast network communication. One of the tools that allows us to regulate and monitor bandwidth in Linux, specifically on CentOS 7, is tc (traffic control). In this article, we'll delve into how to use tc to set bandwidth limitations for network devices and monitor this traffic efficiently.

Understanding tc Basics

tc is part of iproute2, a collection of user-space utilities for managing and monitoring network traffic in Linux systems. It enables us to manipulate packet queues, define rules for packet scheduling, and thereby influence how network traffic is processed.

Preparing the System

Before we begin configuring tc, it's important to ensure that your system is up-to-date and that you have all the necessary packages installed. You can do this using the following commands:

sudo yum update
sudo yum install iproute

Basic Configuration

First, let's see how to display the current bandwidth settings for a network interface using tc. This command will show the existing rules for the selected interface:

tc qdisc show dev eth0

Setting Bandwidth Limits

To set a bandwidth limit for a network interface, you can use the following command. In this example, we'll limit the outgoing bandwidth of the eth0 interface to 1Mbps:

sudo tc qdisc add dev eth0 root tbf rate 1mbit burst 32kbit latency 400ms
  • rate specifies the maximum outgoing traffic rate.
  • burst defines the amount of data that can be sent faster than the specified limit to allow for some flexibility in data transmission.
  • latency determines how long packets can wait in the buffer before being sent.

Monitoring Bandwidth Usage

To monitor the effectiveness of the set rules, you can use the command tc -s qdisc show dev eth0, which will display statistics about sent and received packets, including any lost or delayed ones.

Advanced Configuration

tc offers many more options for precisely controlling and monitoring network traffic. For example, you can create complex filters that limit bandwidth only for specific types of traffic or applications, or use different queuing disciplines such as HTB (Hierarchical Token Bucket) for even more precise traffic control.

 

Bandwidth management is crucial for ensuring smooth network operation. tc is a powerful tool that gives you control over how your network bandwidth is utilized. While it may seem complex at first glance, its basic usage is relatively straightforward. If you need more detailed control over your network traffic, it's worth exploring tc further.