Install & Basic Config

install

sudo apt-get install isc-dhcp-server

interfaces

vi /etc/default/isc-dhcp-server

INTERFACES="eth0 eth1 eth2"

config network param

vi /etc/dhcp/dhcpd.conf

# ns servers separated by comma "," ! ! !
option domain-name-servers 10.0.0.1, 10.0.0.2;

# lease time in sec: -1 for infinity.
default-lease-time -1;
max-lease-time -1;

# a very basic subnet declaration:
subnet 10.0.0.0 netmask 255.255.255.0 {
    interface enp0s3; # optional
    range 10.0.0.150 10.0.0.254; # separated by space " "
    option routers 10.0.0.1; # separated by space " "
}

To check DHCP servers:
service isc-dhcp-server status

To check DNS servers:

nmcli device show <interface_name>        # Ubuntu >= 15
nmcli dev    list iface <interface_name>  # Ubuntu <= 14

ref
ref, inc. other systems
ref: lease time -1s is infinit
ref: lease time, usually used values

Static IP

To config static IP for "router" computer:

alternative 1 - on the dhcp server config

vim /etc/dhcp/dhcpd.conf

host sunny-router {
    hardware ethernet 00:11:22:66:66:88;
    fixed-address 10.0.0.1;
}

service isc-dhcp-server restart

alternative 2 - on the router (client of dhcp)

  • for old ubuntu < v17 vim /etc/network/interfaces:
iface eth2 inet static
    address 10.0.0.1
    netmask 255.255.255.0
    #gateway 10.0.0.1
  • for new ubuntu > 17 vim /etc/netplan
network:
    version: 2
    ethernets:
        enp0s3:
            dhcp4: no
            dhcp6: no
            addresses: [192.168.1.2/24]
            gateway4: 192.168.1.1 # OBS: do NOT set gateway for Host-only network in VirtualBox
            nameservers:
                addresses: [8.8.8.8,8.8.4.4]
sudo netplan apply