Force Ethernet duplex settings on Startup

Mar 28, '03 09:45:00AM

Contributed by: craigsheppard

After much taking, I'm happy to be able to give something to the community! This relates to a previous hint, where some Macintoshes do not auto-negotiate properly with the networking hardware. The current solution is to run a terminal command, sudo ifconfig en0 media 100basetX mediaopt full-duplex, which then correctly sets the media type and speed (in my case, 100basetX and full-duplex). Unfortunately for some of us, these settings don't 'stick' after a restart (the adapter goes back to autoselect), and must be re-set manually each time.

What is needed here is a process that does this type of thing for us on startup, even before reaching the login screen. This is accomplished by creating a StartupItem, and putting it in /Library -> StartupItems. StartupItem is really a folder containing two parts: A shell script of the same name as the folder, and an XML file called StartupParameters.plist.

Create a folder called setDuplex in /Library -> StartupItems, and create a file inside with the same name. The file should contain the following text:

#!/bin/sh
# forces 100baseTX and full-duplex
. /etc/rc.common
ifconfig en0 media 100basetX mediaopt full-duplex
Make it executable by typing chmod a+x setDuplex. Note that you do not need a sudo command in the script, because it is already being run as root.

Next, create another file called StartupParameters.plist, containing the following text:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
  <dict>
    <key>Description</key>
    <string>My Force-Duplex</string>
    <key>Messages</key>
    <dict>
      <key>start</key>
      <string>Forcing Full-Duplex</string>
    </dict>
    <key>OrderPreference</key>
    <string>Early</string>
    <key>Provides</key>
    <array>
      <string>Proper Duplexing</string>
    </array>
  </dict>
</plist>
Restart, then type ifconfig -a in the Terminal, and your en0 interface should no longer say autoselect, and should have the correct settings.

Forgive me if there are any errors, etc - this is my first shell script, and first XML file! I believe everything should be ok, though! It works well on my server.

Comments (10)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030327113141312