Basic Linux Commands for Network Testing

Managing networks is the primary job of a Linux administrator. As a Linux enthusiast, you learn many commands, tools, and utilities the administrators use to configure, manage, and troubleshoot network settings. This tutorial explains these commands in detail with examples.

The ip addr show command

This command displays the current configuration and status of all network interfaces. You can use this command to view the following information.

Current status: - whether the interface is up or down.

Mac address: - physical address of the interface.

IPv4 address: - IPv4 address of the interface.

IPv6 address: - IPv6 address of the interface.

The following image shows how to read/view the above information from the output of this command.

the ip addr show command

The "ip link show" command

This command displays the current status of interfaces. If you only want to view the link state information of interfaces or know whether a particular interface is up, you can use this command. Besides the IP configuration, this command provides the same information that the "ip addr show" command provides.

the ip link show command

By default, the 'ip addr show' and 'ip link show' commands display the configuration of all interfaces. If you want to view the configuration of a single interface, you need to specify the interface's name as the argument. For example, if you want to view the configuration of the interface eno16777736, use the following command.

#ip addr show eno16777736
ip addr show interface command

The 'ip addr flush dev [device]' command

This command flushes the current IP configuration. If the system is configured to get the IP address from the DHCP server, you can use this command to force the system to get the new IP address from the DHCP server.

The following command removes/flushes the IP configuration from the device the eno16777736.

#ip addr flush dev eno16777736

ip addr flush dev command

The 'ip addr add [IP address/netmask] dev [name]' command

This command allows you to add a temporary IP address to the interface. The assigned IP address works only in the current session. You can use it to transfer data or test connectivity between different IP subnets.

The following command adds the IP address 172.168.0.1 to the interface eno16777736.

#ip addr add 172.168.0.1/16 dev eno16777736

adding temporary ip

The 'ip link set dev [interface] up/down' command

This command allows us to enable and disable the specified interface. The following command disables the interface.

#ip link set dev [interface] down

The following command enables the interface.

#ip link set dev [interface] up

setting up and down interfaces

The 'ip neigh' command

This command displays the ARP table of the local system. A system uses the ARP table to map the hardware address and software address of computers available on the local network.

the ip neigh command

In the output: -

  • The first column shows the IP address of the remote system.
  • The second column shows the name of the local interface to which the remote system is attached.
  • The third column shows the hardware address of the local interface to which the remote system is attached.
  • The fourth column shows whether the remote system is reachable or not.

Here, a remote system is any other system available on the local network.

A system uses the ARP protocol to build the ARP table. The ARP protocol works only on the local network. It means you will not see the IP address of any system that is not available on the local network or connected to the local network through the router.

The 'ping [ip address or name of remote system]' command

This command allows us to test connectivity between two computers. It sends small data packets to the destination device. If the destination device is UP, it replies. The ping command on the source device displays the result of each data packet.

If you see the reply in the output, it indicates that the source and destination have connectivity.

the ping command

The 'traceroute -n [ip address or hostname of remote system]' command

This command prints the path data packets take to reach the destination. You can use this command to view the path between the source and the destination. You can also use this command to locate the non-functioning router on the path.

tracerote command

The 'ip route' command

This command displays the IP address of the default gateway. A default gateway connects the local network to the remote networks. A system can access a remote system only if it is connected to the default gateway.

the ip route command

The 'ss -tupna' command

This command displays the opened network connections and their sockets. You can use this command to view a list of all open connections.

viewing open connection

Conclusion

In this tutorial, we discussed basic networking commands. These commands are essential for network management-related tasks. By learning these commands, you can view and troubleshoot simple networks.

ComputerNetworkingNotes Linux Tutorials Basic Linux Commands for Network Testing