Linux Networking | Easy

Hello everyone In this Article we are going to learn to Configure Network Using nmcli tool in Linux in a very simple and easy step-by-step approach

Yellow Fishing Boat Blog Banner 97

Linux Networking

How IP is configured in LAN Card

We will not put IP directly on the LAN Card we 1st make the connection then that connection bind with the LAN Card

In NMCLI we can make a number of connections. When we make a connection one profile is created on that profile IP is assigned that Profile is bind with the LAN Card soo runtime any profile which is the bind that will be the current IP of the machine.

What is the benefit of making the profile???

Suppose that we have one office and there are 4 branches of our office across different locations Ex.

Branch -1 – India – Has the IP range of 10.0.0.0/24

Branch -2 – USA – Has the IP range of 30.0.0.0/24

Branch-3 – UK -Has the IP range of 40.0.0.0.0/24

Now there is one person who use to travel to different locations frequently If we assign the IP Address to the LAN Card of the Laptop then where the person goes he has to assign the IP to that specific location range. They can call to desktop support engineer and they will assign the IP Of that machine according to their range

But if we use the Concept of the profile we can assign the IP To the profile accordingly where is the person they can only have to Use that profiles. This is an easy task that person will do this by own no need to call to a desktop support engineer

How to view profile

1.How to view the Profiles

With the help of nmcli command, with the connection show option we can see how many profiles are there in our server.

# nmcli connection show
Screenshot 18 10

2. How to check the number of devices attached

With the help of nmcli command with the device show option, we can see how many devices are there and detailed information about each device. Like mac address of the device and type etc.

# nmcli device show 
Screenshot 2 16

3, How to check a number of devices that are active

When we add the ( –active ) option in nmcli command then we will get the information on how many devices are active on our server.

# nmcli connection show --active
Screenshot 3 15

4. How to check device status

To check what is the status of the device that is attached to our server then we can add the ( status ) option in nmcli command and tell what is the status of each device.

# nmcli device status
Screenshot 4 16

How to add a new connection?

To add new connection we can use the nmcli tool to add the connection

For the USA-Office we want to assign following details

IP Address – 20.0.0.12/24

Gateway – 20.0.0.1

DNS – 20.0.0.20

In this command, we have defined the connection / IP address / Gateway / DNS and we used autoconnect yes because we want to make our connection presitant.

# nmcli connection add con-name USA-Office ifname ens33 type ethernet ipv4.address 20.0.0.12/24 ipv4.gateway 20.0.0.1 ipv4.dns 20.0.0.20 autoconnect yes
Screenshot 19 11

For the India-Office we want to assign following details

IP Address – 30.0.0.12/24

Gateway – 30.0.0.1

DNS – 30.0.0.30

In this command, we have defined the connection / IP address / Gateway / DNS and we used autoconnect yes because we want to make our connection persistent.

# nmcli connection add con-name India-Office ifname ens33 type ethernet ipv4.address 30.0.0.12/24 ipv4.gateway 30.0.0.1 ipv4.dns 30.0.0.30 autoconnect yes
Screenshot 20 9

For the UK-Office we want to assign following details

IP Address – 40.0.0.12/24

Gateway – 40.0.0.1

DNS – 40.0.0.30

# nmcli connection add con-name UK-Office ifname ens33 type ethernet ipv4.address 40.0.0.12/24 ipv4.gateway 40.0.0.1 ipv4.dns 40.0.0.30 autoconnect yes
Screenshot 21 7

Now when we execute nmcli connection show command we can see that the connections that we created are displayed here. \

And the USA-Office connection is active

Screenshot 8 13

If we want to see the IP address for the connection that is currently active we can execute this command

 # ifconfig | grep -i inet | head -1
Screenshot 9 13

How to Down the Connection

To down the USA-Office connection then we can run this command.

# nmcli connection down USA-Office
Screenshot 27 3

Again when we see the connections using nmcli connection show command we can see that ens33 connection is UP automatically

Screenshot 28 2

And when we execute # ifconfig command we can see that IP is also allocated to the device now

Screenshot 29 2

How to Up the Connection

To UP the UK-Office connection then we can execute this command.

# nmcli connection up UK-Office
Screenshot 30 2

Now when we execute nmcli connection show command again we can see that the UK-Office connection is UP now

Screenshot 31 1

How to Add More IP Address

To add one more IP to the UK-office then we can use the modify a parameter in the nmcli command

# nmcli connection modify UK-Office +ipv4.address 10.125.170.12/24
Screenshot 32 1

# nmcli device status UK-Office – When we execute this command we can see that the UK-Office Device got 2 Ip’s now

How to Add More DNS Value

To add one more DNS to the UK-office then we can use the modify a parameter in the nmcli command

# nmcli connection modify UK-Office +ipv4.dns 8.8.8.8
Screenshot 33 1

How to Delete the Connection

To delete the connection we can write the delete option in the nmcli command with the connection name that we want to delete

Screenshot 37

Now when we run the nmcli connection show command then we can see that our ens33 connection is now deleted

Screenshot 38

Conclusion

If you want to learn Linux in the most simple language then please click on this link.

This is the complete knowledge of how we can configure networking using nmcli command in the Linux kernel if you have any doubts please feel free to comment below. Please don’t forget to join our email subscription to get the latest updates on DevOps Articles.

Leave a Comment