# dhcpcd ip request problem

## Caltrop

Every time I reboot or restart the network I recieve a new IP address.  I had a previous instalation of Mandrake and never had this problem, my IP was reset to it's previous value on every reboot.  The windows machines on the network also recieve the same ip.  This is quite annoying because I run a webserver and having a DNS name resolve to my ip is against network policy so I need to be able to have dhcpcd get the same IP.  It's worked before so I know that it's possible. Is there a way to make dhcpcd try harder to get the same ip?

----------

## garo

Is the dhcp server yours or is it from your ISP ?

----------

## px

With dhcpd you can specify an ip for an hardware adress for your network cards. Mayabe you can try increase the timeout time in dhcpd.

----------

## Caltrop

the dhcp server is a university dhcp server, not mine.  The problem is strange because it worked before with mandrake on the same network.  I just recently installed gentoo.  With Mandrake, everytime I rebooted the computer I would recieve the same IP.

----------

## hummus

this is odd, if your computer is on most of the time, it should never lose its lease on that ip, how long are you leaving it off for and then expecting to get the same ip?

my school has lease times spanning 72 hours, so that you can turn ur comp off over the weekend and still ge the same ip

if more computers were recently added to the network, it could be using up more of the address pool, and they may have shortened the leases because they have limited address space, (but that seems unlikely)

do you ALWAYS get a different unique ip, every reboot, or is there patterns, or do you get one two times in a row, then another one, etc...

grab a sniffer and run it while you do a dhcpcd eth*, look at the dhcp"yi addr" and "ci addr" fields in the dhcp request packets, your client will attempt to request an ip through one of them, look at the lease length option, and other options to get a feel for what the client is requesting

otherwise its i would think its a problem with your computer realizing it has a lease out on an ip, or storing that previous ip, which seems like a really odd low layer probelm

----------

## Caltrop

My computer is always on.  I get a new ip everytime I reboot or run /etc/init.d/net.eth0 restart

----------

## Caltrop

I figured out the problem.  The init script net.eth0 uses dhcpcd -k, line 140, to stop the running dhcpcd process.  I looked through the man pages and dhcpcd -k clears the dhcpcd cache.  replacing this with kill `pidof dhcpcd` solved the problem.

----------

## Zu`

 *Caltrop wrote:*   

> I figured out the problem.  The init script net.eth0 uses dhcpcd -k, line 140, to stop the running dhcpcd process.  I looked through the man pages and dhcpcd -k clears the dhcpcd cache.  replacing this with kill `pidof dhcpcd` solved the problem.

 

Yes that's right  :Wink: 

Like it says exactly in the man page:

```

       -k     Sends SIGHUP signal to the dhcpcd process that is currently running.

              If  dhcpcd  receives SIGHUP it will send DCHP_RELEASE message to the

              server and destroy dhcpcd cache. In a case dhcpcd  receives  SIGTERM

              which  is  normally  used  by  shutdown(8) when rebooting the system

              dhcpcd will not send DHCP_RELEASE and will not destroy  cache.  When

              system  boots  dhcpcd  will use cache to request the same IP address

              from DHCP server which was assigned before the system went down.

```

Perhaps someone should suggest a change in the net.ethx script?

----------

## dufnutz

I'm having the same problem and found the line to fix but how do you know the pid of dhcpcd when writing it in the script?

----------

## rac

 *dufnutz wrote:*   

> how do you know the pid of dhcpcd when writing it in the script?

 

That's what that pidof command is for.  Surrounding it in backticks like Caltrop did will expand to the output of the command in the shell.  Try it: 

```
$ echo `pidof init`

1
```

----------

## dufnutz

when i try

```
pidof init
```

i recieve

```
1
```

but when i do

```
echo 'pidof init'
```

i get 

```
pidof init
```

and when i put the suggested line in my script i get the following error message during a shutdown

```
unknown pid: pidof dhcpcd
```

----------

## pjp

```
$ echo `pidof init`

1
```

Pay close attention to the quotes.

----------

## dufnutz

ahhh ok, thanks a bunch i got it now

----------

