sudo allows you to run a command at an elevated permission level. You can edit the sudoers file by running
One way to do this is to first add a line to your sudoers file which allows the listed commands to be run without a password. By adding the specific command to your sudoers file, you can allow the desired commands to be run without password. You can do this by entering the following 2 lines to your sudoers file (the file that opens when you run "sudo visudo"):
user ALL=(ALL) NOPASSWD: /usr/sbin/networksetup -setnetworkserviceenabled ethernet on
user ALL=(ALL) NOPASSWD: /usr/sbin/networksetup -setnetworkserviceenabled ethernet off
with "user" replaced by your user name.
Then, as your user, to run something at a regular time, you can use crontab
and append the lines:
0 1 * * * sudo networksetup -setnetworkserviceenabled ethernet off && sudo networksetup -setnetworkserviceenabled ethernet on
which will apply this restart at 1 AM every day.
Add the commands directly to root's crontab:
Then enter the line
0 1 * * * networksetup -setnetworkserviceenabled ethernet off && networksetup -setnetworkserviceenabled ethernet on
and save and exit.
You may want to put this in some sort of script that notifies you that the network has been successfully restarted (e.g. with an email or something) so that you're sure it worked.
Alternatively, you can use a launchd script.