Join Scott Simpson for an in-depth discussion in this video Manage the connection, part of Linux: Network Configuration.
- [Narrator] NetworkManager comes installed and running by default on newer distros. You can check if the NetworkManager service is running on your system with sudo systemctl status NetworkManager, and can see that it's running on my system. If it's not running for you, you can start it with sudo systemctl start NetworkManager. And if NetworkManager is not installed, you can install it with your distro's software manager. For example, I type sudo yum install NetworkManager, or on the Debian distro, I have to get install network dash manager.
In order for network manager to make changes to a connection, the connection needs to be marked as managed. Depending on your distro and version, your connections may or may not be managed already. On most current distros, NetworkManager automatically manages any connection that isn't specifically set otherwise. Let's take a quick look here on CentOS, and then over on Ubuntu. If you have two virtual machines running, you can follow along with both, or if you have one machine, follow along where you can, and sit back and watch the rest. I'll clear the screen.
We can check to see if our interfaces are managed with nmcli device. Don't worry about this command right now, I'll show you what it is in a few minutes. What we're looking for here is an indication of whether the devices are managed, or rather if they're unmanaged. Here on CentOS, I can see that only one of mine is marked as unmanaged, but that's the loopback and we're not concerned with that. The rest are managed, they come that way by default. But let's take a look at where that's controlled. On CentOS and Red Hat, the place where we control this is inside the interface configuration file for each interface.
We'll get into manual configuration in more detail later, but for now let's navigate to the configuration files with cd/etc/sysconfig/network-scripts, and let's check out what's here. These files are configuration settings for each interface, which by default get loaded up and set up by NetworkManager at boot. My interface is enp0s3, so I'll edit the corresponding configuration file with sudo vi ifcfg-enp0s3.
I mentioned that this interface is managed by network manager, but I don't see anything about that here. On CentOS, Fedora, and Red Hat, NetworkManager defaults to controlling interfaces it finds here, unless it's told not to. So to tell it not to manage this interface, I'd write NM_CONTROLLED=no. I'll save this with esc wq and then restart the network service so this change takes effect. Write sudo systemctl restart network, and now if I take a look with nmcli device, I can see that my ethernet device is now unmanaged.
But let's change that back so we can work with this device in NetworkManager. Again, I'll write sudo vi ifcfg-enp0s3. And I could remove this line or switch it to NM_CONTROLLED=yes. I want to put my settings back to how they were though, so I'll delete this line. And again save with esc :wq. Then I'll restart the network service again, with sudo systemctl restart network, and verify that my interface is managed again with nmcli device.
Great, I'm back to where I was. Over here on Ubuntu, let's check out the management situation with nmcli device. And it shows that my ethernet interface is managed here too. If it were set to unmanaged, I could edit the NetworkManager configuration file with sudo nano /etc/NetworkManager/NetworkManager.conf and change the managed directive to true. I'll save with ctrl o, enter control x, and I'll restart the network manager with sudo systemctl restart NetworkManager.
(typing) Great, my interface is managed. Now we should be in a good position to use NetworkManager to configure our connection. For the rest of this chapter, I'll stay over here on CentOS, but you should be able to follow along with whatever you're using.
Note: This course concentrates on the CentOS distribution of Linux, but there are separate lessons on configuring networking for Ubuntu/Debian.
- Finding device information
- Managing connections with NetworkManager
- Configuring dynamic addresses using DHCP
- Configuring static clients
- Configuring Wi-Fi
- Configuring networking manually
- Setting the hostname
- Configuring the firewall
- Routing traffic between networks