07.06.2023

Configuring network adapter in Ubuntu or Debian

This guideline describes how to configure the network adapter by editing the file: /etc /network/interfaces and Netplan.

After connecting the server to a private network in the control panel, an additional virtual network adapter will be added to it. For the proper work of the connected interface, it must be configured.

Connect to a virtual server as superuser and run the command:

ifconfig -a

A list of connected interfaces will be displayed:

ens160
Link encap:Ethernet HWaddr 00:00:00:00:00:00
inet addr:xxx.xxx.xxx.xxx Bcast:xxx.xxx.xxx.xxx Mask:255.255.255.0
inet6 addr: yyyy::yyy:yyy:yyyy:yyy/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7011 errors:0 dropped:0 overruns:0 frame:0
TX packets:2862 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6661547 (6.6 MB) TX bytes:234861 (234.8 KB)
ens192
Link encap:Ethernet HWaddr 00:50:56:01:2e:ca
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
lo
Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:160 errors:0 dropped:0 overruns:0 frame:0
TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:11840 (11.8 KB) TX bytes:11840 (11.8 KB)

In the network settings, find MAC field with the value of HWaddr parameter equal to one of those contained in the displayed network interface list. Note the interface name (ens192 in our case).

Important: before configuring the adapter in the operating system, check the control panel whether the DHCP option is enabled or disabled for your network. You can find this option in the network settings.

Editing the file: /etc /network /interfaces

To change network interface settings, open /etc/network/interfaces file:

nano /etc/network/interfaces

DHCP is enabled

If DHСP option was enabled during private network creation, then configure Ubuntu/Debian network adapter to obtain network settings automatically:

auto ens192
iface ens192 inet dhcp

DHCP is disabled

If DHCP is disabled, then configure the interface manually (as in the example below). You may find local address and subnet mask in network settings in control panel:

auto ens192
iface ens192 inet static
address 10.0.1.2
netmask 255.255.255.0

Save changes, exit text editor, and restart network service (ens192 is adapter name, which you have noted):

ifdown ens192 && ifup ens192

To check correctness of network adapter settings, execute ping to a gateway address shown in control panel, such as:

ping 10.0.1.1

Netplan

To change the network interface settings, open the /etc/netplan/99-netcfg-vmware.yaml file:

nano /etc/netplan/99-netcfg-vmware.yaml

DHCP is enabled

If the DHCP function has been enabled when creating a private network, go to the Ubuntu/Debian network adapter settings and make sure you select to receive network settings automatically as well as the gateway address:

ens192:
dhcp4: true
dhcp6: no
addresses: []
gateway4: 10.0.1.1
nameservers:
addresses:
- 10.0.1.1

DHCP is disabled

If the DHCP function has been disabled, then specify the interface parameters manually, as shown in the example below. The local address of the subnet mask can be found in the network settings in the control panel:

ens192:
dhcp4: no
dhcp6: no
addresses:
- 10.0.1.2/24
gateway4: 10.0.1.1
nameservers:
addresses:
- 10.0.1.1

After you save the changes and exit the editor, you need to verify the interface configuration and then reboot the network services:

sudo netplan generate
sudo netplan apply