4

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.

Mahesh
  • 12,488
  • 4
  • 44
  • 58
rofls
  • 141
  • 1
  • 4
  • Make sure you types the password correctly for your wireless ;) – Rinzwind May 18 '12 at 06:08
  • rc.local is executing with root permission, so you dont need to use a sudo. Is everything alright in your Network Manager? You can try to remove Network Manager and configure a /etc/network/interfaces – us3r May 18 '12 at 06:43
  • a) it's wired, see "ethernet" b) rc.local isn't working, I think it's because it's running dhclient before the system is fully booted. That's why I'm trying to run it immediately after boot, or login c) I think something is definitely wrong with my Network Manager, but I don't know how to follow your instructions, could you be more precise? – rofls May 18 '12 at 06:55
  • Can you give us the output of the command ifconfig after you have rebooted (but before you've run sudo dhclient), and again after you have run sudo dhclient? It sounds like you may have an IP address incorrectly configured/not configured for DHCP on your network interface. (ps: comment from Matt) – Mahesh May 18 '12 at 17:45
  • and kindly edit your question with the requested info. If it is long, you may use and post the link here – Mahesh May 18 '12 at 17:47
  • 1
    Can you give us the output of the command `ifconfig` after you have rebooted (but before you've run `sudo dhclient`), and again after you have run `sudo dhclient`? It sounds like you may have an IP address incorrectly configured/not configured for DHCP on your network interface. – Matt Malesky May 18 '12 at 05:52
  • Will do, ~5 minutes. – rofls May 18 '12 at 06:56
  • They were nearly the same. Only difference was that there are significantly more RX and TX packets after, which I think means I'm getting an IP address, just not looking up websites correctly or something. It will occasionally browse before running dhclient, just not reliably and quickly. – rofls May 18 '12 at 07:06

2 Answers2

5

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.

Scott Severance
  • 13,776
  • 9
  • 52
  • 76
0

You can create a Custom script to start or stop services and make it executable at startup, i don't have experience in writing codes so please refer this official Guide look up Installing custom init-scripts

atenz
  • 12,674
  • 5
  • 44
  • 66
  • Yeah, but I think those run during boot, by default, though I could be wrong. Thanks though! – rofls May 18 '12 at 07:05
  • 1
    Welcome to Ask Ubuntu! Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Mahesh May 18 '12 at 17:48