10

I'm starting a VPN connection using Network Manager. Once the connection is established I have to change MTU in order it to work properly. For example:

sudo ifconfig ppp0 mtu 777

It is very annoying to execute this command every time I open a VPN connection. Is there any idea to create a script that would execute this command automatically once the connection is established (ppp0 interface is up)?

2 Answers 2

16

Create a script in /etc/network/if-up.d, containing

#!/bin/sh

if [ "$IFACE" = "ppp0" ]; then
    ifconfig ppp0 mtu 777
fi

and make it executable.

3
  • 1
    Two points: 1) the device name is probably "vpn0" these days, and 2) make sure that the filename of the script does not have a "." in it (bugs.launchpad.net/ubuntu/+source/debianutils/+bug/38022)
    – lord_nimon
    Jul 10, 2020 at 0:33
  • This does not seem to work for ubuntu 20.04
    – CutePoison
    Nov 9, 2020 at 20:02
  • Worked for me in Ubuntu 20.04; I had to do this because openconnect --mtu 1200 nor --base-mtu 1200 had any effect with a Pulse Secure VPN. Jan 21, 2021 at 10:39
3

Here's a modernized (using ip instead of ifconfig) and generic (openconnect on the command-line uses tun0, Network Manager uses vpn0 through the network applet; the numbers may vary if another network is already active) variant of @enzotib's excellent answer, tested on Ubuntu 20.04:

#!/bin/bash

if [[ "$IFACE" =~ ^(tun|vpn)[0-9] ]]; then
    ip link set "$IFACE" mtu 777
fi
1
  • How about this way : [[ "${IFACE%?}" =~ (tun|vpn) ]]
    – ETech
    May 27, 2021 at 12:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .