Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

How do I run this command after-startup automatically (by removing it's requirement for root, or some other means), or is there a different way of troubleshooting my ethernet connection? Otherwise I'll have to start using Windows more than Ubuntu.

share|improve this question

What about using rc.local to execute a background script that waits a few seconds/minutes before running the sudo dhclient command?

Otherwise, there's always crontab--you could have a script run every minute, or every few minutes to check the status of the network connection, then run sudo dhclient if the connection is down.

share|improve this answer
I like the idea of executing a delayed dhclient, but it sounds like it would rely on some system state so that it would happen immediately after login, as the first thing I usually want to do is browse the web (i.e., not run dhclient or wait for it). As to using crontab, could that be able to run dhclient (which requires root) and start automatically at boot? Thanks! – rofls May 18 '12 at 6:50
@rofls yes, you can edit the root user's crontab. cron is the task scheduler built into UNIX, Linux, etc., and it has very fine-grained control for running commands. For example, you could run a command every minute, or you could run it at 12:45 PM on every Friday the 13th that happens to fall in the month of October. Once you've added a task to a user's crontab, the cron daemon (crond) will automatically execute the crontab tasks (unless, of course, you've disabled or stopped crond). – rob May 18 '12 at 7:05
thanks, cron looks quite cool (no pun intended... sorry) but it seems mostly to provide means of time-based execution (stems from "chronological," I guess) I need something that relies on the state of the system to know when to run, I feel, because it should only run directly after I log in. Unless you have some fancy way of configuring this execution (or my schedule, to be precisely booted and ready to browse at x time) I don't think it will work. – rofls May 18 '12 at 7:18
If you need something to run directly after you log in, you can add a command to your ~/.bashrc login script. Otherwise, if you write a script that checks the network state and runs dhclient if the network is not connected, you can still add that to cron. It won't affect performance much. (A similar workaround is used for DD-WRT installations on which one of the router's network interfaces stops working--the cron job checks whether the interface is up, then restarts it if it's down.) – rob May 18 '12 at 12:37

Rather than trying to brew a solution yourself, have you looked into NetworkManager?

For a personal computer I find it very useful.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .