Configure network settings in Ubuntu - GitMasterNikanjam/C_WiKi GitHub Wiki

To configure network settings in Ubuntu via the command line, you can use the netplan utility. Here's how to set it up:

1. Locate the Netplan Configuration File

Netplan configuration files are located in /etc/netplan/. Typically, you'll find a YAML file there, such as 01-netcfg.yaml or 50-cloud-init.yaml. You can list the files using:

ls /etc/netplan/

2. Edit the Netplan Configuration File

Open the file with a text editor, for example:

sudo nano /etc/netplan/01-netcfg.yaml

3. Configure Static IP or DHCP

Example 1: Static IP Configuration

For a static IP configuration (e.g., on enp4s0), your file might look like:

network:
  version: 2
  ethernets:
    enp4s0:
      dhcp4: no
      addresses:
        - 192.168.1.100/24
      gateway4: 192.168.1.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4
    enp5s0:
      dhcp4: yes

Example 2: DHCP Configuration

If you want to configure an interface to use DHCP (e.g., on enp5s0), the configuration would be:

network:
  version: 2
  ethernets:
    enp5s0:
      dhcp4: yes

4. Apply the Configuration

After editing, apply the changes using:

sudo netplan apply

5. Verify the Configuration

You can check the status of your network interfaces with:

ip addr show

Or to test connectivity, try pinging an external site:

ping 8.8.8.8

By following these steps, you can easily configure your network interfaces to use either static IP addresses or DHCP on an Ubuntu system.


Error:

sudo netplan apply

** (generate:1073): WARNING **: 11:42:32.597: gateway4 has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.

** (process:1072): WARNING **: 11:42:33.099: gateway4 has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.

** (process:1072): WARNING **: 11:42:33.541: gateway4 has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.

** (process:1072): WARNING **: 11:42:33.542: gateway4 has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.   

The warnings you’re seeing indicate that the gateway4 option is deprecated in Netplan and you should use the routes section instead to define default routes. Here’s how to modify your configuration to comply with the new approach:

Example of Updated Static IP Configuration

Modify your Netplan configuration to use the routes section:

network:
  version: 2
  ethernets:
    enp4s0:
      dhcp4: no
      addresses:
        - 192.168.1.100/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4
    enp5s0:
      dhcp4: yes

Explanation:

  • routes: This replaces gateway4. You define a route with to: default to indicate that it's the default route, and via specifies the gateway IP address.

Applying the Configuration

After making these changes, save the file and apply the configuration again:

sudo netplan apply

Verifying the Configuration

Check the network settings to ensure they have been applied correctly:

ip route show

This should now reflect the updated routing configuration without the deprecation warnings.


If only two of your Ethernet ports are showing up when you run ifconfig, there are a few possible reasons and steps to troubleshoot:

1. Check for Hardware Recognition

Ensure that the system recognizes all Ethernet ports. Run:

lspci | grep -i ethernet

This command lists all Ethernet controllers detected by the system. If you see all four ports listed here, they are recognized at the hardware level.

2. Check Network Interfaces

You can also check the network interfaces using:

ip link show

This will list all network interfaces, including any that might not be configured. Look for the interfaces named enp4s0, enp5s0, enp6s0, enp7s0, or similar.

3. Verify Driver Installation

If some ports are not showing, it could be a driver issue. Check the system logs for any messages related to network devices:

dmesg | grep -i ethernet

This will show any relevant logs that might indicate issues loading drivers for the Ethernet ports.

4. Check for Missing Configuration

If you see the ports listed but they aren't configured, ensure that your Netplan configuration includes all interfaces you want to set up. If not, you may need to edit the configuration file at /etc/netplan/.

5. Reboot

If you've recently installed drivers or made changes to the system, a reboot can sometimes resolve issues with device recognition.

6. Install Additional Drivers

If the Ethernet ports are not recognized at all (not listed in lspci), you may need to install additional drivers. Check the manufacturer's website for any necessary drivers.

Example Commands Recap

Here's a recap of the commands you can use:

lspci | grep -i ethernet
ip link show
dmesg | grep -i ethernet

Summary

By following these steps, you should be able to identify why only two of your Ethernet ports are showing up and take appropriate actions to resolve the issue. If you need further assistance, feel free to provide additional details on what you find!


if you configure your network settings using Netplan and apply those changes with sudo netplan apply, the configuration will persist across reboots. Netplan saves the settings in the configuration file (typically located in /etc/netplan/), and the system applies those settings during the boot process.

Steps to Ensure Persistence:

  1. Configure the Network: Make sure you've correctly set up your network interfaces in the Netplan configuration file (e.g., 01-netcfg.yaml).

  2. Apply the Configuration: After editing the file, use the command:

    sudo netplan apply
    

    This command applies the changes immediately.

  3. Reboot: You can safely reboot your system using:

    sudo reboot
    
  4. Verify After Reboot: Once the system has restarted, you can verify that the configurations are still in place by using:

    ip link show
    

If everything is set up correctly in your configuration file, the network interfaces should come up with the desired settings after a reboot. If you face any issues after rebooting, feel free to reach out for further assistance!


In the context of network interfaces, the term "UP" refers to the operational state of a network port or interface. Here's what it means:

Definitions:

  1. UP:

    • Indicates that the network interface is active and operational. This means that the interface is configured to send and receive data packets.
    • When an interface is "UP," it can participate in network communication, and you can expect it to transmit and receive network traffic.
  2. DOWN:

    • Indicates that the network interface is inactive and not operational. This could be due to several reasons, such as being administratively disabled, not having a valid connection (no carrier), or simply not being configured correctly.
    • When an interface is "DOWN," it cannot communicate over the network.
  3. NO-CARRIER:

    • This state is often associated with an interface that is UP but not connected to a network (e.g., the cable is unplugged, or there’s no link to a switch or router). It signifies that while the interface is active, it doesn't have a valid physical connection to a network.

Summary

  • UP = The network interface is active and can communicate over the network.
  • DOWN = The network interface is inactive and cannot communicate.
  • NO-CARRIER = The interface is active but lacks a physical connection to a network.

Understanding these states helps in diagnosing network issues and ensuring that your interfaces are configured correctly for network connectivity.


To bring other network ports (like enp5s0, enp6s0, and enp7s0) UP in Ubuntu, you can use the following methods:

Method 1: Using ip Command

You can use the ip command to bring an interface up. Here’s how:

  1. Open a Terminal.

  2. Run the following command for each interface you want to bring up:

    sudo ip link set enp5s0 up
    sudo ip link set enp6s0 up
    sudo ip link set enp7s0 up
    
  3. Verify the Status: After running the commands, check the status of the interfaces again using:

    ip link show
    

Method 2: Using ifconfig Command

If you prefer the ifconfig command (note that it is deprecated in favor of the ip command):

  1. Open a Terminal.

  2. Run the following command for each interface:

    sudo ifconfig enp5s0 up
    sudo ifconfig enp6s0 up
    sudo ifconfig enp7s0 up
    
  3. Verify the Status: Check the status using:

    ifconfig
    

Method 3: Modify Netplan Configuration

If you want the interfaces to remain UP after a reboot, you need to configure them in the Netplan configuration file:

  1. Open the Netplan Configuration File:

    sudo nano /etc/netplan/01-netcfg.yaml
    

    (Replace 01-netcfg.yaml with your actual configuration file name.)

  2. Add or Modify the Interfaces: Make sure each interface you want is included and configured. For example:

    network:
      version: 2
      ethernets:
        enp4s0:
          dhcp4: yes
        enp5s0:
          dhcp4: yes # or your desired static configuration
        enp6s0:
          dhcp4: yes # or your desired static configuration
        enp7s0:
          dhcp4: yes # or your desired static configuration
    
  3. Save and Apply the Configuration: After editing, save the file and apply the configuration:

    sudo netplan apply
    

Method 4: Check Physical Connection

If an interface is still not coming up:

  • Check if the Ethernet cable is connected properly to the port.
  • Try a different cable or switch port to rule out physical connection issues.

Summary

  • Use the ip or ifconfig command to bring interfaces up immediately.
  • Modify the Netplan configuration file to ensure interfaces stay up after a reboot.
  • Check physical connections if interfaces do not come up as expected.

If you encounter any issues while performing these steps, feel free to ask for help!


If your network configuration is not being saved after a reboot in Ubuntu, it usually indicates that there might be an issue with how the Netplan configuration file is set up or that it’s not being applied correctly. Here are some steps to troubleshoot and ensure that your configuration persists:

1. Check the Netplan Configuration File

Ensure that your Netplan configuration file is set up correctly.

  1. Open the Configuration File:

    sudo nano /etc/netplan/01-netcfg.yaml
    

    Replace 01-netcfg.yaml with your actual configuration file name if it differs.

  2. Verify the Syntax: Make sure the indentation and syntax are correct. Here’s an example configuration for multiple interfaces:

    network:
      version: 2
      ethernets:
        enp4s0:
          dhcp4: true
        enp5s0:
          dhcp4: true
        enp6s0:
          dhcp4: true
        enp7s0:
          dhcp4: true
    

2. Apply the Configuration

After editing the file, apply the configuration using:

sudo netplan apply

3. Check for Errors

Run the following command to check for any syntax errors in your Netplan configuration:

sudo netplan try

This command will apply the configuration temporarily and allow you to verify if it works correctly. If there are errors, it will show them and revert after 120 seconds.

4. Check for Other Configuration Files

Sometimes, there might be multiple configuration files in the /etc/netplan/ directory. Check for other YAML files that might be conflicting:

ls /etc/netplan/

If you find multiple files, ensure they are not conflicting with each other.

5. Permissions Issue

Ensure the configuration file has the correct permissions. The typical permissions are:

ls -l /etc/netplan/

The files should typically be owned by root. You can correct the permissions if needed:

sudo chown root:root /etc/netplan/01-netcfg.yaml
sudo chmod 644 /etc/netplan/01-netcfg.yaml

6. Reboot and Test

After verifying and applying the configuration, reboot your system:

sudo reboot

After the system has rebooted, check the status of your interfaces again using:

ip link show

7. Debugging Logs

If it still doesn’t work, check the system logs for any errors related to Netplan or network configuration:

journalctl -xe | grep netplan

Summary

By following these steps, you should be able to identify and fix any issues that are preventing your network configuration from being saved after a reboot. If you still encounter problems, feel free to share your configuration file and any error messages you receive for further assistance!


To check if other network managers (like NetworkManager or systemd-networkd) are active on your Ubuntu server, you can use several commands. Here’s how to do it:

1. Check for NetworkManager Status

You can check if NetworkManager is running by using the following command:

systemctl status NetworkManager
  • If it’s active and running, you'll see output indicating its active status.
  • If it's not running, you’ll see a message indicating that the service is inactive or not found.

2. Check for systemd-networkd Status

You can check if systemd-networkd is running:

systemctl status systemd-networkd
  • Again, look for the active status in the output.

3. List All Network Services

To get a list of all network-related services and their status, you can use:

systemctl list-units --type=service | grep network

This will show you a list of services related to networking, including their active status.

4. Check Active Network Interfaces

You can also use ip or ifconfig to see which network interfaces are currently active and managed by any network manager:

ip link show

or

ifconfig

5. Check Network Configuration Files

  • Netplan: You can check if there are any configurations set up in Netplan that might conflict with other network managers:

    ls /etc/netplan/
    
  • NetworkManager: If you suspect NetworkManager is being used, you can check its configuration files:

    cat /etc/NetworkManager/NetworkManager.conf
    

6. Disabling Conflicting Managers

If you find that both NetworkManager and systemd-networkd are running, you may want to disable one of them, depending on your preference:

  • To disable NetworkManager:

    sudo systemctl stop NetworkManager
    sudo systemctl disable NetworkManager
    
  • To disable systemd-networkd:

    sudo systemctl stop systemd-networkd
    sudo systemctl disable systemd-networkd
    

Summary

Using the commands above, you can check if other network managers are active and determine if any are conflicting with your Netplan configuration. If you find any unnecessary network managers running, consider disabling them to ensure your desired network settings apply correctly. Let me know if you need any more help!


To use only Netplan and disable other network managers on your Ubuntu server, follow these steps:

1. Disable NetworkManager

If NetworkManager is running, you can disable it with the following commands:

sudo systemctl stop NetworkManager
sudo systemctl disable NetworkManager

2. Disable systemd-networkd

If systemd-networkd is running and you want to disable it as well, run:

sudo systemctl stop systemd-networkd
sudo systemctl disable systemd-networkd

3. Verify the Status of Network Managers

After disabling them, verify that neither NetworkManager nor systemd-networkd is running:

systemctl status NetworkManager
systemctl status systemd-networkd

Both should show as inactive or not found.

4. Confirm Netplan is Active

Ensure that your Netplan configuration is properly set up. If you haven't done so already, check your configuration file in /etc/netplan/:

ls /etc/netplan/

Open the configuration file (usually named *.yaml) with an editor:

sudo nano /etc/netplan/your-config-file.yaml

5. Apply Netplan Configuration

After ensuring that your configurations are correct, apply the Netplan settings:

sudo netplan apply

6. Reboot the System

To ensure all changes take effect properly, reboot your server:

sudo reboot

7. Verify Network Configuration After Reboot

After the reboot, check the status of your network interfaces using:

ip addr show

or

ifconfig

Summary

By following these steps, you will have disabled other network managers, allowing you to use only Netplan for network configuration. If you encounter any issues or need further assistance, feel free to ask!


The warning you're seeing indicates that while you've stopped systemd-networkd, it can still be activated by its associated socket. To completely disable systemd-networkd, you'll need to disable the socket as well. Here’s how to do it:

Steps to Completely Disable systemd-networkd

  1. Stop systemd-networkd Socket: You need to stop the socket that can activate systemd-networkd:

    sudo systemctl stop systemd-networkd.socket
    
  2. Disable systemd-networkd Socket: Then, disable the socket so it won't start again on boot:

    sudo systemctl disable systemd-networkd.socket
    
  3. Verify that Both Services are Inactive: After stopping and disabling both systemd-networkd and NetworkManager, you can verify their status:

    systemctl status systemd-networkd
    systemctl status NetworkManager
    

    Both should be inactive.

Check for Other Network Managers

If you are using any other network management tools (like connman or others), you may want to disable those as well.

Reboot and Confirm Configuration

After you have disabled both NetworkManager and systemd-networkd, reboot your server:

sudo reboot

After rebooting, check that only Netplan is managing the network interfaces by using:

ip addr show

This will help confirm that your intended configurations are active and no other network managers are interfering.

If you encounter any further issues or have any questions, feel free to ask!


It looks like both systemd-networkd and NetworkManager are still active on your system, which could be causing conflicts and delays during network configuration. Here’s how to ensure that both are completely disabled and that only Netplan is managing your network interfaces:

Steps to Disable NetworkManager and systemd-networkd

  1. Stop Both Services: You can stop both services using the following commands:

    sudo systemctl stop NetworkManager
    sudo systemctl stop systemd-networkd
    
  2. Disable Both Services: To prevent them from starting on boot, run:

    sudo systemctl disable NetworkManager
    sudo systemctl disable systemd-networkd
    
  3. Stop and Disable Their Sockets: To completely ensure systemd-networkd does not start again, stop and disable its socket:

    sudo systemctl stop systemd-networkd.socket
    sudo systemctl disable systemd-networkd.socket
    
  4. Verify Service Status: After stopping and disabling the services and their sockets, check their status to ensure they are inactive:

    systemctl status NetworkManager
    systemctl status systemd-networkd
    

    Both should show as inactive or stopped.

Verify Netplan is Working

  1. Reboot Your System: After disabling the services, reboot your server:

    sudo reboot
    
  2. Check Network Interfaces: After rebooting, check the status of your network interfaces using:

    ip addr show
    
  3. Check Netplan Configuration: You can confirm that your Netplan configuration is being used by checking the output of the following command:

    sudo netplan apply
    

    There shouldn't be any errors, and it should configure your network interfaces as defined in your Netplan YAML files.

Further Troubleshooting

If NetworkManager or systemd-networkd starts again after a reboot:

  • Check for Conflicting Services: Some distributions come with network management tools that may start these services automatically. Ensure that there are no other network management tools installed that might be conflicting.

  • Check if Any Configuration Files Are Present: Sometimes, configuration files for these services in /etc/systemd/system/ or /etc/network/ can lead to them being enabled automatically. Review those directories for any lingering configurations.

Following these steps should help you use only Netplan for network management and eliminate the delays you’ve been experiencing at startup. If you have any questions or need further assistance, feel free to ask!