当前位置:首页 > 站长知识 > 正文内容

Debian网络优化设置方法

2024-08-27站长知识38

在Debian系统中,通过合理的配置和优化工具,可以提高网络的稳定性和传输速度,提升用户体验。本教程将介绍一些常用的Debian网络优化工具,包括最佳MTU设置、WAN TCP优化以及Netfilter网络过滤框架等方面。

网络优化工具列表:

软件包流行度大小说明
iftopV:7, I:10293显示一个网络接口上的带宽使用信息
iperfV:3, I:44360互联网协议带宽测量工具
ifstatV:0, I:759接口统计监控
bmonV:1, I:17144便携式带宽监视器和网速估计工具
ethstatusV:0, I:340快速测量网络设备吞吐的脚本
bingV:0, I:080实验性的随机带宽测试器
bwm-ngV:1, I:1495小巧简单的控制台带宽监测器
ethstatsV:0, I:023基于控制台的以太网统计监视器
ipfmV:0, I:082带宽分析工具

一、 最佳MTU

在网络管理中,通常可以依赖网络管理器自动设置最佳最大传输单元(MTU)。然而,在某些特定场景下,我们可能需要手动调整MTU。MTU是指数据包在没有IP分片的情况下能够携带的最大字节数,对于IPv4来说,这个值还需要加上28字节,而对于IPv6来说,需要加上48字节。

例如,通过使用ping命令并添加”-M do”选项来发送不同大小的ICMP数据包进行实验后,你可能会发现IPv4连接的MTU为1460字节,而IPv6连接的MTU为1500字节。

$ ping -4 -c 1 -s $((1500-28)) -M do www.debian.org
PING  (149.20.4.15) 1472(1500) bytes of data.
ping: local error: message too long, mtu=1460
---  ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
$ ping -4 -c 1 -s $((1460-28)) -M do www.debian.org
PING  (130.89.148.77) 1432(1460) bytes of data.
1440 bytes from klecker-misc.debian.org (130.89.148.77): icmp_seq=1 ttl=50 time=325 ms
---  ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 325.318/325.318/325.318/0.000 ms
$ ping -6 -c 1 -s $((1500-48)) -M do www.debian.org
PING www.debian.org(mirror-csail.debian.org (2603:400a:ffff:bb8::801f:3e)) 1452 data bytes
1460 bytes from mirror-csail.debian.org (2603:400a:ffff:bb8::801f:3e): icmp_seq=1 ttl=47 time=191 ms
--- www.debian.org ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms

最佳 MTU 值的基本指引方法:

网络环境MTU基本原理
拨号连接(IP: PPP)576标准的
以太网连接 (IP: DHCP 或固定)1500默认标准值

除了这些基本的指引方法外,还具有以下方法:

使用任何隧道方式的最佳 MTU 需要进一步减去它们上面的头部;

MTU 值不应当超过通过实验验证的 PMTU 值;

当遇到其它限制的时候,较大的 MTU 值通常比较好。

最大分片大小 (MSS) 是另外一种衡量包大小的方法。MSS 和 MTU 的关系如下.

对于 IPv4, MSS = MTU – 40

对于 IPv6,MSS = MTU – 60

二、WAN TCP优化

通过调整 TCP 缓冲区大小参数,可以最大限度地提高 TCP 吞吐量,如现代高带宽和高延迟广域网的 “TCP 调整”。到目前为止,Debian 目前的默认设置即使在我的局域网内使用快速的 1G bps FTTP 服务时也能很好地运行。

三、Netfilter网络过滤框架

Netfilter 使用 Linux 内核模块提供状态防火墙和网络地址转换 (NAT) 框架。

防火墙工具列表:

软件包流行度大小说明
iptablesV:315, I:7402414netfilter 管理工具(iptables(8) 用于 IPv4, ip6tables(8) 用于 IPv6)
arptablesV:0, I:1100netfilter 管理工具(arptables(8) 用于 ARP)
ebtablesV:14, I:29264netfilter 管理工具 (ebtables(8) 用于以太网桥)
iptstateV:0, I:2119持续性监控 netfilter 状态 (和 top(1) 相似)
ufwV:53, I:75857Uncomplicated Firewall (UFW) is a program for managing a netfilter firewall
gufwV:5, I:103660graphical user interface for Uncomplicated Firewall (UFW)
firewalldV:9, I:142496firewalld is a dynamically managed firewall program with support for network zones
firewall-configV:0, I:21164graphical user interface for firewalld
shorewall-initV:0, I:088Shoreline 防火墙 初始化
shorewallV:3, I:83090Shoreline 防火墙, netfilter 配置文件生成器
shorewall-liteV:0, I:071Shoreline 防火墙, netfilter 配置文件生成器 (精简版)
shorewall6V:0, I:11334Shoreline 防火墙, netfilter 配置文件生成器(IPv6 版本)
shorewall6-liteV:0, I:071Shoreline 防火墙, netfilter 配置文件生成器 (IPv6,精简版)

netfilter 主要的用户层程序是 iptables(8).你能从 shell 手工交付式的配置 netfilter,使用 iptables-save(8) 保存当前状态,当系统重启时,通过 init 脚本调用 iptables-restore(8) 来恢复。