Tuning OpenVPN MTU and MSS Clamping for Stability


OpenVPN is a widely used VPN solution known for its flexibility and strong security. However, optimizing its performance can be challenging, especially when dealing with network instability or throughput issues. One of the most critical aspects of OpenVPN performance is managing the Maximum Transmission Unit (MTU) and the Maximum Segment Size (MSS). Both of these settings are crucial for maintaining a stable connection and preventing packet fragmentation, which can degrade performance or cause connectivity issues.

Understanding MTU and MSS

MTU defines the largest packet size that can be transmitted over a network. If a packet exceeds the MTU of a network interface, it must be fragmented, potentially causing packet loss or delays. MSS, on the other hand, is the maximum amount of data that can be sent in a single TCP segment, excluding the TCP header. Both of these parameters can be configured to ensure efficient and reliable communication over OpenVPN.

Why MTU Tuning is Important

When an OpenVPN connection is established, the MTU setting can have a significant impact on the reliability of the connection. If the MTU is set too high, it can cause packet fragmentation, leading to slower speeds and connection drops. On the other hand, if the MTU is set too low, it can unnecessarily reduce the efficiency of the VPN connection.

To achieve optimal performance, the MTU should be set according to the maximum size allowed by the network, but without exceeding the path MTU (PMTU) between the client and server. OpenVPN uses the “Path MTU Discovery” feature to dynamically adjust the MTU based on the network’s characteristics, but manual adjustments may be necessary in some situations.

MTU Discovery and OpenVPN

OpenVPN supports Path MTU Discovery (PMTUD), which helps to automatically determine the largest packet size that can be transmitted without fragmentation. However, in some cases, this automatic discovery may not work as expected due to network conditions like firewalls or routers that block ICMP packets, which are used in PMTUD.

To manually tune the MTU setting in OpenVPN, the following steps can be taken:

tun-mtu 1500
mssfix 1400

The tun-mtu directive sets the MTU for the tunnel interface, while the mssfix directive reduces the MSS for TCP traffic, which can help avoid fragmentation in cases where the MTU is too large.

Setting MSS Clamping

MSS clamping is a technique used to prevent TCP fragmentation by reducing the MSS of packets to fit within the network’s MTU. By default, OpenVPN does not modify the MSS of outgoing packets, which can lead to fragmentation if the MSS exceeds the MTU of the network path. To resolve this, you can enable MSS clamping in OpenVPN by using the following configuration:

mssfix 1400

This setting ensures that TCP segments are never larger than 1400 bytes, which is a common value that avoids fragmentation for most VPN connections. The mssfix directive is particularly useful when dealing with networks that have varying MTU values and where fragmentation might occur.

Configuring MTU and MSS on the Server

To configure the MTU and MSS settings on the OpenVPN server, you can use the following configuration directives in the server configuration file:

dev tun
tun-mtu 1500
mssfix 1400

Here, dev tun specifies the use of a TUN device for routing IP traffic, tun-mtu 1500 sets the MTU to 1500 bytes, and mssfix 1400 ensures that the MSS is clamped at 1400 bytes.

Configuring MTU and MSS on the Client

Similar to the server-side configuration, the OpenVPN client configuration file also needs to specify the MTU and MSS settings. This ensures that the connection remains stable from the client side:

dev tun
tun-mtu 1500
mssfix 1400

The client configuration typically mirrors the server settings to ensure that both ends of the tunnel agree on the MTU and MSS values. In some cases, the client may require a lower MTU setting if the network path has a lower PMTU.

Testing and Troubleshooting MTU and MSS

After adjusting the MTU and MSS settings, it is essential to test the VPN connection to ensure that it is stable and free from fragmentation issues. One way to do this is to use the ping command to check for packet loss or fragmentation:

ping -M do -s 1472 

Here, -M do tells ping to not fragment packets, and -s 1472 specifies the payload size (1472 bytes plus the 28 bytes for the ICMP header equals 1500 bytes total, which is a typical MTU value). If the ping succeeds without fragmentation, it indicates that the MTU setting is appropriate. If the ping fails, you may need to lower the MTU value slightly.

Additional Considerations for MTU and MSS

While adjusting the MTU and MSS settings is important, other factors such as the underlying network conditions, the type of encryption used by OpenVPN, and the quality of the Internet connection can also impact performance. It is essential to monitor the VPN connection regularly and adjust the MTU and MSS values as necessary based on the network environment.

We earn commissions using affiliate links.


14 Privacy Tools You Should Have

Learn how to stay safe online in this free 34-page eBook.


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top