Software & AppsOperating SystemLinux

Fixing Ubuntu 18.04 Network Start Failure with Netplan DHCP Configuration

Ubuntu 1

In this article, we will be discussing how to fix a network start failure in Ubuntu 18.04, specifically focusing on issues related to Netplan DHCP configuration. Netplan is a utility for easily configuring networking on a Linux system. However, it can sometimes cause issues, especially when dealing with DHCP configurations.

Quick Answer

To fix a network start failure in Ubuntu 18.04 caused by Netplan DHCP configuration, you can start by checking the Netplan configuration file for any discrepancies. Update the configuration file with the correct DHCP settings and apply the changes using the commands sudo netplan generate and sudo netplan apply. If the issue persists, you can mark the interface as optional in the configuration file or create a startup script that runs dhclient to obtain an IP address.

Understanding the Issue

The problem usually manifests as a failure to start the network on boot, which can be traced back to the Netplan DHCP configuration not working properly. This could be due to a variety of reasons, such as incorrect configuration settings, software bugs, or hardware issues.

Checking the Netplan Configuration File

First, let’s check the Netplan configuration file. You can do this by running the following command in the terminal:

cat /etc/netplan/01-netcfg.yaml

This command (cat) is used to read and concatenate files. Here, it displays the content of the Netplan configuration file (01-netcfg.yaml). Make sure the syntax is correct and the necessary DHCP settings are present.

Updating the Netplan Configuration

If you find any discrepancies in the configuration file, you need to update it. You can use a text editor to modify the DHCP settings for the interface ens160 to dhcp4: true. The updated configuration should look like this:

network:
 version: 2
 renderer: networkd
 ethernets:
 ens160:
 dhcp4: true

Once you’ve made the necessary changes, save and close the file.

Applying the Netplan Configuration Changes

After updating the configuration file, you need to apply the changes. This can be done by running the following commands:

sudo netplan generate
sudo netplan apply

The sudo command is used to execute commands with root privileges. The netplan generate command generates the configuration files, and netplan apply applies the changes.

Checking for Errors

After running the above commands, it’s a good idea to check for any errors or clues that might help you troubleshoot the issue. You can do this by running the following command:

dmesg | grep -e enp -e netplan

This command (dmesg) displays the system log messages, and grep is used to filter the output based on the given patterns (-e enp -e netplan).

Restarting the System

Once you’ve applied the changes and checked for errors, restart your system. If the network starts properly, then you’ve resolved the issue. If not, you can try the next step.

Optional Interface Configuration

If the above steps do not resolve the issue, you can try marking the interface as optional in the Netplan configuration file. This can be done by adding the line optional: true under the ens160 section. Save the file and apply the Netplan changes as described in the previous steps.

Using a Startup Script

If none of the above solutions work, you can create a startup script that runs dhclient to obtain an IP address. This can be done by creating a script file, for example /etc/network-startup.sh, with the following content:

#!/bin/bash
dhclient ens160

This script uses the dhclient command to request a DHCP lease for the ens160 interface.

Next, make the script executable by running the following command:

sudo chmod +x /etc/network-startup.sh

The chmod command is used to change the permissions of a file, and the +x option makes the file executable.

Finally, add the script to the system startup by creating a systemd service. Create a file /etc/systemd/system/network-startup.service with the following content:

[Unit]
Description=Network Startup Script

[Service]
ExecStart=/etc/network-startup.sh

[Install]
WantedBy=multi-user.target

This file defines a new systemd service that runs the startup script when the system boots.

To enable the service, run the following command:

sudo systemctl enable network-startup.service

This command enables the service to start on boot.

By following these steps, you should be able to resolve the issue with Netplan DHCP configuration on Ubuntu 18.04. If you continue to experience problems, you may need to consult with a network administrator or seek help from the Ubuntu community.

What is Netplan?

Netplan is a utility for easily configuring networking on a Linux system. It allows users to define network interfaces and their properties in a YAML configuration file.

How do I check the Netplan configuration file?

You can check the Netplan configuration file by running the command cat /etc/netplan/01-netcfg.yaml in the terminal. This will display the content of the configuration file.

What should I do if there are discrepancies in the Netplan configuration file?

If you find any discrepancies in the configuration file, you need to update it. Use a text editor to modify the DHCP settings for the interface and ensure the syntax is correct. Save the file after making the necessary changes.

How do I apply the Netplan configuration changes?

After updating the configuration file, apply the changes by running the commands sudo netplan generate and sudo netplan apply in the terminal. The first command generates the configuration files, and the second command applies the changes.

How can I check for errors after applying the Netplan configuration changes?

To check for errors or clues that might help you troubleshoot the issue, run the command dmesg | grep -e enp -e netplan in the terminal. This will display system log messages filtered based on the patterns provided.

What should I do if the network still doesn’t start properly after applying the Netplan changes?

If the network still doesn’t start properly, you can try marking the interface as optional in the Netplan configuration file. Add the line optional: true under the interface section, save the file, and reapply the Netplan changes.

Is there an alternative solution if the above steps don’t resolve the issue?

If the above steps don’t resolve the issue, you can create a startup script that runs dhclient to obtain an IP address. Detailed steps for creating the script and enabling it as a systemd service are provided in the article.

What should I do if I continue to experience problems?

If you continue to experience problems, it may be helpful to consult with a network administrator or seek assistance from the Ubuntu community. They can provide further guidance and support based on your specific situation.

Leave a Comment

Your email address will not be published. Required fields are marked *