# DHCP Server and Dhcp Relay Agent at same server Can't bind to dhcp address: Address already in use



## Ercan Deger (Jan 27, 2021)

Hello All,

I am using FreeBSD 11.3 and trying to run dhcpd and dhcrelay at the same device.


```
/usr/local/sbin/dhcpd -cf /usr/local/etc/dhcpd.conf igb3

Listening on BPF/igb3/08:35:71:06:79:d1/192.168.77.0/24
Sending on   BPF/igb3/08:35:71:06:79:d1/192.168.77.0/24
```

dhcrelay

`dhcrelay -i igb1 -4 192.168.75.200`

but dhcrelay is giving error

Can't bind to dhcp address: Address already in use

lsof shows me dhcpd running on all interface

```
[root@myserver /]# lsof -n|grep dhc
dhcpd  28213   root  cwd     VDIR               0,81               1024         2 /
dhcpd  28213   root  rtd     VDIR               0,81               1024         2 /
dhcpd  28213   root    3u    unix 0xfffff8005ccac368                0t0           ->0xfffff800058bd6d0
dhcpd  28213   root    4u    VCHR               0,33              0t736        33 /dev/bpf
dhcpd  28213   root    6u    IPv4 0xfffff80131d03860                0t0       UDP *:bootps
```
I can't run 2 programs at same time

What must I do?

Thanks for your help


----------



## SirDice (Jan 28, 2021)

Ercan Deger said:


> trying to run dhcpd and dhcrelay at the same device.


To do what? What's the point of doing that?


----------



## Ercan Deger (Jan 28, 2021)

Hi SirDice,

I have 2 local interfaces, 
192.168.75.0/24 network (igb1)
192.168.77.0/24 network (igb3)

I am using dhcpd service at FreeBSD at igb1 

for other interface (igb3) I want to use dhcrelay to forward dhcp request to windows machine.

but when I start dhcpd it is listening on all interface so I cant start dhcrelay.

Thanks,


----------



## SirDice (Jan 28, 2021)

I'd either forward everything to the Windows machine or handle all DHCP requests on the FreeBSD host. It's a bit of a management nightmare having to maintain multiple different DHCP servers.


----------



## im (Jan 28, 2021)

Hello!

I have found no way to setup dhcpd for listening only the one interface.

There is a link related to the issue:


			How to configure dhcp to listen to a specific interface instead	of	0.0.0.0?
		

But it seems to be a Solaris-specific feature.
I think it is too dificult to use for regular FreeBSD user.


```
Solaris 11
We have integrated a patch from Oracle to use sockets instead of
DLPI on Solaris 11.  This functionality was written for use with
Solaris Studio 12.2 and requires the system/header package.
By default this code is disabled in order to minimize disruptions
for current users.  In order to enable this code you will need to
enable both USE_SOCKETS and USE_V4_PKTINFO as part of the
configuration step.  The command line would be something like:
          ./configure --enable-use-sockets --enable-ipv4-pktinfo
```


----------



## SirDice (Jan 28, 2021)

Lets circle back to the beginning, why would you want to split up different subnets to different DHCP servers? You know you can host multiple, different, subnets from one DHCP server?


----------



## Ercan Deger (Jan 29, 2021)

I am responsible for igb1 subnet and I have no permission for other network, then I need to forward queries to windows machine. I know it is interesting 

I think isc dhcpd needs bind to 0.0.0.0 ip so We cant run dhcpd and dhcrelay at same server 

I tried im's suggestion;

I used --enable-use-sockets while compiling and dhcpd run on interface  ( it needs dhcpd.conf local-address *192.168.77.1;*)

I modified Makefile

CONFIGURE_ARGS+=--localstatedir=/var *--enable-use-sockets --enable-ipv4-pktinfo*


New compiled dhcpd needs seperate configurations and multiple dhcpd process for all required interface.

Listening on *Socket*/igb3/192.168.77.0/24
Sending on   *Socket*/igb3/192.168.77.0/24
Server starting service.

theoretically It works as expected.

dhcpd      6573   root    6u    IPv4 0xfffff80005928e60                0t0       UDP *192.168.77.1*:bootps

but no ip leased to pc's 

when I changed local-address *0.0.0.0*; it works


----------

