4

I'm working on a custom Ubuntu 20.04 server and am trying to get a dhcp IP for it. The server has so far run on a static IP and when I run dhcp or dhclient it says dhcpd: command not found and dhclient: command not found.

The /sbin has no dhcpd or dhclient directories but there is a /etc/dhcp folder which contains dhclient-enter-hooks.d dhclient-exit-hooks.d with scripts in it to which I assume is start/stop dhcp.

What I want to know is if it's possible that dhcp or dhclient is not installed in this machine or if I'm missing the installation path and if it isn't which should be the best one to install to get a dhcp IP from.

6
  • 2
    It's possible that it just wasn't installed by those who set up the machine originally. If they are still available you might ask them. If not, you might want to ask the package system whether those packages are installed. It will certainly know better than anyone else. On top of that, it will be super helpful in installing the packages if indeed they aren't installed yet. May 30 at 9:44
  • 4
    Can you post your /etc/network/interfaces file.
    – Z0OM
    May 30 at 10:23
  • @Hans-MartinMosner checked in installed packages, doesn't look like they're installed. May 30 at 10:31
  • @BlockchainOffice, ther is no interfaces file only if-pre-up.d and if-up.d folders there May 30 at 10:32
  • 4
    Do you got /etc/netplan/FILENAME.yaml ?
    – Z0OM
    May 30 at 10:36

1 Answer 1

4

If you receive command not found when trying to run dhcp or dhclient, it's possible that these are not installed.

To install the DHCP client utilities run:

sudo apt install isc-dhcp-client

This will install the isc-dhcp-client package, which includes the dhclient.

After the installation, you should be able to use the dhclient command to receive an IP address from a DHCP server.

Make sure that /etc/network/interfaces is configured to use DHCP.

auto eth0
iface eth0 inet dhcp

Replace eth0 with your network interface name on your system.

Restart the networking with:

systemctl restart networking

You can run the following command to request an IP address:

sudo dhclient

The dhcpd command you mentioned is for the DHCP server, not the client.

If you need to configure and run a DHCP server, you will need to install and set up the isc-dhcp-server package instead.

Configure network with netplan:

How to Configure Networking in Ubuntu 20.04 with NetPlan

Locate the netplan configuration file in the /etc/netplan/ folder and has a .yaml extension.

Edit the file, should see a yaml structure defining the network interfaces and their configurations. Set the dhcp4 property to true.

nano /etc/netplan/YOUR_NETPLAN_CONFIG_FILE.yaml

dhcp example:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: true
      dhcp6: true

If you have multiple network interfaces, you can add similar sections for each interface.

Apply changes:

netplan apply

Request an IP address:

sudo dhclient

Ubuntu source:

Ubuntu Network configuration

1
  • 1
    thanks, didn't know that dhcpd was for the server May 30 at 10:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .