After lots of trial and error I've managed to have osx actually BE a network server that starts automagically. Indeed, as many of us have discovered, in order to share one's internet connexion with a LAN, one has to click the "start" internet sharing after each restart. Bummer... but no longer !
This tip may be a bit complicated, and it requires a couple of scripts, but I believe that it's still quite straightforward. Be prepared to part from the InternetSharing prefs pane, though (RIP).
In the following instructions, I'm assuming that you have a dynamic connection to your ISP (ie through DHCP) that uses an Ethernet modem. I believe this hint should work as well with a static IP, but I haven't tested it this way.
[Editor's note: This is a long and fairly complex hint, and I have not tested it myself. Please make sure you have good backups prior to doing anything such as the following on your machine ... it's just common sense!]
STEP ONE:
We're going to create a new IP address for our LAN. This address must exist as early as possible, or named won't be able to bind to it (cf supra). Open the Network prefs pane, and select "Network Port Configurations" from the "Show:" menu. Click New... and call it whatever you want, but select "Built-in Ethernet" (if your primary net access is throught ethernet, or course). Now select your new configuration from the "Show" popup menu. Select configure "Manually". Set the values as follows:
% mkdir NATAnd now for the script itself; use your favorite editor (vi, emacs etc) and call it NAT and enter the following text:
% chmod 755 NAT
% chown root:wheel NAT
% cd NAT
#!/bin/shSave the file, exit your editor and type chmod 4754 NAT.
. /etc/rc.common
ConsoleMessage "Starting NAT"
wrongorder=$(/sbin/ifconfig en0 | sed -n '/inet/p' | head -n 1
| sed -n '/192/p' | awk '{print $2}'| wc -l)
# Enter the above as ONE LINE! #
if [ "${wrongorder}" -gt 0 ]; then
ConsoleMessage "swapping DHCP and unregistered alias"
ifconfig en0 -alias 192.168.0.1
ifconfig en0 alias 192.168.0.1
fi
/usr/sbin/natd -f /etc/natd.conf
/sbin/ipfw add 20000 divert natd all from any to any via en0
/sbin/ipfw add 20050 divert natd all from any to any via en1
/sbin/ipfw add 20050 divert natd all from any to any via en1STEP THREE:
{
Description = "NAT";
Provides = ("NAT");
Requires = ("Network",
"Resolver");
OrderPreference = "Late";
Messages =
{
start = "Starting NAT";
stop = "Stopping NAT";
};
}Save and exit, and, just to make sure, do (as root):% chown root:admin StartupParameters.plistSTEP FOUR:Alright, now let's make sure that everything is fine in the hostconfig file (which carries global values for things like ip forwarding etc). Open /etc/hostconfig as root in a text editor, and make sure that you have the following saying "-YES-":
% chmod 644 StartupParameters.plist
IPFORWARDING=-YES-The last line is if you want a local DNS/named server)
DNSSERVER=-YES-
// query-source address * port 53;After it is a line that starts with "listen-on". Make sure that the listen-on line is not commented (doesn't have any // at the beginning), and replace it with the following:
listen-on { 192.168.0.1; };Save and exit. What we've just done is we asked named to only reply to internal DNS querries. Unless you want to have a public DNS server (in which case you probably would know how to set it up by yourself ^_^), you'll want to keep your DNS private.
interface en0Save and exit.
dynamic yes
same_ports yes
log_denied no
use_sockets yes
unregistered_only yes
Mac OS X Hints
http://hints.macworld.com/article.php?story=20021014052604432