# How to set mtu automatically at startup?



## 3mors (Jan 5, 2003)

I've to set my network card mtu to 1454 in order to navigate on my PowerBook G4, as it's plugged to a LAN with internet in sharing.

Where do I have to put *ifconfig en0 mtu 1454* in order to be setted automatically at startup without having to type it on terminal every time?

Thank you.


----------



## gatorparrots (Jan 5, 2003)

*/etc/iftab*

In order to avoid editing a system file that will probably get blown away by the next update from Apple, I recommend doing it in a StartupItem instead.

Download BroadbandOptimizer and add it to their startup script. This will have the side benefit of optimizing your connection for broadband as well.
http://versiontracker.com/moreinfo.fcgi?id=12591&db=mac


----------



## 3mors (Jan 5, 2003)

Sure, thanks.
But this apps doesn't change mtu value, so I can't navigate and check for software updates in prefpane.

I read that I can modify BroadbandOptimizer config, but I don't know where and how to put *ifconfig en0 mtu 1454*.

Could u help me?


----------



## 3mors (Jan 5, 2003)

I've also tried to add this line to /etc/iftab file:

en0 mtu 1454

but it doesn't work after reboot.


----------



## gatorparrots (Jan 5, 2003)

Try adding this line to "/Library/StartupItems/BroadbandOptimizer/BroadbandOptimizer"
(using pico or BBEdit Lite so as to preserve the plain text file format and UNIX line endings):
/sbin/ifconfig alias 'en0 mtu 1454'

If that doesn't work, add this line instead:
echo 'en0 mtu 1454' >> /etc/iftab

Sorry I can't test it more thoroughly for you (since my configuration is different than yours). This should give you a good lead on how to implement it, however.


----------



## 3mors (Jan 5, 2003)

> _Originally posted by gatorparrots _
> *
> echo 'en0 mtu 1454' >> /etc/iftab
> *



Doesn't work.


----------



## gatorparrots (Jan 5, 2003)

To run the command manually in the Terminal, you have to do so as root:
sudo ifconfig en0 mtu 1454
If this works, you know that you can add it to the StartupItem to have it run at every boot.

Did you try to edit /etc/iftab manually with pico?
sudo pico /etc/iftab?
If that doesn't stick after a reboot, then move on to the StartupItem method.

 The StartupItem should run as an administrative user (and therefore automatically be ran with sudo) so to add it to the file, you just add this line:
ifconfig en0 mtu 1454 
to
"/Library/StartupItems/BroadbandOptimizer/BroadbandOptimizer" 

Sorry if my previous post was confusing.


----------



## 3mors (Jan 6, 2003)

> _Originally posted by gatorparrots _
> *To run the command manually in the Terminal, you have to do so as root:
> sudo ifconfig en0 mtu 1454*



The terminal "SUDO" way works perfectly, in fact I do in this way to set mtu value.



> *Did you try to edit /etc/iftab manually with pico?
> sudo pico /etc/iftab?*



I used BBEDIT to edit the file and I'm sure it's not a problem, as I use this app to edit all the other config files.



> *The StartupItem should run as an administrative user (and therefore automatically be ran with sudo) so to add it to the file, you just add this line:
> ifconfig en0 mtu 1454
> to
> "/Library/StartupItems/BroadbandOptimizer/BroadbandOptimizer"
> *



Already done. Doesn't work.


----------



## gatorparrots (Jan 6, 2003)

To edit a root-owned file such as */etc/iftab*, you have to open BBEdit as root, otherwise you cannot save the file (it will open as read-only).

sudo -b /System/Library/Frameworks/Carbon.framework/Versions/Current/Support/LaunchCFMApp '/Applications/BBEdit Lite 6.1/BBEdit Lite 6.1 for OS X'


----------



## 3mors (Jan 6, 2003)

No.
U can open the file directly on BBedit and when u edit the file, the app asks if u want to do it.
When u save, it asks for root password.

I use it everytime, especially for long config file such as _httpd.conf_.


----------



## gatorparrots (Jan 6, 2003)

You must have a special configuration, because my root-owned files open as read-only (the little pencil icon in the upper left corner has a slash through it). If you try to edit the file, BBEdit gives a warning dialog box: _The document "httpd.conf" couldn't be unlocked because it is owned by "root"._ 

Are you using BBEdit 6 or 7 (the full version)? I am using the Lite version of 6.1 (as you may have guessed by my previous post) and cannot edit root-owned files without the previous command to open BBEdit Lite with root privileges.


----------



## 3mors (Jan 6, 2003)

Yes. I use BBEdit 7.0.1 full version.

This is the difference.


----------



## gatorparrots (Jan 8, 2003)

Okay, here is the definitive answer:
Manually add the setting now:
sudo ifconfig en0 mtu 1454 up

To get it to stick after rebooting, add these two lines to the */Library/StartupItems/BroadbandOptimize/BroadbandOptimizer* startup script:
#change from default 1500
/sbin/ifconfig en0 mtu 1454 up > /dev/null

The finished script should looks like this:

```
#!/bin/sh

##
# Broadband Optimizer
# optimize networking for broadband connection
##

. /etc/rc.common

CheckForNetwork

#if [ "${NETWORKUP:=-NO-}" = "-YES-" ]; then

/usr/sbin/sysctl -w net.inet.tcp.sendspace=65536 > /dev/null
/usr/sbin/sysctl -w net.inet.tcp.recvspace=65536 > /dev/null
/usr/sbin/sysctl -w kern.ipc.maxsockbuf=524288 > /dev/null
/usr/sbin/sysctl -w net.inet.tcp.delayed_ack=0 > /dev/null
/usr/sbin/sysctl -w net.inet.udp.recvspace=73728 > /dev/null
#change from default 1500
/sbin/ifconfig en0 mtu 1454 up > /dev/null
echo "Network settings optimized for Broadband Connection"

#fi
```

_Note: you could also accomplish the same task by adding your setting to */System/Library/StartupItems/Network/Network*, but I wouldn't recommend editing a system file like that, especially since it may be blown away by a future system update from Apple. Editing the third-party startup item would be the preferred method, as it should survive system updates. 

Also, it appears that /etc/iftab is not the place for such configurations.This article should shed some light on the subject:
http://www.opensource.apple.com/projects/documentation/howto/html/network_config.html#N2732
It seems like the Network startup script provides this type of ifconfig information._

Thanks for sticking it out with me!


----------

