Setting the MTU automatically in Debian

Last Updated on August 1, 2017 by Dave Farquhar

I run this website off a server running on an ADSL line in a spare bedroom of my home. That causes some weird issues from time to time, like the time I had to figure out setting the MTU automatically in Debian.

Why Debian?

My server of choice is Debian, because it’s Linux which makes it fast, reliable, and cheap, and Debian makes it pretty easy to install only what you want and need, so I can have a server OS that’s only using 125 megabytes of disk space, leaving most of my drive available for content. I like having space for content.

This will work in Debian-derived systems like Ubuntu and Linux Mint too.

PPPoE issues

Now, the downside of modern DSL: Southwestern Bell, like most ISPs these days, uses PPPoE. So not only can your IP address change with no notice whatsoever, you also have the hassles of PPPoE. With the default settings, some unknown but noticeably large percentage of web users won’t be able to access a web server running on a DSL connection using PPPoE.

The reason is MTU and fragmentation.Yes, you remember MTU if you used Windows 9x back in the bad old days of dialup. Tweakers would play around with the MTU settings in hopes of squeezing just a little more performance out of their 56K modems, and they would swear that one utility did a better job than any others, or that this MTU setting was optimal and the conventional wisdom of 576 stank… Remember those flamewars?

Well, with broadband, theoretically the right setting to use is 1500. Trouble is, PPPoE steals some of that packet space, and the result is something worse than slow speeds. In some scenarios, you completely vanish.

Setting the MTU

The way to make my website reappear is to issue the command ifconfig eth0 mtu 1472. The exact number doesn’t seem to matter much. It appears for me that 1472 is the maximum I can use. (It can vary from ISP to ISP, in case you’re wondering.)

Excellent. Problem solved.

Not so fast. Problem solved until my server reboots. Linux doesn’t need to reboot, right? Right you are. But here in St. Louis, the power likes to hiccup a lot, especially in the summertime. My server is on a UPS, but every once in a while, in the middle of the night, there must be a long enough power failure that my UPS dies, because every once in a while I fall off the ‘net again.

To set the default MTU permanently–that is, to change it automatically on bootup–one normally would change the ifup script or the rc.startup script. Except Debian doesn’t have either of those.

My kludgy solution: cron. Log in as root, issue the command crontab -e, and add the following line:

*/2 * * * * ifconfig eth0 mtu 1472

With this in place, only seconds will elapse between the time my power comes back on for good and I reappear on the ‘net. I can live with that.

More Debian tricks

If you change your network card or motherboard, you don’t have to reinstall Debian but you may lose eth0. Here’s how to get eth0 back. And here’s how to get a list of the installed packages in Debian.

If you found this post informative or helpful, please share it!

5 thoughts on “Setting the MTU automatically in Debian

  • August 4, 2004 at 12:27 am
    Permalink

    Interesting. I have a little Debian box that I’m using as an auxiliary workstation at my office. No, I didn’t master the arcane art of Debian installs, the new beta installer is pretty usable.

    I never knew that Debian didn’t have an rc.local or equivalent. Also curious, "who -r" reports runlevel 2, tho I boot to a gui login. The rc2.d – rc5.d directories seem the same. I also see an /etc/rcS.d directory, complete with a README file. The README says that the scripts are executed once, even in single user mode. Another curiosity, since it also states that "* After the S40 scripts have executed, all local file systems are mounted and networking is available". I don’t know why networking would start in single user mode.

    Besides being Sarge based, I also installed the 2.6 kernel, so I don’t know if this will be the same for your presumably more conservative server. If so, though, it would appear that making a short init script and linking it with a link in /etc/rcS.d and a link name starting with S5 should do the trick.


    -Steve

  • August 4, 2004 at 9:21 am
    Permalink

    I’ve never used it, but I see that inittab has an action field called "powerokwait" that should execute when the UPS notifies init that the power is back on. I don’t know what the hardware requirements would be. My UPS came with a cable and some windows-only software, but I never tried to use it. I don’t run a server, and just want the UPS to filter the line power and give me time to shut down. Anyway, "cron" might be more robust.

    I’m running a hard-drive install of Knoppix with the 2.6 kernel. Having come recently from Mandrake, I’m no expert on the Debian boot scripts. I have a (empty) directory "/etc/rc.boot" which I supposed was for local stuff.

    For "who -r" I get "run-level 5", which matches the default runlevel in inittab.


    Yeah, but it’s a moist heat.

    • August 4, 2004 at 10:22 am
      Permalink

      UPS monitoring tools need either a USB or RS-232 link between the PC and the UPS. As mine is a bottom-of-the-line APC that lacks such a connector, I guess I’ve got a "dumb" UPS.

      I suppose an upgrade would be a good idea at some point. In the meantime, at least I have a journaling file system to protect the server from corruption.

  • August 4, 2004 at 10:24 am
    Permalink

    Nice idea. I hadn’t thought of using those script facilities (normally used to initialize daemons). It’s more elegant than a cron job. Thanks for that suggestion!

    • January 12, 2005 at 10:02 pm
      Permalink

      I just implemented this:

      Create a file in /etc/init.d called "mtu" with the following contents:
      ———-
      #!/bin/sh

      ifconfig eth0 mtu 1454
      ———-
      chmod a+x /etc/init/d/mtu

      ln -s /etc/init.d/mtu /etc/rcS.d/S52mtu

      That should set the MTU to 1454 at boot up which I use for my ADSL (via ATM) connection.

      (Why 1454?: http://www.myne*censored*chman.com/kb/adsl/pppoemtu.htm)

Comments are closed.