Ubuntu – How to automate a root command after (not during) startup

12.04bashdhclientethernetroot

I'm using Ubuntu 12.04 LTS, but I need to run the following command:

sudo dhclient

after startup to acquire a stable ethernet connection. I am running dhclient during startup already, through the /etc/rc.local file.

Someone please help me run this command after-startup automatically (by removing it's requirement for root, or some other means), or suggest a different way of troubleshooting my ethernet connection.

Best Answer

One workaround would be to use rc.local with a sleep command. Put the following into /etc/rc.local:

(sleep 60; dhclient) &

This will make the command wait for 60 seconds before being executed, which should allow enough time for your machine to finish booting.