Ask Sawal

Discussion Forum
Notification Icon1
Write Answer Icon
Add Question Icon

How to up interface in ubuntu?

3 Answer(s) Available
Answer # 1 #

How to configure the network interface in Ubuntu 20.04:

Configuring the network interface in Ubuntu 18.04 was a surprise to many. Although there exists, familiar to all, the configuration file /etc/network/interfaces, it says:

Configuration via ifupdown has been replaced by netplan. Configuration via/etc/netplan. If you want to go back to ifupdown configure via command:

sudo apt install ifupdown

We will not install anything else. Set up what there is. First, look at the content of the directory /etc/netplan.

Let's see, what is in this file.

The configuration file is written in YAML. The settings shown in the example above were made at the stage of installing the operating system. Let's take a closer look.

We activate the current settings with the command:

netplan apply

We examined the main options. More setup examples are on the official website.

What if the system does not use netplan?

It's the old fashioned way. First we get a list of available interfaces:

ifconfig -a

In this case, there are 2 network interfaces without IP addresses (for now). Configured by DHCP. Let's move on to the settings.

sudo nano /etc/network/interfaces

A server receiving IP from a DHCP server is not a good solution. We bring the file to the form:

What does this mean.

The second and subsequent interfaces are configured in the same way or configured using a DHCP server. Apply settings:

sudo /etc/init.d/networking restart

[1]
Edit
Query
Report
Darby Swartzwelder
Quality Improvement
Answer # 2 #
  • 2.1. Using "ip" Usage: # ip link set dev up # ip link set dev down. Example: # ip link set dev eth0 up # ip link set dev eth0 down.
  • 2.2. Using "ifconfig" Usage: # /sbin/ifconfig up # /sbin/ifconfig down.
[1]
Edit
Query
Report
Daud Kunjal
WIDTH STRIPPER
Answer # 3 #

Ubuntu ships with a number of graphical utilities to configure your network devices. This document is geared toward server administrators and will focus on managing your network on the command line.

Ethernet interfaces are identified by the system using predictable network interface names. These names can appear as eno1 or enp0s25. However, in some cases an interface may still use the kernel eth# style of naming.

To quickly identify all available Ethernet interfaces, you can use the ip command as shown below.

Another application that can help identify all network interfaces available to your system is the lshw command. This command provides greater details around the hardware capabilities of specific adapters. In the example below, lshw shows a single Ethernet interface with the logical name of eth4 along with bus information, driver details and all supported capabilities.

Interface logical names can also be configured via a Netplan configuration. If you would like control which interface receives a particular logical name use the match and set-name keys. The match key is used to find an adapter based on some criteria like MAC address, driver, etc. The set-name key can be used to change the device to the desired logical name.

ethtool is a program that displays and changes Ethernet card settings such as auto-negotiation, port speed, duplex mode, and Wake-on-LAN. The following is an example of how to view the supported features and configured settings of an Ethernet interface.

The following section describes the process of configuring your system’s IP address and default gateway needed for communicating on a local area network and the Internet.

For temporary network configurations, you can use the ip command which is also found on most other GNU/Linux operating systems. The ip command allows you to configure settings which take effect immediately – however they are not persistent and will be lost after a reboot.

To temporarily configure an IP address, you can use the ip command in the following manner. Modify the IP address and subnet mask to match your network requirements.

The ip can then be used to set the link up or down.

To verify the IP address configuration of enp0s25, you can use the ip command in the following manner:

To configure a default gateway, you can use the ip command in the following manner. Modify the default gateway address to match your network requirements.

You can also use the ip command to verify your default gateway configuration, as follows:

If you require DNS for your temporary network configuration, you can add DNS server IP addresses in the file /etc/resolv.conf. In general, editing /etc/resolv.conf directly is not recommended, but this is a temporary and non-persistent configuration. The example below shows how to enter two DNS servers to /etc/resolv.conf, which should be changed to servers appropriate for your network. A more lengthy description of the proper (persistent) way to do DNS client configuration is in a following section.

If you no longer need this configuration and wish to purge all IP configuration from an interface, you can use the ip command with the flush option:

To configure your server to use DHCP for dynamic address assignment, create a Netplan configuration in the file /etc/netplan/99_config.yaml. The following example assumes you are configuring your first Ethernet interface identified as enp3s0.

The configuration can then be applied using the netplan command:

To configure your system to use static address assignment, create a netplan configuration in the file /etc/netplan/99_config.yaml. The example below assumes you are configuring your first Ethernet interface identified as eth0. Change the addresses, routes, and nameservers values to meet the requirements of your network.

The configuration can then be applied using the netplan command.

The loopback interface is identified by the system as lo and has a default IP address of 127.0.0.1. It can be viewed using the ip command.

Name resolution (as it relates to IP networking) is the process of mapping hostnames to IP addresses, and vice-versa, making it easier to identify resources on a network. The following section will explain how to properly configure your system for name resolution using DNS and static hostname records.

Traditionally, the file /etc/resolv.conf was a static configuration file that rarely needed to be changed, or it automatically changed via DCHP client hooks. systemd-resolved handles nameserver configuration, and it should be interacted with through the systemd-resolve command. Netplan configures systemd-resolved to generate a list of nameservers and domains to put in /etc/resolv.conf, which is a symlink:

To configure the resolver, add the IP addresses of the appropriate nameservers for your network to the netplan configuration file. You can also add optional DNS suffix search-lists to match your network domain names. The resulting file might look like the following:

The search option can also be used with multiple domain names so that DNS queries will be appended in the order in which they are entered. For example, your network may have multiple sub-domains to search; a parent domain of example.com, and two sub-domains, sales.example.com and dev.example.com.

If you have multiple domains you wish to search, your configuration might look like the following:

If you try to ping a host with the name server1, your system will automatically query DNS for its Fully Qualified Domain Name (FQDN) in the following order:

If no matches are found, the DNS server will provide a result of notfound and the DNS query will fail.

Static hostnames are locally defined hostname-to-IP mappings located in the file /etc/hosts. Entries in the hosts file will have precedence over DNS by default. This means that if your system tries to resolve a hostname and it matches an entry in /etc/hosts, it will not attempt to look up the record in DNS. In some configurations, especially when Internet access is not required, servers that communicate with a limited number of resources can be conveniently set to use static hostnames instead of DNS.

The following is an example of a hosts file where a number of local servers have been identified by simple hostnames, aliases and their equivalent Fully Qualified Domain Names (FQDN’s):

The order in which your system selects a method of resolving hostnames to IP addresses is controlled by the Name Service Switch (NSS) configuration file /etc/nsswitch.conf. As mentioned in the previous section, typically static hostnames defined in the systems /etc/hosts file have precedence over names resolved from DNS. The following is an example of the line responsible for this order of hostname lookups in the file /etc/nsswitch.conf.

To modify the order of these name resolution methods, you can simply change the hosts: string to the value of your choosing. For example, if you prefer to use legacy unicast DNS versus multicast DNS, you can change the string in /etc/nsswitch.conf as shown below:

Bridging is a more advanced configuration, but is very useful in multiple scenarios. One scenario is setting up a bridge with multiple network interfaces, then using a firewall to filter traffic between two network segments. Another scenario is using bridge on a system with one interface to allow virtual machines direct access to the outside network. The following example covers the latter scenario:

Configure the bridge by editing your netplan configuration found in /etc/netplan/, entering the appropriate values for your physical interface and network:

Now apply the configuration to enable the bridge:

The new bridge interface should now be up and running. The brctl provides useful information about the state of the bridge, controls which interfaces are part of the bridge, etc. See man brctl for more information.

Users of the former ifupdown may be familiar with using hook scripts (e.g., pre-up, post-up) in their interfaces file. Netplan configuration does not currently support hook scripts in its configuration definition.

Instead, to achieve this functionality with the networkd renderer, users can use networkd-dispatcher. The package provides both users and packages with hook points when specific network states are reached, to aid in reacting to network state.

The Netplan FAQ has a great table that compares event timings between ifupdown/systemd-networkd/network-manager.

It is important to be aware that these hooks run asynchronously; i.e. they will not block transition into another state.

The Netplan FAQ also has an example on converting an old ifupdown hook to networkd-dispatcher.

[0]
Edit
Query
Report
Asma Celimon
CLOTHESPIN DRIER OPERATOR