Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Control network settings with sysctl.conf UNIX
I recall a hint called Broadband Optimizer a while ago. I have since figured out a way to use the Freebsd style sysctl.conf to control your network settings. Read the rest of the article for the how-to...


The first thing is to create a sysctl.conf file...
 % sudo emacs /etc/sysctl.conf
...and put your settings in it. For example, I'll use the Broadband Optimizers settings:
net.inet.tcp.sendspace: 65536
net.inet.tcp.recvspace: 65536
net.inet.tcp.delayed_ack: 0
net.inet.udp.recvspace: 73728
The next thing is to create an rc.sysctl file:
 % sudo emacs /etc/rc.sysctl
Put the following in it:
#!/bin/sh
#
# Copyright (c) 1999 Warner Losh
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD: src/etc/rc.sysctl,v 1.4.4.6 2002/04/15 00:44:13 dougb Exp $
#

#
# Read in /etc/sysctl.conf and set things accordingly
#

if [ -f /etc/sysctl.conf ]; then
while read var comments
do
case ${var} in
#*|'')
;;
*)
mib=${var%=*}
val=${var#*=}

if current_value=`sysctl -n ${mib} 2>/dev/null`; then
case ${current_value} in
${val}) ;;
*)
sysctl -w ${var}
;;
esac
else
case ${1} in
last)
echo "Warning: sysctl ${mib} does not exist"
;;
esac
fi
;;
esac
done
The final step is to edit the Startup Item:
 % sudo emacs /System/Library/StartupItems/SystemTuning/SystemTuning
At the end of the file where it says...
sysctl -w kern.maxvnodes=${newvnodes}
...add the following:
if [ -r /etc/rc.sysctl ]; then
sh /etc/rc.sysctl first
fi
Now all you have to do is add parameters to /etc/sysctl.conf and they will be read at boot.

[Editor's note: I have not tested this script myself!]
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[19,850 views]  

Control network settings with sysctl.conf | 14 comments | Create New Account
Click here to return to the 'Control network settings with sysctl.conf' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Confused
Authored by: jasonxz on Jul 22, '02 12:40:42PM

After creating these files in Emacs, how do I save them? I read the man pages for Emacs, but I really couldn't understand how it works.



[ Reply to This | # ]
Confused
Authored by: shepmaster on Jul 22, '02 01:27:57PM

For emacs, you will want to type control-x then control-s to save, then control-x control-c to exit.



[ Reply to This | # ]
Confused
Authored by: timrob on Jul 22, '02 02:24:22PM

I guess I should have put those commands in there.
ctrl-x then ctrl-s saves. ctrl-x then ctrl-c saves and exits.
You could just use pico instead.
Or use BBEdit or whatever makes you happy.
As long as it handles newlines properly, you should be alright.

Tim





[ Reply to This | # ]
BBEdit
Authored by: uurf on Jul 22, '02 05:15:22PM
I did use bbedit, and I got the following upon attempting to run the script:
[localhost:~] user% sudo sh /etc/rc.sysctl
/etc/rc.sysctl: parse error near `;;' [37]
/etc/rc.sysctl: parse error near `)' [38]
/etc/rc.sysctl: parse error near `;;' [55]
/etc/rc.sysctl: parse error near `esac' [56]
/etc/rc.sysctl: parse error near `done' [57]
[localhost:~] user%
this despite having saved linebreaks as "UNIX" wha'appened?

[ Reply to This | # ]
Is there a way to do this w/o reboot?
Authored by: adolph on Jul 22, '02 12:49:15PM

Is there a service that can be restarted instead of rebooting?



[ Reply to This | # ]
Is there a way to do this w/o reboot?
Authored by: timrob on Jul 22, '02 02:10:04PM

All you have to do when you change settings in sysctl.conf is:

sudo sh /etc/rc.sysctl

As always with the sudo command you'll need an administors password.

Tim



[ Reply to This | # ]
bad advice..
Authored by: etrepum on Jul 22, '02 05:56:19PM

It's a bad idea to go changing around anything in /System because an update to OS X could easily clobber it. Make your own StartupItem and throw it in /Library. I won't describe the process in detail but it's painfully obvious if you are familiar with shell scripting and take a look at any of the ones that are there.



[ Reply to This | # ]
Would be nice to see a how to article w/correct info
Authored by: jasonxz on Jul 24, '02 01:18:45PM

Considering all the reported errors in the original posting and now the advice that this should be done with a Startup Item, it would be very helpful to have an article posted on how to do this correctly via Startup Items. I was so confused by all the corections in the comments that I've just given up.



[ Reply to This | # ]
RE:Would be nice to see a how to article w/correct info
Authored by: timrob on Jul 24, '02 03:23:47PM

Well, If there is enough interest, I would write it out in plain text.
The errors were a result of my failure to escape certain characters
which have different meaning to HTML than to the shell.
You'll notice I did use a StartupItem. The suggestion was to create a new
one in /Library/StartupItems. There have already been a number of hints that
explain how to do that. If we are lucky this will be a feature in 10.2.
If that does wind up being the case then most of this hint would be moot.
All that would be needed would be to create/edit /etc/sysctl.conf.
In any case, if this seems difficult to you even with corrections then perhaps
it is not an area you should be fooling around with anyway.



[ Reply to This | # ]
error in script
Authored by: ahl on Jul 22, '02 10:02:00PM

There is an error in the script, which is in the line after

        case ${var} in)

There should be a '' before the '#' to stop the shell from interpreting the line as a comment:

        \#*|'')

It appears that backslash characters are being "reduced" by the "posting" editor--in plain text you need two in the message for each one you want in the output, and in HTML you need FOUR!!!

I'm surprised that this script isn't there already, as it's a standard FreeBSD script. Maybe someone with Jaguar can check whether it's there in the newer OS?

[ Reply to This | # ]

error in script
Authored by: timrob on Jul 23, '02 02:00:16PM

You are correct. Thanks for spotting this.
I chose to edit the startup item because they were
already using the sysctl command there. Good point though
about editing /System/Libray/StartupItems. I just copied
the /System/Libray/StartupItems/SystemTuning to /Library/StartupItems
and edited out the original text leaving my added script. It works fine,
but sysctl.conf is read much later in the boot sequence.
I do hope that they include this function in 10.2.



[ Reply to This | # ]
error in script
Authored by: froz on Jul 24, '02 03:39:39AM

There are a couple more errors, the last two lines of /etc/rc.sysctl should be:

[whitespace]done < /etc/rc.sysctl
fi

the keyword/value pairs in /etc/sysctl.conf should be
kw=val instead of kw: val

It's kind of hard to post code fragments as HTML without being able to escape angle brackets, etc.



[ Reply to This | # ]
Hopefully it will be in 10.2
Authored by: jasonxz on Jul 24, '02 07:41:29PM

... that way no one will have to bother with an erroneous article.



[ Reply to This | # ]
Re:Hopefully it will be in 10.2
Authored by: timrob on Jul 25, '02 09:03:11PM

...Or deal with Noise makers.



[ Reply to This | # ]