ip link deals with the network devices.
nmcli deals with the "profiles" or "settings" that tell the system how to use the network devices.
View current devices
in this tutorial, we will use available network interface as example. Record down available online device name.
nmcli device status
View current profiles
nmcli connection show
Create a profile
nmcli connection add con-name "[Profile name]" ifname [Device] type [Type] -- [Properties]
[Type] and [Properties] are obtained from IT department.
Example: sudo nmcli connection add con-name "dummy-lab" ifname enp0s3 type ethernet -- ipv4.addresses 10.0.0.50/24 ipv4.gateway 10.0.0.1 ipv4.method manual
Verify the profile exists
nmcli connection show
Check current connection
ip a
Activate profile
sudo nmcli connection up "[Profile name]"
Example: sudo nmcli connection up "dummy-lab"
Validate the IP address
ip a show dev [Device]
Example: ip a show dev enp0s3
Validate the gateway
ip route show
[Cleanup] Switch back to your original connection
sudo nmcli connection up "[Device]"
Example: sudo nmcli connection up "enp0s3"
[Cleanup] Delete the dummy profile
sudo nmcli connection delete "[Profile name]"
Example: sudo nmcli connection delete "dummy-lab"
Solution
student@localhost:~$ nmcli device status
DEVICE TYPE STATE CONNECTION
enp0s3 ethernet connected enp0s3
lo loopback connected (externally) lo
student@localhost:~$ nmcli connection show
NAME UUID TYPE DEVICE
enp0s3 82a01695-c03f-31f0-a493-b94df1b1c235 ethernet enp0s3
lo 261d83f3-4caa-4be9-982f-5552120d398a loopback lo
student@localhost:~$ sudo nmcli connection add con-name "dummy-lab" ifname enp0s3 type ethernet -- ipv4.addresses 10.0.0.50/24 ipv4.gateway 10.0.0.1 ipv4.method manual
[sudo] password for student:
Connection 'dummy-lab' (73fadc27-5717-4948-9caf-b58ad022dead) successfully added.
student@localhost:~$ nmcli connection show
NAME UUID TYPE DEVICE
enp0s3 82a01695-c03f-31f0-a493-b94df1b1c235 ethernet enp0s3
lo 261d83f3-4caa-4be9-982f-5552120d398a loopback lo
dummy-lab 73fadc27-5717-4948-9caf-b58ad022dead ethernet --
student@localhost:~$ ip a
1: 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 noprefixroute
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:51:d6:54 brd ff:ff:ff:ff:ff:ff
altname enx08002751d654
inet 192.168.0.110/24 brd 192.168.0.255 scope global noprefixroute enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe51:d654/64 scope link noprefixroute
valid_lft forever preferred_lft forever
student@localhost:~$ sudo nmcli connection up "dummy-lab"
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
student@localhost:~$ ip a show dev enp0s3
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:51:d6:54 brd ff:ff:ff:ff:ff:ff
altname enx08002751d654
inet 10.0.0.50/24 brd 10.0.0.255 scope global noprefixroute enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::93a9:7cd6:b746:b05e/64 scope link noprefixroute
valid_lft forever preferred_lft forever
student@localhost:~$ ip route show
default via 10.0.0.1 dev enp0s3 proto static metric 100
10.0.0.0/24 dev enp0s3 proto kernel scope link src 10.0.0.50 metric 100
student@localhost:~$ sudo nmcli connection up "enp0s3"
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
student@localhost:~$ sudo nmcli connection delete "dummy-lab"
Connection 'dummy-lab' (73fadc27-5717-4948-9caf-b58ad022dead) successfully deleted.