1

I am running one Ubuntu Server 14.04 with network configuration using /etc/network/interfaces and so ifup/ifdown scripts.

I realised that if I configure one interface in DHCP mode, then I unplug the cable from the interface and the IP address configured via DHCP is maintained until the DHCP lease expires. What I need is dhclient to flush addresses and routes configured via DHCP in the interface when the link goes down immediately.

How can I get dhclient to flush IP addresses and routes when the link status is DOWN?

0

You can use ifplugd to run a command when an Ethernet cable is plugged or unplugged. I'm not sure whether installing ifplugd is necessary — it's possible that there's a built-in way with udev and upstart — but I can't find it in the upstart documentation.

Since you're using ifupdown, call ifdown when the cable is unplugged. In /etc/ifplugd/ifplugd.action, write something like

#!/bin/sh
if [ "$1" = "eth0" ] && [ "$2" = "down" ]; then
  ifdown "$1"
fi
  • Great! You provided me the key point. – chrpinedo Mar 25 '15 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.