# How do I startup and shutdown network services from terminal?



## vikingshelmut (Mar 12, 2002)

I like to leave my system on all the time, but would like to be able to shutdown the network services from the terminal before I leave work.  The machine needs to be on (no sleep) because I'm usually rendering something overnight.  I know when you start up in single user mode, you can type something like "SystemStartup" at the prompt, which will startup ALL system services.  I also remember a command which allowed you to startup ONLY network services (NetworkStartup? or something like that).  So I'd like to be able to shutdown the network services on this machine every night, then startup network services when I come back the next day.  I'm sure there are lots of other ways to perform what I'm trying to do, but the ability to type a command to startup and shutdown network services without exiting Aqua would be a very cool tool to have!  If I can do this, I was also thinking of setting this up as a daily cron job. 
Sorry about the long post!


----------



## gumse (Mar 12, 2002)

Pull the network plug instead.


----------



## chenly (Mar 18, 2002)

gumse's right--just disconnect the network cable. It's hot-pluggable.


----------



## vikingshelmut (Mar 20, 2002)

Yes, I know I can unplug a network cable and get the same effect.  I just think that knowing how this stuff works via terminal could be useful tool.  I am a well experienced Mac user, but am learning everything I can about BSD and the terminal.

So if anybody else has any good suggestions regarding performing this process via the terminal, let me know!

FYI - the therory behind this post, is that during system startup, the system executes 1 command which starts all network services.  I know i can boot to single user mode, and execute this 1 command to have network access in single user mode.  I'm just wondering if I can perform the same thing in reverse;  ie shutting down all network services via 1 command in the terminal.  Or, do I have to kill off the dameons one at time?

Thanks in advance...


----------



## chenly (Mar 21, 2002)

testuser, YOU RULE!


----------



## lethe (Jun 26, 2002)

another option to blocking the ports that the services use is to actually turn off the processes that run the services.  you can save CPU cycles that way for your rendering.

i m not exactly sure which file you mean about SystemStartup.  but all the startup files can be found in /System/Library/StartupItems.  you might be talking about one of these.  there is one in there for network: /System/Library/StartupItems/Network/Network

that is the executable script that is run but the system at boot time to start networking services.  so you might be able to do something like this in single user mode:

/System/Library/StartupItems/Network/Network Start

i have heard that these scripts might at one point allow you to run them with the stop parameter, thereby stopping the services with the same script you used to start them.  but right now that doesn t work.

one easy way to stop some network services is to stop the internet superserver, inetd.  just ps aux| grep aux to find its PID and then kill it.  the AppleFileServer is the executable of the afp server, and it is not handled by inetd, nor is apache.  those can be turned off in systempreferences, but you can do it from the command line too.

you could use a method like this to  make a script to undo everything that the network startup script does, and stick that in your crontab.

my solution seems messy and incomplete, but i just thought i would describe to you another approach to solving your problem.  perhaps someone else can expand upon, or else debunk this approach....


----------



## ladavacm (Jun 27, 2002)

those running as daemons, and those started on-demand by inetd.

You can kill daemons by issuing kill PID.  Appropriate PIDs can be found in /var/run/daemonname.pid files.  

On-demand started servers can be commented out of /etc/inetd.conf, after which you have to kill -HUP inetd (/var/run/inetd.pid will tell you the PID to kill).

Simple.

Or you can ifconfig en0 down to disable the network card, which is even simpler 
(you bring it up again with, you guessed it
ifconfig en0 up
)


----------



## extra88 (Jun 27, 2002)

Thanks for the good examples of ipfw, Testuser. I was wondering what the "add 100" (and subsequent "delete 100") referred to. Is the 100 supposed to be the number assigned to that rule? Would you pick a new number for each rule? Could you assign multiple rules the same number so a single command could be used to delete them all at once?

Or maybe the 100 is a priority level so rules <100 would be processed before this one?


----------

