Skip to content

Instantly share code, notes, and snippets.

@mohamadaliakbari
Last active November 6, 2023 19:33
Show Gist options
  • Star 39 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save mohamadaliakbari/1cb9400984094541581fff07143e1c9d to your computer and use it in GitHub Desktop.
Save mohamadaliakbari/1cb9400984094541581fff07143e1c9d to your computer and use it in GitHub Desktop.
Run dhclient on Startup in Ubuntu 18.04

dhclient is the Dynamic Host Configuration Protocol (DHCP) Client one would use to allow a client to connect to a DHCP server.

$ sudo nano /etc/rc.local

#!/bin/bash
dhclient
exit 0

$ sudo chmod 755 /etc/rc.local

$ sudo systemctl enable rc-local

$ sudo systemctl restart rc-local

$ sudo systemctl status rc-local

@mark-e-deyoung
Copy link

mark-e-deyoung commented Dec 11, 2020

Helped me get DHCP working for IP over InfiniBand (ipoib) interfaces in a MAAS cluster. The DHCP process in systemd-networkd used by netplan doesn't seem to work with ipoib while dhclient does.

See: netplan not sending DHCP request of IPoIB interfaces.

@ac101m
Copy link

ac101m commented Mar 14, 2021

I have a bunch of machines running 16.04 (which will be going EOL in a month and a half) that need to be upgraded.
I have run into this issue with ipoib on another machine running 20.04 and am now dreading the upgrade.

In all the years since I started using linux, I never encountered a situation where /etc/network/interfaces either bugged out or wasn't capable of doing what I needed it to. I just don't understand why this needed to be changed! Its things like this that give me second thoughts about ubuntu.

@mickaelbaron
Copy link

Hi,

In my case, DHCP server was provided by a Windows Server. To fix the problem, you need to apply this workaround (https://netplan.io/examples/#integration-with-a-windows-dhcp-server).

Details with Ubuntu 20.04 LTS

  • Edit /etc/netplan/00-installer-config.yaml
  • Add dhcp-identifier key into current network configuration
network:
  ethernets:
    eth0:
      dhcp-identifier: mac
      dhcp4: true
  version: 2
  • Restart Netplan configuration
$ sudo netplan generate
$ sudo netplan apply

@leeanh2612
Copy link

Hi,

In my case, DHCP server was provided by a Windows Server. To fix the problem, you need to apply this workaround (https://netplan.io/examples/#integration-with-a-windows-dhcp-server).

Details with Ubuntu 20.04 LTS

  • Edit /etc/netplan/00-installer-config.yaml
  • Add dhcp-identifier key into current network configuration
network:
  ethernets:
    eth0:
      dhcp-identifier: mac
      dhcp4: true
  version: 2
  • Restart Netplan configuration
$ sudo netplan generate
$ sudo netplan apply

Thanks man you are boss <3

@jialeif
Copy link

jialeif commented Oct 26, 2022

[Match]
Name=enp*

[Network]
DHCP=ipv4

Great helps

@gbc921
Copy link

gbc921 commented Sep 19, 2023

Ubuntu 18.04 (server) is using systemd-networkd as default, if the service is enable systemctl status systemd-networkd, the proper way to enable dhcp is to use the systemd network configuration files (/etc/systemd/network/*) https://www.freedesktop.org/software/systemd/man/systemd.network.html

As exemple, the following configuration file will enable DHCP to any nic that have a name that's matching enp*

cat /etc/systemd/network/20-dhcp.network
[Match]
Name=enp*

[Network]
DHCP=ipv4

Awesome!
Had to do that for the Cloud Image of Ubuntu Server 22.04 LTS (Jammy)

Then later sudo systemctl daemon-reload && sudo systemctl enable systemd-networkd --now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment