# [Solved] DHCP server

## beren43

Installed gentoo. Then you must configure the dhcp server.

In /etc/dhcpd.conf

interfaces=«enp0s8»;

authoritative;

default-lease-time 600;

max-lease-time 7200;

subnet 172.18.0.0 netmask 255.255.255.0 {

range 172.18.0.100 172.18.0.160;

option subnet-mask 255.255.255.0;

option broadcast-address 172.18.0.255;

option routers 172.18.0.1; }

But after /etc/init.d/dhcpd start 

unknown option interfaces; 

unknown option authoritative; 

unknown option default-lease-time 

unknown option max-lease-time 

unknown option subnet 

unknown option range 

...Last edited by beren43 on Tue Dec 29, 2015 2:22 pm; edited 1 time in total

----------

## NeddySeagoon

beren43,

Welcome to Gentoo.

Normally, you only use a dhcp server on your router.  You can use Gentoo as a router if you want to but that's unusual in a home setup.

On Gentoo you configure your dhcp server in /etc/dhcp/dhcpd.conf, rather than /etc/dhcpd.conf.

The file should be present and full of useful comments.

Heres the uncommented lines from my /etc/dhcp/dhcpd.conf

```
# The next line is fake

option domain-name "gentoo.org";

# If this DHCP server is the official DHCP server for the local

# network, the authoritative directive should be uncommented.

authoritative;

# no service on these subnets

# don't serve the internet

subnet 62.x.y.z netmask 255.255.255.248 {

}

# dmz     

subnet 192.168.10.0 netmask 255.255.255.0 {

}

# wireless 

# lease times from 1 to 4 hours

subnet 192.168.54.0 netmask 255.255.255.0 {

        range 192.168.54.220 192.168.54.239;

        default-lease-time 3600;

        max-lease-time 14400;

        option subnet-mask 255.255.255.0;

        option broadcast-address 192.168.54.255;

        option routers 192.168.54.253;

        option interface-mtu 1492;

        }

# lease times from 12 to 24 hours

subnet 192.168.100.0 netmask 255.255.255.0 {

        range 192.168.100.220 192.168.100.239;

        default-lease-time 31200;

        max-lease-time 43200;

        option subnet-mask 255.255.255.0;

        option broadcast-address 192.168.100.255;

        option routers 192.168.100.253;

        option interface-mtu 1492;

        }
```

I also have an entry (not shown) to support PXE booting from the days when I used to netboot my media player.

----------

## beren43

I can use Gentoo as a router.

I have two network interfaces (WAN and LAN). If you need to configure static ip.

I add in /etc/conf.d/net

config_enp0s8="172.18.0.1/24"

Correctly ?

----------

## NeddySeagoon

beren43,

That's correct.

I have 

```
config_eth0="192.168.100.20/24 brd 192.168.100.255"

routes_eth0="default via 192.168.100.253"
```

My interface is eth0 and yours is enp0s8.

-- edit --

My  brd 192.168.100.255 is not strictly required.

----------

## beren43

After config_enp0s8="172.18.0.1/24 broadcast 172.18.0.255" 

This interface has no ip

----------

## NeddySeagoon

beren43,

You will need to (re)start net.enp0s8, which, by default, does not exist.

In /etc/init.d/     net.enp0s8 needs to  be a symlink to net.lo.

In my case 

```
ls -l /etc/init.d/net.*

lrwxrwxrwx 1 root root     6 May 14  2013 /etc/init.d/net.eth0 -> net.lo

-rwxr-xr-x 1 root root 17824 Nov  8 16:42 /etc/init.d/net.lo
```

Now you can do 

```
/etc/init.d/net.enp0s8 start
```

That's restart if its already running.

You can also add net.enp0s8 to the default runlevel.

This is covered in the Gentoo Handbook

----------

## beren43

cd /etc/init.d 

ln -s net.lo net.enp0s8

Failed to create symlink ./net.enp0s8 file exist

----------

## beren43

How to remove

/etc/init.d/net.enp0s8 -> enp0s8   ?

----------

## NeddySeagoon

beren43,

```
rm /etc/init.d/net.enp0s8
```

You need to be root.

----------

## beren43

rm /etc/init.d/net.enp0s8

it is impossible to remove   /etc/init.d/net.enp0s8  no such file or directory

----------

## NeddySeagoon

beren43,

If the file does not exist, you can make the symlink correctly.

If it does exist, rm will remove it.

Tab completion is your friend.

Type /et press tab.  You get /etc/ for free.  

Rinse and repeat as many times as needed.  It helps avoid typing errors in file names.

----------

## beren43

Ok

I need to create the directory /etc/dhcp and there create a file dhcpd.conf ?

----------

## NeddySeagoon

beren43,

If you have net-misc/dhcp already installed both the directory and file should already exist.

You only need edit it.

If you really mean net-misc/dhcpcd, whicd in just the client part, it should just work.

What are you trying to do?

----------

## beren43

Ok.

Configured in /etc/dhcp/dhcpd.conf

```
subnet 172.18.0.0 netmask 255.255.255.0 {

        range 172.18.0.100 172.18.0.110;

        default-lease-time 3600;

        max-lease-time 14400;

        option subnet-mask 255.255.255.0;

        option broadcast-address 172.18.0.255;

        option routers 172.18.0.1;

        option interface-mtu 1492;

        } 
```

/etc/init.d/dhcpd start there are no errors

But clients do not receive ip automatically

Code tags added by NeddySeagoon for easy reading.

----------

## NeddySeagoon

beren43,

You need the 

```
authoritative; 
```

 statement too.

----------

## beren43

```
authoritative;

subnet 172.18.0.0 netmask 255.255.255.0 {

        range 172.18.0.100 172.18.0.110;

        default-lease-time 3600;

        max-lease-time 14400;

        option subnet-mask 255.255.255.0;

        option broadcast-address 172.18.0.255;

        option routers 172.18.0.1;

        option interface-mtu 1492;

        } 
```

Clients do not receive ip automatically

----------

## NeddySeagoon

beren43,

What is in your dhcpd log in cd /var/log?

What operating system are the clients using?

Are the clients connecting via wired or wireless?

Explain your network topology.

----------

## beren43

Thanks for the help. DHCP is working. The problem was that I ran /etc/init.d/dhcpd start. But the service dhcpd status service is stopped. 

If service dhcpd start and it worked ! So dchcp the server need to run service dhcpd start ?

----------

