nitred / nr-wg-mtu-finder

MIT License
192 stars 22 forks source link

Use `ip link set` for MTU instead of setting up/tearing down tunnel #7

Open kc9jud opened 1 year ago

kc9jud commented 1 year ago

Is there a reason why

ip link set wg0 mtu <MTU>

isn't sufficient for modifying the MTU? Why set up and tear down the tunnel repeatedly? It would also allow this script to work with Wireguard configurations not managed by wg-quick (netplan, systemd, etc.).

nitred commented 1 year ago

To be honest, a VPN is just a means to an end for me. I made the predecessor to this project to solve a real world problem for myself which was to find an optimal MTU pair between my PC and a VPS server that with a limited understanding of how the internals of Wireguard work. I merely followed this tutorial to get it up and running. wg-quick was used in the tutorial and that's the thing I have always used.

Now that you have brought it to my attention, I find the ip link set command very intriguing. I will test it out some time soon and will see if I can integrate it into this project as an alternative mechanism to change the MTUs. I'll keep this issue open and report back my findings. I can't make any promises on the timelines though.

mcr-ksh commented 7 months ago

just change a few lines:

                #self.wg_quick_down()
                #self.update_mtu_in_conf_file()
                #self.wg_quick_up()
                self.ip_link_set_dev()

add the function ip_link_set_dev

    def ip_link_set_dev(self):
        """Set new MTU on device."""
        msg = "ip link set dev"
        print(f"{msg:<50s}", end=": ")
        process = subprocess.Popen(
            ["ip", "link", "set", "dev", f"{self.interface}", "mtu", f"{self.current_mtu}"],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            universal_newlines=True,
        )
        stdout, stderr = process.communicate()
        self.handle_returncode(
            returncode=process.returncode, stdout=stdout, stderr=stderr
        )