LFCS – Network Management

Jarret B

Well-Known Member
Staff member
Joined
May 22, 2017
Messages
340
Reaction score
367
Credits
11,754
These days, we connect nearly all computers to a network in some manner. Whether the connection is Ethernet (hard-wired) or Wi-Fi, there is a method of sharing data or accessing shared data.

When dealing with TCP/IP for the Internet, these commands can come in handy when there are connection issues.

ip’ Command

Most Linux users still use the command ‘ifconfig’ in a terminal when listing IP information on network devices. If you perform the command ‘man ifconfig’ on a CentOS system, you will see the following under ‘Notes’:

This program is obsolete! For replacement check ip addr and ip link.

For best practices, it is better to use the command ‘ip’. There is not a big rush to remove the command ‘ifconfig’ since so many users still rely on it, but who knows when the command will disappear from Linux.

The proper program to use is ‘ip’. There are a few parameters, but you really need only a few.

To get the basic information of all network devices, just run the command ‘ip addr’ or shortened to ‘ip a’. The command should return something similar to:

lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever

2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:0b:4e:22 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.42/24 brd 10.0.2.255 scope global dynamic noprefixroute enp0s3
valid_lft 594sec preferred_lft 594sec
inet6 fe80::d422:3331:e0eb:6d3f/64 scope link noprefixroute
valid_lft forever preferred_lft forever

3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:a8:fb:61 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.133/24 brd 192.168.56.255 scope global dynamic noprefixroute enp0s8
valid_lft 596sec preferred_lft 596sec
inet6 fe80::3ab8:c1b0:14e7:2291/64 scope link noprefixroute
valid_lft forever preferred_lft forever


The ‘lo’ device is the loopback (127.0.0.1) on every device. There are then two other devices (enp0s3 and enp0s8). They are both Ethernet Devices, which are designated by the name that starts with ‘en’. The devices are in the PCI Bus 0 (p0) and either Slot 3 (s3) or Slot 8 (s8). Wi-Fi devices start with a ‘wl’. The ‘wl’ is Wireless LAN, ‘o’ is on board, and when there are multiple devices, the system will number them. Names of devices added to a USB Port either start with ‘en’ or ‘wl’, depending on the connection, and the name will be based on the device and driver. The command lists the IP Address and Subnet Mask for both devices. You should see that it lists both the IP v4 and IP v6 addresses when enabled.

If you just want to see a specific controller, then use the parameter ‘show’ or ‘s’ followed by the device name. Such as to see the information for the device ‘enp0s3’ only, use the command ‘ip a s enp0s3’.

If you want only the IP4 or IP6 information, use the parameter ‘-4’ or ‘-6’ before the ‘a’ parameter. For the IPv4 information, the device ‘enp0s3’ only, use the command ‘ip -4 a s enp0s3’.

If you want to set a temporary IP address for a device, you can use the following command:

ip addr add <ip/subnet> dev <device-name>

Let’s say I had a laptop that was configured for use at my house. My house settings are all DHCP enabled, so this is easy. IF I take my laptop to an office that may not use DHCP, I then need to configure a manual IP Address and Subnet Mask. So, if I needed to change my Wi-Fi device (wlo1) to a static IP Address of 192.168.1.178/24, then my command would be:

ip addr add 192.168.1.178/24 dev wlo1

Once you reboot the laptop, the system loses the setting.You can delet
e the new IP Address by switching ‘add’ with ‘del’ as in the following command:

ip addr del 192.168.1.178/24 dev wlo1

NOTE: If you are using a Graphical User Interface (GUI), you can easily use the Network Settings to make changes. Using the Command-Line Interface (CLI) can be easier and faster, or even set up a script.

Network Manager

Because of the nature of computers, the Network Manager is a very important aspect of any system. For more clarity, though, Network Management is more suitable for understanding on mobile systems. You may find a use for these methods on a desktop or server, but they have more relevance to a laptop system.

There are some items in here that you may need more than others, but it is best to know them.

The Network Manager is a service that is named ‘NetworkManager’. The service name is case-sensitive.

Whether on Ubuntu or CentOS, you can verify the service is running with the command ‘systemctl status NetworkManager’. It should be active (currently running) and enabled (set to auto-start at boot).

NOTE: If the NetworkManager is not active or loaded (not found), the install the service with ‘sudo yum install NetworkManager’ for CentOS or ‘sudo apt install network-manager’ for Ubuntu.

To access the service, you need to use the command ‘nmcli’, which is ‘Network Manager CLI’.

Similar to the ‘ip’ command, the ‘nmcli’ program has many parameters. You can type the command ‘nmcli ’ and then press ‘TAB’ twice. If you do not put a space after the command ‘nmcli’, then you need to press ‘TAB’ three times. Once you select a parameter, such as ‘connection’ or ‘c’, you can press double ‘TAB’ again to see the parameters for the ‘connection’ parameter.

NOTE: You can simplify the parameter ‘connection’ as ‘c’ since there are no other parameters that start with a ‘c’.

Just using the command ‘nmcli’ will give more information on all physical network devices. An example of the output for one device is:

enp0s3: connected to Wired connection 1
"Intel 82540EM Gigabit Ethernet Controller (PRO/1000 MT Desktop Adapter)
ethernet (e1000), 08:00:27:0B:4E:22, hw, mtu 1500
ip4 default
inet4 10.0.2.42/24
route4 0.0.0.0/0
route4 10.0.2.0/24
inet6 fe80::d422:3331:e0eb:6d3f/64
route6 fe80::/64
route6 fe80::/64


To show just the physical devices, use ‘nmcli conn show’ to get:

NAME UUID TYPE DEVICE
Wired connection 1 5417a6c6-713b-3471-8355-fd70bc16b27c ethernet enp0s3
Wired connection 2 f9874449-7d38-3be6-9004-ab1006393d60 ethernet enp0s8


For a more verbose output, use the ‘-p’ or ‘pretty’ parameter. The usage varies between CentOS and Ubuntu. For CentOS, use:

nmcli -p conn show enp0s3

For Ubuntu, use:

nmcli -p conn show 1

In this last case, you specify the connection by the ‘Wired Number’. Here, ‘enp0s3’ is connection 1 and ‘enp0s8’ is connection 2.

If you want to create your own device to temporarily overwrite an existing device, you can do:

nmcli conn add con-name <device-name> ifname <current-device> type <physical-type:ethernet> <ip-type:ip4> <ip-address> <gateway-address-type:gw4> <gateway-address>

So, let’s say we want to overwrite the device ‘enp0s3’ with a name of ‘enet1’ with an IPv4 address of ‘192.168.1.75’ and a gateway address of ‘192.168.1.1’. The command would be:

nmcli conn add con-name enet1 ifname enp0s3 type ethernet ip4 192.168.1.75 gw4 192.168.1.178

Once you issue the command, there should be a message that the connection was successfully added. You need to bring down the current connection, in this case ‘enp0s3’, with the command:

nmcli conn down enp0s3

The new connection can be started by the new device name:

nmcli conn up enet1

You can now show the information for the new device with the command:

nmcli conn show enet1

To remove it, just reboot.

Conclusion

I’m hoping you found this interesting and helpful for using a mobile system. This method could be useful for systems that need to connect to a system that is on a different subnet (different IP Node and Machine on the same physical network).

Maybe I can write an article or two on TCP/IP Version 4 to help some of those who don’t get the math behind it. I didn’t touch on any of the math here, but knowing it can help with different IP Node and Machine IDs.
 

Members online


Latest posts

Top