2

I know how to request that a machine to acquire a new IP address, however I've got a slightly different scenario.

I have configured a box locally on my network which has DHCP. Therefore, it acquired an IP address. I want to ship it to somebody on a different network which also has DHCP. Ideally, they would plug in their Ethernet cable before starting up their machine; in reality, they will just plug in cables as fast as they can.

The problem I've seen: they plug in the power first, and then the Ethernet. The machine doesn't automatically acquire an IP address using the new DHCP server unless we have them restart the box (or, if we had them log in, by restarting networking or forcing DHCP to release/renew).

Is there a way to configure an Ubuntu server (10.04 LTS) to automatically try to release/renew any time that an Ethernet cable is connected?

Macho Matt
  • 211
  • 4
  • 10
  • 2
    What version of ubuntu ... it _should_ already be doing this as part of the ifup scripts – Zypher Sep 16 '11 at 17:33
  • 10.04 LTS. I can't say for sure that nobody has changed that file. Is there a setting in the ifup scripts that I can look at? – Macho Matt Sep 16 '11 at 17:35
  • FWIW, I'm encountering this same in Ubuntu Server 14.04, pretty much stock installation. – thom_nic Feb 22 '16 at 16:28

1 Answers1

1

It looks like one common way to handle this is to add a udev rules file. I believe this gets installed by some package on a desktop system, but I cannot find it on any of my Ubuntu or Debian servers.

Here is a blog that seems to have some details.

The blog suggests adding a udev rules like this.

/etc/udev/rules.d/85-ifupdown.rules

# This file causes network devices to be brought up or down as a result
# of hardware being added or removed, including that which isn't ordinarily
# removable.
# See udev(7) for syntax.

SUBSYSTEM=="net", GOTO="net_start"
GOTO="net_end"

LABEL="net_start"

# Bring devices up and down only if they're marked auto.
# Use start-stop-daemon so we don't wait on dhcp
ACTION=="add",          RUN+="/sbin/start-stop-daemon --start --background --pidfile /var/run/network/bogus --startas /sbin/ifup -- --allow hotplug $env{INTERFACE}"

ACTION=="remove",       RUN+="/sbin/start-stop-daemon --start --background --pidfile /var/run/network/bogus --startas /sbin/ifdown -- --allow hotplug $env{INTERFACE}"

LABEL="net_end"

If you look at the ifup command being used you will notice that it only applies to hotplug interfaces. So be sure to use allow-hotplug instead of auto in your network interfaces file.

Zoredache
  • 128,755
  • 40
  • 271
  • 413
  • Interesting, I'm attempting this on an Intel i3 NUC and when I `sudo udevadm monitor` I don't get any events when plugging or unplugging the ethernet cable. However it looks like simply changing `auto eth0` to `allow-hotplug eth0` causes a dhcp lease to occur when the ethernet cable is connected. – thom_nic Feb 22 '16 at 18:44