8000 feat: add custom MTU option to OpenVPN setup by Knogle · Pull Request #1300 · angristan/openvpn-install · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add custom MTU option to OpenVPN setup #1300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Knogle
Copy link
@Knogle Knogle commented Jun 1, 2025

Background / Rationale:

  • By default, OpenVPN uses an MTU of approximately 1500 bytes minus header overhead. However, this default can cause fragmentation issues in environments involving nested VPN tunnels, DOCSIS networks, NAT setups, MPLS networks, or certain ISPs and mobile carriers which impose smaller MTU sizes.
  • Allowing administrators to specify an MTU that matches their actual path MTU helps prevent these issues by aligning the VPN traffic with network constraints.

Implemented Changes:

  1. Installation Wizard (installQuestions()):

    • Immediately after protocol selection (UDP/TCP), users are prompted: Do you want to set a custom MTU for the VPN interface? 1) No, keep default 2) Yes, specify a custom MTU
    • If a custom MTU is chosen, input is validated to be between 576 and 1500 bytes, ensuring compliance with standard minimum and maximum MTU sizes.
    • The decision is stored using two variables:
      • CUSTOM_MTU ("y" or "n")
      • MTU (numeric user input if applicable)
  2. Server configuration (installOpenVPN()):

    • If CUSTOM_MTU=="y", the script automatically appends to /etc/openvpn/server.conf: tun-mtu <MTU> mssfix <MTU - 40>
    • The mssfix setting dynamically adjusts TCP packet sizes to account for VPN overhead (typically IP + TCP/UDP headers of ~40 bytes). This prevents fragmentation and improves throughput and stability.
  3. Client Template (client-template.txt):

    • If a custom MTU is selected, the script also ensures each generated client .ovpn configuration file includes: tun-mtu <MTU> mssfix <MTU - 40>
    • This approach guarantees consistency between server and client MTU settings, eliminating potential mismatches.

Benefits of this Feature:

  • Reduced Packet Fragmentation: By precisely matching MTU settings to actual network conditions, fragmentation-related performance issues (delays, retransmissions, and reduced throughput) are mitigated or entirely eliminated.

  • Enhanced TCP Throughput: The automatic inclusion of mssfix optimizes TCP segment sizes, significantly improving overall VPN performance for TCP connections.

  • Greater Network Compatibility: Facilitates optimal operation in scenarios involving nested VPN setups (e.g., OpenVPN within WireGuard or IPsec tunnels), cellular network connections, or specific ISP-imposed MTU constraints.

  • Simplified Configuration Management: Custom MTU and MSS settings applied consistently across server and client configurations reduce administrative overhead and potential configuration errors.

**Background / Rationale:**

- By default, OpenVPN uses an MTU of approximately 1500 bytes minus header overhead. However, this default can cause fragmentation issues in environments involving nested VPN tunnels, DOCSIS networks, NAT setups, MPLS networks, or certain ISPs and mobile carriers which impose smaller MTU sizes.
- Allowing administrators to specify an MTU that matches their actual path MTU helps prevent these issues by aligning the VPN traffic with network constraints.

**Implemented Changes:**

1. **Installation Wizard (`installQuestions()`):**
   - Immediately after protocol selection (UDP/TCP), users are prompted:
     ```
     Do you want to set a custom MTU for the VPN interface?
     1) No, keep default
     2) Yes, specify a custom MTU
     ```
   - If a custom MTU is chosen, input is validated to be between 576 and 1500 bytes, ensuring compliance with standard minimum and maximum MTU sizes.
   - The decision is stored using two variables:
     - `CUSTOM_MTU` ("y" or "n")
     - `MTU` (numeric user input if applicable)

2. **Server configuration (`installOpenVPN()`):**
   - If `CUSTOM_MTU=="y"`, the script automatically appends to `/etc/openvpn/server.conf`:
     ```
     tun-mtu <MTU>
     mssfix <MTU - 40>
     ```
   - The `mssfix` setting dynamically adjusts TCP packet sizes to account for VPN overhead (typically IP + TCP/UDP headers of ~40 bytes). This prevents fragmentation and improves throughput and stability.

3. **Client Template (`client-template.txt`):**
   - If a custom MTU is selected, the script also ensures each generated client `.ovpn` configuration file includes:
     ```
     tun-mtu <MTU>
     mssfix <MTU - 40>
     ```
   - This approach guarantees consistency between server and client MTU settings, eliminating potential mismatches.

**Benefits of this Feature:**

- **Reduced Packet Fragmentation:**
  By precisely matching MTU settings to actual network conditions, fragmentation-related performance issues (delays, retransmissions, and reduced throughput) are mitigated or entirely eliminated.

- **Enhanced TCP Throughput:**
  The automatic inclusion of `mssfix` optimizes TCP segment sizes, significantly improving overall VPN performance for TCP connections.

- **Greater Network Compatibility:**
  Facilitates optimal operation in scenarios involving nested VPN setups (e.g., OpenVPN within WireGuard or IPsec tunnels), cellular network connections, or specific ISP-imposed MTU constraints.

- **Simplified Configuration Management:**
  Custom MTU and MSS settings applied consistently across server and client configurations reduce administrative overhead and potential configuration errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0