There are two ways to manage the network connections on a Linux machine—with NetworkManager and by editing configuration files. This video discusses the basics of both.
- [Instructor] On Ubuntu, there are two primary ways to configure network settings. We can make manual changes to configuration files, and on recent versions of Ubuntu, the networking settings can be handled by a service called NetworkManager. On Ubuntu, configuration files that control network interfaces are kept in the etc/network folder, in a file called interfaces. Here we define the behavior and settings for network interfaces on the system. Each interface has a few lines of text describing it, and we'll look at that in detail later on.
The entries in this file are brought up and brought down by the networking service, and if you make changes, you'll need to restart that service in order for things to take effect. There are also a few folders within the network folder, ending with .d, which contain scripts that run when certain actions are taken on the network interface, bringing it up, bringing it down, and so on. These can be helpful for adding custom actions, and are used for certain existing services already, like the name resolution service updates and interacting with wi-fi networks. The other way of configuring devices is with NetworkManager, a service that has a handful of apps that configure network settings interactively.
The app we'll be using primarily in this course is nmcli, the command line interface, though there's also a text mode app called nmtui, and various apps for different desktop environments. When the NetworkManager service is enabled, it won't manage interfaces listed in the etc/network/interfaces file, so you can choose whether a particular network interface is managed by NetworkManager or not. Because of this, file-based configuration and NetworkManager managed configurations can co-exist on the same machine, but it's usually a good idea to stick to one or the other to keep things clear.
We use NetworkManager to create connections, which are groups of configuration settings for a device. The connection defines how the device should connect to a given network, what its parameters are, and so on. Rather than making changes manually to a file, with NetworkManager, we configure a connection at the command line or interactively. The nmcli command that I mentioned earlier has a few options that let us look at different things. Typing it by itself shows us some helpful text. There's some options to display data differently, and here at the bottom are the various objects we can look at.
They're written like this, with square brackets, to remind us that while we could type out the full object name, and that would work, using just the first letter also works. If I wanted to take a look at general information about NetworkManager, I can type nmcli general, or just nmcli g, and see an overview of what's connected. I could use nmcli c, or connection, and that shows the connections that NetworkManager knows about.
Nmcli d shows the devices that NetworkManager knows about. Here I can see my ethernet connection, and under devices, there's the ethernet device itself. I can see how these are associated, the connections view refers to an entry under connection in the device view, and the device name in the device view refers to a device in the connections view. For each of these objects, you can get more specific help about how to use them by adding help on the end. For connection information, for example, nmcli c, for connection, and then help shows me the usage information.
Throughout the course, we'll use some other commands, and if you want to explore on your own, you can. It's good to be familiar with both ways of configuring connections, manually, and with NetworkManager. As we configure the network interfaces, we have two options of how to tell them about addressing information. We can configure them to be dynamic or static. When we set up a system to be part of a network, it needs an IP address and other information about that network. One way to do this is to allow the machine to be given a dynamically assigned IP, or dynamic IP, one assigned by DHCP.
DHCP, or Dynamic Host Configuration Protocol, is a way for a client system to communicate with the server that's responsible for handing out and keeping track of IP addresses used on the network. The DHCP server then tells the client what address information to use. This is how most home networks and many organizational networks function. Dynamic addressing is helpful, because while any machine on the network needs an address to communicate, most of the time, it doesn't matter which address a machine has, as long as it's valid on the network and isn't being used by something else already.
If a network doesn't have a DHCP server, or the addressing for a particular machine needs to be configured manually, we can set a static IP address, one that doesn't change. This is extremely useful for servers, and for other devices that need to be reached consistently. If you're setting up your machine to have a domain name, for example, the record needs to point to something fixed, and a dynamic IP that can change would cause problems with that. Setting a static address is critical for some systems, but you need to be sure you're not using an address that's already in use.
If the system you're configuring is moved to a different network, it won't be able to connect using the static address from a different network. That means you'd need to reconfigure the network from a local console rather than remotely. Desktops and laptops usually use DHCP with NetworkManager, and servers usually will have a static IP configured in the interfaces file, but that's not always the case. It's important to know how to configure both kinds of addressing setups, and you'll need to choose which approach to use for systems on your network.
As I mentioned before, the two services that we'll be dealing with here are NetworkManager and networking. We can check the status of these services with the systemctl status command. To start or stop a service, we can use start or stop in the command, and to set a service to start up at boot or not, we can enable or disable it, and if we need to restart the service for some reason, like if we've made a change to the interfaces file and we need services to pick up on it, we can use systemctl restart and the servicename.