13 Commands for managing network on Linux

Stay on top of the main commands used in Linux distributions for managing network interfaces. These commands are essential in the daily life of a Linux Network Administrator, being one of the main points of his work routine. Know more!

For IT professionals who act as Network Administrators, it is common to use the command line (cli) to perform various tasks, among them, for example, how to test the communication between hosts, add a new route to be taken, measure the speed of the Internet and even monitor incoming and outgoing traffic from an interface.

Read more:

FIND, Finding Anything on Linux
Permissions on Linux - Understanding chmod
5 practices to keep Linux SSH secure
How to install FileZilla on Linux manually
Integrating CentOS with Active Directory

In this article, I will cover with some examples the main network commands used in Linux that can make life much easier for those who need to set up a network or obtain information about a connection.

Without further ado, let's get down to business!

PING

Ping (Packet Internet Network Groper - or in Portuguese, packet finder on the internet network) is used to measure the time (usually in milliseconds) to send and receive a data packet between devices on the same network or the connection Internet servers or public addresses. This command is available on almost all operating systems, not just Linux. His objective is to check that all equipment is connected and responsive to commands, as well as to evaluate the quality of communication between network infrastructures.

As an example, to find out the response time between one host and another, we use:

$ ping 192.168.1.1

With the result of the above test, we can find that:

  • The computer where the ping test is being performed, is able to see the destination host;
  • The 6 packets transmitted got 6 responses, so there was no packet loss;
  • The response time between hosts is short, which indicates good communication performance. The longer the time, the slower the data transmission and the more difficult it is to synchronize information in real time;

In this other example, the ping test was unable to find the destination host:

An unsuccessful result of the ping test means that it was not possible to carry out communication between the devices, and for that, it will be necessary to take other measures, such as checking the network, the cabling, the IP range and the infrastructure equipment responsible for ensure the communication of the devices. 

There are some parameters that can be used together with the ping command, which can be consulted by typing in the terminal:

$ ping -h

#Profissa: Take a professional course!
Ensure a certified course in IT and Software through the online study platform Udemy.
click here and check out all the latest technology courses!

IFCONFIG

This command is used to list, configure and control information about TCP / IP parameters of a network interface. It is used to configure an IP address and netmask on a network interface, view host interfaces and enable or disable the interface. Its main uses are:

$ ifconfig -> Display the active network interfaces;

$ ifconfig -a -> Display all network interfaces, active and inactive;

# ifconfig virbr0 192.168.1.93 netmask 255.255.255.0 -> Used to define a temporary IP and netmask for the eno1 interface.

Extra: 

There is also how to connect and disconnect a network interface using the commands:

#ifup virbr0 -> Turn on the network interface named virbr0;

#ifdown virbr0 -> Turn off the network interface named virbr0;

ROUTE

This command is used to display the active routes of a host with the network, and also serves to add a static route to be followed. To list the routes of the device with the network, we can use:

$ route -n

To add a static route manually, use the command:

$ route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

The above command adds the route for the device to communicate with the local network in the 192.168.1.0/24 range.

ETHTOOL

With this command it is possible to check which interfaces are, change the speed, change the way of trading and even check which interface is physically connected.

To show the speed of the network card and whether it is connected:

$ ethtool eno1

To make the network interface physically blinking so you can find out what the interface is:

# ethtool -p eno1 20

Where: 

eno1 -> Interface name;

20 -> time in seconds to flash;

This command is very useful when you need to physically identify the interfaces on the server and there is no evidence or documentation.

To manipulate the speed of the interface, which can limit the trading rate:

# ethtool -s eno1 speed 35 dupĺex [half | full]

Where:

eno1 -> interface name;

35 -> speed in MB;

NMTUI

This command is used to configure network cards in graphical mode through a graphical interface, opened in SSH itself when typing the command:

$ nmtui

With it, we can manipulate the connection information through the screen:

NETSTAT

The netstat command is used to check which ports are open on the host. Its use occurs through:

$ netstat -tupan

To check if a specific door is open, use it as follows:

$ netstat -tupan | grep 80

#Profissa: Take a professional course!
Ensure a certified course in IT and Software through the online study platform Udemy.
click here and check out all the latest technology courses!

TCPDUMP

This command is used to monitor traffic that is passing through a computer network. With this command it is possible to monitor the traffic of specific hosts through the IP address and the service ports.

# tcpdump -i eno1 arp

There are other parameters that can be used to refine this command:

# tcpdump -i eno1 src host 192.168.1.2 >> Monitor all traffic from eth0 from ip: 192.168.1.2.

# tcpdump -i eno1 src port 3389 >> Monitor traffic on source port 3389.

# tcpdump -i eno1 dst port 3389 >> Monitor destination port 3389, could place destination (src) and source (dst).

# tcpdump -i eno1 not host 192.168.1.9 >> Monitor all eno1 interface traffic except host 192.168.1.9.

# tcpdump -i any host 177.86.200.200 and icmp >> Display all traffic from all interfaces for specific ip and icmp protocol.

# tcpdump -i eno1 icmp >> View all eth0 traffic by filtering the icmp protocol.

TCPDUMP command parameters:

-i: Specify the network interface;

any: All interfaces;

host: Specify the IP;

and: And specify another protocol;

dst: Destination (specify IP);

src: Origin (Specify IP);

DHCLIENT

This command is used to force a network interface to obtain an IP automatically from an active DHCP server on the network. Usually when connecting a new device on the network, if there is a DHCP server it will receive an address automatically. If not, with the dhclient command it is possible to force the search manually for a valid address.

# dhclient -i eno1

TRACEROUTE

The traceroute command is used to trace the routes taken to a destination by sending ICMP echo packets, listing all hops performed. This command is useful to find the location where a packet stopped before reaching its final destination, and can help the network administrator to solve the problem, diverting traffic by another route (in the case of our example, we are using the DNS IP Of google).

# traceroute 8.8.8.8

#Profissa: Take a professional course!
Ensure a certified course in IT and Software through the online study platform Udemy.
click here and check out all the latest technology courses!

TRACEPATH

The tracepath command returns information very similar to traceroute. However, there are not so many details and super user privileges are not required to run it:

$ tracepath 8.8.8.8

MTR

The MTR command is similar to the traceroute, what differentiates it is the fact that it automatically updates the jumps while the traceroute after listing, you need to run the command again to update the list.

# mtr 8.8.8.8

NMAP

The NMAP command is used to display host information, such as netbios name, status and ports that are open.

$ nmap 192.168.1.93

When it is necessary to list the ports being used by services hosted on a host, the NMAP command can be very useful to the system administrator.

NBTSCAN

This command is used to discover the netbios name of a host through the IP address.

This is very useful and can help the times when you need to identify the name of a device and the administrator does not know the physical location of it, the only information you have at hand is the IP address.

Well folks, that's it for today and I hope you enjoyed the content and can enjoy it for your learning.

This article was written by me João Paulo Scopel and published exclusively for the website Dicas de Infra. Its distribution is authorized and free, as long as the credits to the creator and to the site dicasdeinfra.com.br are maintained.

I work as an Open Source Solutions Consultant, if you need any work, mentoring or consulting, through the contact channels of the Blog or my Social Networks I will be available.

reference: linuxnaweb.com

Was this article helpful?

To maintain a quality standard for you, we have invested in a great hosting plan, Paid CDN, Website Optimization Plugins, etc ...

Help us to keep the project active! 

Follow the news in real time. Follow our Instagram profile.

João Paulo Scopel
João Paulo Scopel has a degree in Information Systems and a professional in Information Technology for 10 years. Acts as a Technology and Infrastructure Analyst with an emphasis on Linux solutions, is an Open-Source Solutions Consultant for companies and is a Columnist of Dicas de Infra.
en_USEnglish

UP TO 90% DISCOUNT

TAKE OFF YOUR CAREER !!

Do you want to upgrade your career? 

Invest in yourself and get ahead! Get that dream job in 2021!