Autostart Apple's Internet Sharing on startup

Oct 28, '02 08:25:44AM

Contributed by: john_e

A recent hint here explained how to enable NAT on boot, but this one enables Apple's actual Internet Sharing option from the Sharing panel during startup. Here's what you need to do.

[Editor's note: I have not tested this myself ... and yes, it's distinct from the above referenced hint. That hint launched NAT at startup, the command-line version of internet sharing; this hint enables Apple's version, which apparently has some differences according to the comments to the first hint.]

In the Terminal, open the file /etc/hostconfig as root by typing sudo pic /etc/hostconfig. Add an entry at the bottom looking like this:

ISHARING=-YES-
This is just for having an easy way of disabling
this feature if you want to. Change -YES- to -NO- and it will not start on boot.

Next, you need to createa new StartupItems directory and the required startup files. Do this by typing:
% cd /Library/StartupItems/
% sudo mkdir ISharing
% cd ISharing
% sudo pico ISharing
The last step will open the pico editor on a new, blank "ISharing" file. [Editor's note: I added the "cd ISharing" step here as it was not in the original hint and seems to be required based on the structure of other StartupItems folders.]

In this file, copy and paste the following:
#!/bin/sh

. /etc/rc.common

##
# Start up Internet Sharing
##

if [ "${ISHARING:=-NO-}" = "-YES-" ]; then
ConsoleMessage "Starting Internet Sharing"
/usr/libexec/InternetSharing
fi
Then hit Control-X and type Yes when it asks you to save. After pico quites, type sudo pico StartupParameters.plist and copy this bit into the file:
{
Description = "Internet Sharing";
Provides = ("ISharing");
Requires = ("Network", "NetworkExtensions", "Resolver");
OrderPreference = "Late";
Messages =
{
start = "Starting Internet Sharing";
stop = "Stopping Internet Sharing";
};
}
Save once again as described above using Control-X. Now you're almost good to go. Just one more thing, making sure the permissions are right. Just type these commands:
% sudo chmod 755 ISharing
% sudo chown root:wheel ISharing
% sudo chown root:admin StartupParameters.plist
% sudo chmod 644 StartupParameters.plist
You should now be able to restart your machine and have Apple's Internet Sharing preference enabled at startup.

Comments (49)


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