List of Linux Networking and Troubleshooting Commands for Beginners

Network configuration and troubleshooting are the essential part of Linux administration. Even for a developer who works with Linux Systems, knowledge about Linux network commands is an added advantage. Few Linux networking command people use today is deprecated. In this post, I will explain about the important networking commands and its new versions.

Recommended: Learn Linux in 5 Days and Level Up Your Career Udemy Course

List of Linux Networking and Troubleshooting Commands

Let’s have a look at the list of  commands you can use to configure and troubleshoot networking in Linux

1. hostname

Hostname command is used to view the hostname of the machine and to set the hostname.

You can use the hostname command to set a new hostname for the machine.

If you set the hostname using “hostname” command, when you restart the machine, the hostname will change to the name specified in the hostname file ( eg: /etc/hostname). So if you want to change the hostname permanently, you can use the /etc/hosts file or relevant hostname file present on the server.

For ubuntu machines, you can change it in the /etc/hostname file.

For RHEL, CentOS and Fedora you can change it in the /etc/sysconfig/network file.

Also read: List of Linux Commands Every Developer Should Know

2. ping

The ping command is used to check if the remote server is reachable or not. Ping command has the following syntax.

ping using DNS name

ping using the IP address

Limit the packets to send

If you want to limit the ping output without using ctrl+c, then you can use the “-c” flag with a number as shown below.

3. ip (ifconfig)

ip command is used to display and manipulate routes and network interfaces. ip command is the newer version of ifconfig. ifconfig works in all the systems, but it is better to use ip command instead of ifconfig. Let’s have a look at few examples of ip command.

Display network devices and configuration

You can use this command with pipes and grep to get more granular output like IP address of eth0 interface. The following command gets the IP address of eth0 network interface.

READ  Linux Command Line Tips for Increasing Productivity

Get details of a specific interface

Enable and disable a network interface

You can enable and disable a particular network interface using IP command.

4. ss (netstat)

ss command is a replacement for netstat. You can still use netstat command on all systems. Using ss command, you can get more information than netstat command. ss command is fast because it gets all the information from the kernel userspace. Now let’s have a look at few usages of ss command.

Listing all connections

The “ss” command will list all the TCP, UDP and Unix socket connections on your machine.

The output of ss command will be big so you can use ” ss | less ” command to make the output scrollable.

Filtering out TCP, UDP and Unix sockets

If you want to filter out TCP , UDP or UNIX socket details, use “-t” “-u” and “-x” flag with the “ss” command. It will show all the established connections to the specific ports. If you want to list both connected and listening ports using “a” with the specific flag as shown below.

List all listening ports

To list all the listening ports, use “-l” flag with ss command. To list specific TCP, UDP or UNIX socket, use “-t”, “-u” and “-x” flag with “-l” as shown below.

5. traceroute

traceroute is a network troubleshooting utility. Using traceroute you can find the number of hops required for a particular packet to reach the destination. If you do not have traceroute utility in your system or server, you can install it from the native repository.

READ  How to Setup AWS ECS Cluster as Build Slave for Jenkins

The above output shows the hop count (12) to reach google.com from devopscube AWS ec2 server.

6. dig

If you have any task related to DNS lookup, you can use “dig” command to query the DNS name servers. If you want to get the A record for the particular domain name, you can use the dig command with the domain name. From the output, in the answer section, you will find the A record of the domain name as shown below.

7. route

“route” command is used to get the details of route table for your system and to manipulate it. Let us look at few examples for the route command.

Listing all routes

Execute the “route” command without any arguments to list all the existing routes in your system or server.

If you want to get the full output in numerical form without any hostname, you can use “-n” flag with the route  command.

If you think we missed any important command,  let us know in the comments section.

Free DevOps Resources

Get DevOps news, tutorials and resources in your inbox. A perfect way If you want to get started with devops. Like you, we dont like spam.

Leave a Reply

Your email address will not be published. Required fields are marked *