How to configure a network interface on Ubuntu?

by viola_gleichner , in category: Networking & Wireless , 2 years ago

How to configure a network interface on Ubuntu?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by coty_beier , 2 years ago

@viola_gleichner 

To configure a network interface on Ubuntu, you can follow these steps:

  1. Identify the network interface you want to configure by running the following command:
1
ifconfig


This will display a list of all network interfaces on your system, along with their IP addresses.

  1. Open the network configuration file for the interface you want to configure. The location of this file depends on the version of Ubuntu you are using. For Ubuntu 20.04 and later, the file is located at /etc/netplan/ directory.
1
sudo nano /etc/netplan/01-netcfg.yaml


  1. Edit the file to specify the IP address and other network configuration settings for the interface. For example:
1
2
3
4
5
6
7
8
9
network:
  version: 2
  ethernets:
    ens33:
      dhcp4: no
      addresses: [192.168.1.10/24]
      gateway4: 192.168.1.1
      nameservers:
          addresses: [8.8.8.8, 8.8.4.4]


Here, we are configuring the ens33 interface to use a static IP address of 192.168.1.10/24, with a gateway of 192.168.1.1 and DNS servers of 8.8.8.8 and 8.8.4.4.

  1. Save the changes to the configuration file and exit the editor.
  2. Apply the new network configuration by running the following command:
1
sudo netplan apply


This will apply the new network configuration and activate the interface with the new settings.


You can also restart the network service to apply the new configuration by running the following command:

1
sudo systemctl restart networking


Note: If you are using a version of Ubuntu earlier than 20.04, the process for configuring a network interface may be slightly different.

Member

by emie , 6 months ago

@viola_gleichner 

In order to configure a network interface on Ubuntu, you can follow these steps:


Identify the network interface you want to configure by running the following command: ifconfig. This will display a list of all network interfaces on your system along with their IP addresses.


Open the network configuration file for the interface you want to configure. For Ubuntu 20.04 and later, the file is located at /etc/netplan/ directory.


sudo nano /etc/netplan/{YOUR_FILE_NAME}.yaml


Edit the file to specify the IP address and other network configuration settings for the interface, similar to the example below:

1
2
3
4
5
6
7
8
9
network:
  version: 2
  ethernets:
    ens33:
      dhcp4: no
      addresses: [192.168.1.10/24]
      gateway4: 192.168.1.1
      nameservers:
          addresses: [8.8.8.8, 8.8.4.4]


Save the changes to the configuration file and exit the editor.


Apply the new network configuration by running the following command: sudo netplan apply. This will apply the new network configuration and activate the interface with the new settings.


You can also restart the network service to apply the new configuration by running the following command: sudo systemctl restart networking.


Please note that the process may vary slightly if you are using a version of Ubuntu earlier than 20.04.