refactor: convert script to automtu package with CI workflow

https://chatgpt.com/share/697112b2-0410-800f-93ff-9372b603d43f
This commit is contained in:
2026-01-21 18:53:44 +01:00
parent 78da3ffc73
commit dcc7a68973
23 changed files with 905 additions and 896 deletions

View File

@@ -1,95 +1,29 @@
# wg-mtu-auto
# automtu
[![GitHub Sponsors](https://img.shields.io/badge/Sponsor-GitHub%20Sponsors-blue?logo=github)](https://github.com/sponsors/kevinveenbirkenbach) [![Patreon](https://img.shields.io/badge/Support-Patreon-orange?logo=patreon)](https://www.patreon.com/c/kevinveenbirkenbach) [![Buy Me a Coffee](https://img.shields.io/badge/Buy%20me%20a%20Coffee-Funding-yellow?logo=buymeacoffee)](https://buymeacoffee.com/kevinveenbirkenbach) [![PayPal](https://img.shields.io/badge/Donate-PayPal-blue?logo=paypal)](https://s.veen.world/paypaldonate)
Auto-detect your egress interface, optionally probe Path MTU (PMTU) using DF-ping,
compute a WireGuard MTU, and apply MTU settings.
Automatically detect the optimal WireGuard MTU by analyzing your local egress interface and optionally probing the Path MTU (PMTU) to one or more remote hosts.
The tool ensures stable and efficient VPN connections by preventing fragmentation and latency caused by mismatched MTU settings.
## Install (editable)
pip install -e .
---
## Usage
## ✨ Features
Show only (no changes):
automtu --dry-run
- **Automatic Egress Detection** — Finds your primary internet interface automatically.
- **WireGuard MTU Calculation** — Computes `wg0` MTU based on egress MTU minus overhead (default 80 bytes).
- **Optional Path MTU Probing** — Uses ICMP “Dont Fragment” (`ping -M do`) to find the real usable MTU across network paths.
- **Multi-Target PMTU Support** — Test multiple remote hosts and choose an effective value via policy (`min`, `median`, `max`).
- **Dry-Run Mode** — Simulate changes without applying them.
- **Safe for Automation** — Integrates well with WireGuard systemd services or Ansible setups.
Probe PMTU to targets and apply on egress:
sudo automtu --pmtu-target registry-1.docker.io --apply-egress-mtu
---
Auto-add WireGuard peer endpoints as targets and apply WG MTU:
sudo automtu --auto-pmtu-from-wg --apply-wg-mtu
## 🚀 Installation
Force WG MTU:
sudo automtu --set-wg-mtu 1372 --apply-wg-mtu
### Option 1 — Using [pkgmgr](https://github.com/kevinveenbirkenbach/package-manager)
Help:
automtu --help
If you use Kevin Veen-Birkenbachs package manager (`pkgmgr`):
```bash
pkgmgr install automtu
````
This will automatically fetch and install `wg-mtu-auto` system-wide.
### Option 2 — Run directly from source
Clone this repository and execute the script manually:
```bash
git clone https://github.com/kevinveenbirkenbach/wg-mtu-auto.git
cd wg-mtu-auto
sudo python3 main.py --help
```
---
## 🧩 Usage Examples
### Basic detection (no PMTU)
```bash
sudo automtu
```
### Specify egress interface and force MTU
```bash
sudo automtu --egress-if eth0 --force-egress-mtu 1452
```
### Probe multiple PMTU targets (safe policy: `min`)
```bash
sudo automtu --pmtu-target 46.4.224.77 --pmtu-target 2a01:4f8:2201:4695::2
```
### Choose median or max policy
```bash
sudo automtu --pmtu-target 46.4.224.77,1.1.1.1 --pmtu-policy median
sudo automtu --pmtu-target 46.4.224.77,1.1.1.1 --pmtu-policy max
```
### Dry-run (no system changes)
```bash
automtu --dry-run
```
---
## 🧪 Development
Run unit tests using:
```bash
make test
```
To see installation guidance (does not install anything):
```bash
make install
```
---