To enable DHCP for an Ethernet card on Ubuntu, you can follow these steps depending on the version of Ubuntu you are using. The process involves modifying network configuration files.
-
Open Terminal: Press
Ctrl + Alt + T
to open the terminal. -
Locate the Netplan Configuration File: Typically, the configuration files are located in
/etc/netplan/
. You can list the files with:ls /etc/netplan/
-
Edit the Configuration File: Open the relevant YAML file (e.g.,
01-netcfg.yaml
) using a text editor likenano
orvim
:sudo nano /etc/netplan/01-netcfg.yaml
-
Configure DHCP: Modify or add the following lines to enable DHCP for your Ethernet interface (replace
eth0
with your actual interface name if different):network: version: 2 renderer: networkd ethernets: eth0: dhcp4: true dhcp6: false
-
Save and Exit: If you are using
nano
, pressCtrl + O
to save andCtrl + X
to exit. -
Apply the Configuration: Run the following command to apply the changes:
sudo netplan apply
-
Open Terminal: Open your terminal.
-
Edit the Interfaces File: Open the
/etc/network/interfaces
file in a text editor:sudo nano /etc/network/interfaces
-
Add or Modify DHCP Configuration: Modify or add the following lines for your Ethernet interface (replace
eth0
with your actual interface name):auto eth0 iface eth0 inet dhcp
-
Save and Exit: Save your changes and exit the editor.
-
Restart Networking Service: To apply the changes, restart the networking service with:
sudo systemctl restart networking
Or for older versions:
sudo service networking restart
After applying these changes, you can verify that your Ethernet interface is using DHCP by checking its IP address:
ip addr show eth0 # Replace eth0 with your interface name if different.
You should see an IP address assigned from your DHCP server.
By following these steps, you will successfully enable DHCP for your Ethernet card on Ubuntu.
Citations: [1] https://geek-university.com/configure-dhcp-client-on-ubuntu/ [2] https://www.server-world.info/en/note?os=Ubuntu_23.04&p=dhcp&f=2 [3] https://unix.stackexchange.com/questions/319740/use-dhcp-on-eth0-using-command-line [4] https://www.alibabacloud.com/help/en/ecs/how-to-configure-the-network-as-dhcp-in-a-linux-image