Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Drop dhcpcd lease before connecting
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
firespace
n00b
n00b


Joined: 13 Dec 2014
Posts: 1

PostPosted: Sat Dec 13, 2014 6:35 am    Post subject: Drop dhcpcd lease before connecting Reply with quote

I have a peculiar problem with my USB-modem. When modem is shut off, it forgets about all DHCP leases and it resets every time one tries to rebind a DHCP lease a modem knows nothing about, so if my modem gets disconnected due to a bad USB cable, I can no longer connect until I remove /var/lib/dhcp/*.lease. The problem is I don't know how to delete it automatically. I have already tried digging into configuration files, but to no avail.

Is there any way to make dhcpcd forget about a lease right after a link goes down or when a USB-modem goes up?
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Sat Dec 13, 2014 11:16 am    Post subject: Re: Drop dhcpcd lease before connecting Reply with quote

firespace wrote:
Is there any way to make dhcpcd forget about a lease right after a link goes down or when a USB-modem goes up?

firespace ... are you using netifrc to manage the interface? If so you can do something like the following:

/etc/conf.d/net
Code:
preup() {
   [ -f "/var/lib/dhcpcd/dhcpcd-${IFACE}.lease" ] && {
      rm -f /var/lib/dhcpcd/dhcpcd-${IFACE}.lease
   }
   return 0
}

HTH & best ... khay
Back to top
View user's profile Send private message
lost+found
Guru
Guru


Joined: 15 Nov 2004
Posts: 509
Location: North~Sea~Coa~s~~t~~~

PostPosted: Sat Dec 13, 2014 11:49 am    Post subject: Reply with quote

Welcome to the forums!

Another way is to use /etc/dhcpcd.enter-hook (See `dhcpcd-run-hooks' manual), and execute commands on dhcp events. Even a firewall script can be (re)run here.
Code:
case "${reason}" in
   #BOUND|INFORM|REBIND|REBOOT|TIMEOUT|STATIC)
   #   /root/scripts/firewall.sh &>/dev/null
   #   ;;
   PREINIT|NOCARRIER)
      rm -f /var/lib/dhcpcd/dhcpcd-eth0.lease
      ;;
esac
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6835
Location: Blighty

PostPosted: Sat Dec 13, 2014 2:00 pm    Post subject: Reply with quote

Or add
Code:
reboot 0
to dhcpcd.conf
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum