网络性能工具
使用 `iperf`、`netstat` 和 `ss` 等工具测量网络吞吐量、延迟和活动连接
网络性能工具 是 CoddyKit 上的免费 Linux Networking & TCP/IP for Developers 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Linux Networking & TCP/IP for Developers 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Linux Networking & TCP/IP for Developers 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Boost Your Network Insights
Ever wonder how fast your network truly is, or what's happening behind the scenes? In this lesson, we'll dive into powerful Linux tools to measure and understand network performance.
We'll explore iperf for bandwidth, netstat for connections, and ss for detailed socket statistics.
What is Network Performance?
Network performance isn't just about speed! It includes several key metrics:
- Throughput: The amount of data transferred over time (e.g., Mbps).
- Latency: The delay before a transfer of data begins (e.g., ms).
- Jitter: Variation in latency, which can affect real-time applications.
- Packet Loss: Data packets failing to reach their destination.
Measuring these helps diagnose slow or unreliable connections.
Meet iperf: Bandwidth Hero
iperf is a fantastic tool for measuring network throughput. It works in a client-server model, where one machine acts as a server and another as a client, sending data between them.
This allows you to test the raw speed and capacity of a link between two points in your network.
Setting up iperf as a Server
To use iperf, you first need to start a server on one machine. It will listen for incoming connections from clients.
Open a terminal on your server machine and run this command:
iperf3 -sRunning iperf as a Client
Now, on a different machine (your client), you can connect to the iperf server and start a bandwidth test. Replace <server_ip> with the actual IP address of your server.
The output will show you the transfer rate and bandwidth achieved.
iperf3 -c <server_ip>iperf for UDP & Latency
iperf isn't just for TCP! You can also test UDP throughput and observe packet loss or jitter. UDP is often used for real-time applications where speed is critical.
To run a UDP test, add the -u flag. Try it out!
iperf3 -c <server_ip> -u -b 100Mnetstat: Network Statistics
netstat (network statistics) is a classic command-line tool that displays network connections, routing tables, interface statistics, and more.
It's great for quickly seeing what ports are open and what connections are active on your system.
Viewing Active Connections with netstat
To see all active TCP and UDP connections, along with listening ports, use the following flags:
-t: TCP connections-u: UDP connections-l: Listening sockets-n: Numeric addresses (don't resolve hostnames)
This gives a raw, fast overview.
netstat -tulnIntroducing ss: Socket Statistics
While netstat is useful, ss (socket statistics) is its modern, faster, and more powerful successor. It can display more information about sockets than netstat.
ss directly queries kernel data structures, making it quicker and more efficient, especially on systems with many connections.
Exploring Sockets with ss
ss uses similar flags to netstat but often provides more detail or performs faster. Here are a couple of common uses:
ss -tuln: Same as netstat, shows TCP/UDP listening ports.ss -s: Provides a summary of socket statistics (e.g., total TCP established, UDP in use).
Give ss -s a try to see a quick summary!
ss -sQuick Check: Performance Tools
You've learned about iperf, netstat, and ss. Which of these tools is primarily used to measure network bandwidth or throughput?
Recap: Monitor Your Network
Great job! You've explored essential tools for network performance:
iperf: Your go-to for measuring network throughput (bandwidth) and testing latency/jitter with TCP and UDP.netstat: A classic for viewing active connections, listening ports, and basic network statistics.ss: The modern, faster alternative tonetstatfor detailed socket information.
These tools are invaluable for diagnosing network issues and ensuring optimal performance.
常见问题解答
「网络性能工具」课时是免费的吗?
是的 — 「网络性能工具」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Linux Networking & TCP/IP for Developers 课程的其余内容,请升级到 CoddyKit PRO。 Linux Networking & TCP/IP for Developers 课程共包含 4 节课。
「网络性能工具」这节课中我会学到什么?
使用 `iperf`、`netstat` 和 `ss` 等工具测量网络吞吐量、延迟和活动连接 你通过在浏览器中直接运行的动手代码来练习 Linux Networking & TCP/IP for Developers,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Linux Networking & TCP/IP for Developers 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Linux Networking & TCP/IP for Developers 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「网络性能工具」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Linux Networking & TCP/IP for Developers 课中编写并运行代码吗?
能。每节 Linux Networking & TCP/IP for Developers 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。