14 Useful Linux Networking Commands

Are you tired of fumbling around with your Linux networking configurations? Look no further than these 14 useful commands to simplify your life! Whether you’re an experienced sysadmin or a newbie, this comprehensive list will provide the tools you need to manage and troubleshoot your network connections. Say goodbye to frustration and hello to smooth sailing with Linux networking. Let’s dive in!

ip

If you are like most people, you use your computer for work, entertainment and personal tasks. You use your network to share files, printers and other devices with other users on your home or office network. In this article we will show you some useful Linux networking commands to help you manage your network.

To start with, let’s look at the basic command to list all active networks:

# ip addr

This command will list all active interfaces and their associated addresses. For example, if we were connected to a local network using an Ethernet cable, the output would look something like this:

1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00 2e inet 127.0.0.1/8 scope host valid_lft forever preferred_lft forever 3: eth0 (eth0): mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08-5c-2a-b6-f7 brd ff:[ffff::ffff]:ff:[ffff::ffff] 4e inet 192.168.1.101/24 brd 192.168.1.255 scope global eth0 valid

nmap

One of the most powerful networking tools available on Linux is nmap. This tool can be used to scan a network for vulnerable machines, open ports, and perform host discovery. In this article, we will cover some of the most useful nmap commands and provide examples of how to use them.

nmap can be used to scan for hosts and services on a network. The -A option scans all hosts on the network, while the -P parameter scans for specific service types (ports). The following example will scan for hosts on the local network:

nmap -P0 -A 192.168.1.0/24

The nmap command line has many other options that are not covered in this article. If you want to know more about them, check out the nmap manual page or use the man nmap command to get a list of all available options.

nmap is very versatile and can be used in many different ways. Some common uses include scanning for security issues, checking open ports, discovering hosts and services on a network, and detecting remote machine administration accounts. If you need to scan a large network or want to learn more about how nmap works, then I recommend reading the nmap user guide or searching online for resources that cover specific uses for nmap.

ping

ping is a command that allows you to test the reachability of remote hosts on the network. By default, ping works on network interfaces with an IP address. However, you can also use ping to test reachability for hostnames or addresses using the -N flag.

The -t flag can be used to specify a timeout in milliseconds before returning a failure response. The -r flag can be used to determine the round trip time (RTT) between your computer and the target host. The -c flag can be used to set a count value that will be printed after each successful or failed ping request.

You can also use ping to check whether a device is alive by issuing the following command:

ping devicename
If you don’t specify any arguments, ping prints out information about all currently active network interfaces.

iPerf

1. iPerf is a Linux command line tool used to measure network performance. It can produce detailed information on the performance of network connections, such as throughput, latency, and packet loss.

2. To use iPerf, first open a terminal window and type the following command:

iperf –c [options] host1[:host2[:…]]

3. You can also specify a particular port or interface to measure using the -p or –i options, respectively. For example, to measure the bandwidth between host1 and host2 on port 5555 using iPerf, you would type the following command:

iperf –c 5555 –p 5555

traceroute

1. traceroute
2. ping
3. ipcalc
4. route -n

Traceroute is a network diagnostic tool that can be used to determine the route taken by packets through a network. To use traceroute, you first need to specify the hostname or IP address of the target machine, followed by the path to the destination machine (or hosts). Here’s an example using traceroute to test connectivity to server 192.168.1.1:

traceroute 192.168.1.1 > tracepath

If you want to see only ICMP errors, use this command:
traceroute -i icmp

ping is a utility for determining whether a machine is online and responding to requests from other machines on the network. You can use ping to check for active connections, verify reachability, and test latency between two hosts. The syntax for ping is as follows:
ping [hostname]

The example below uses ping to check connectivity between two hosts:
ping 192.168.1.2

ipcalc is a simple utility that allows you to calculate IP addresses and subnet masks using given hostnames or IP addresses as arguments. Here’s an example using ipcalc to calculate IP addresses for server 192.168.1.1:

tcpdump

The tcpdump utility can be used for network debugging and analysis. It can capture and display detailed packets data on a Linux system. tcpdump can be used to identify problems with network connections, protocol implementation, and traffic flow.

netstat

Netstat is a command line utility for viewing active network connections and traffic statistics. It can be used to identify which applications are using the most bandwidth, which ports are being accessed the most frequently, and which hosts are communicating with each other.

To use netstat, you must first determine which interface your computer is connected to the network on. To do this, use the ifconfig command:

ifconfig ethernet eth0

If you are not sure what interface your computer is connected to, you can also use the enp7s0 interface:
2. Once you have identified your interface, enter the following command:

netstat -an | more
This command will display all active network connections and traffic statistics. You can then use the arrow keys on your keyboard to scroll through the list of items displayed. The following table provides some sample output from this command:

Table 1: Sample netstat Output

IP Address Subnet Mask Protocol State User PID %CPU %MEM kbytes packets bytes 7c3f9a68-1dd2-4e4d-b029-519eff00fbcd 192.168.1.128 255.255.255.224 UGCP 0 4294967295 100 58296 30664 1327360 1 8c79fecc-5691-417c-bca9-da8f4dbbd713 10.0.

ss

SSH is a secure remote login protocol for Linux used for logging into systems as well as transferring files. To connect to a SSH server, you first need to know its address. There are several ways to find an SSH server’s address. One way is to use the NetworkManager utility. You can also type the following command:

ssh [server’s hostname]

In this example, we are connecting to the server at 10.0.1.11 using the user pi and password raspberry .

To disconnect from the SSH server, type quit at the prompt.

ssh

SSH is a secure Shell protocol that allows you to connect to remote machines using Secure Shell (SSH). SSH lets you access your machine from anywhere in the world, and provides security benefits over traditional network connections.

To use SSH, you need to have a valid SSH key pair. You can generate an SSH key pair by running the ssh-keygen command on your local machine:

ssh-keygen -t rsa -b 4096

You will be prompted for a location to save your key file, and you will be asked for a password to protect the key file. After generating your key pair, you can use it to log into your remote machine by running the following command:

ssh user@remote_machine_name

scp and sftp

1. Use scp and sftp to copy files and directories

Both scp and sftp are commonly used to copy files and directories between computers. To use them, you first need to establish a connection between the two systems.

To copy a file using scp, use the following command:

scp [user@]server:/path/to/file client@server:destination/path

To copy a directory using scp, use the following command:

scp [user@]server:/path/to/dir client@server:destination/dir

Ifconfig

Ifconfig is a command line tool that allows you to configure various aspects of your Linux networking. With ifconfig, you can control the IP address, netmask, broadcast address, and default gateway for each network interface in your system. You can also set up IP masquerading and port forwarding.

Ifconfig is a very powerful tool, and it can be difficult to understand all of its options. This article will provide a brief overview of ifconfig concepts, and then later in the article we will provide examples of how to use ifconfig to configure your network settings.

The first step in using ifconfig is establishing an interface’s configuration. To do this, use the ifconfig command with the -a option:

ifconfig -a

This command will display all of the network interfaces in your system and their current configuration. The following table provides a quick summary of each column in this table:

Column Description Address The physical or IP address for the interface Netmask The subnet mask for the interface Broadcast Address The MAC address for the interface Gateway The IP address of the gateway device onlag Iflag A flag that controls how packets are forwarded over this interface lo Link-local address (used by some drivers only) mtu Maximum transmission unit prio Priority queueing scheduling algorithm rip RIPng routing information protocol vlan Virtual LAN identifier (802.1Q VLAN support) eth0 Ethernet adapter 1 ipv4 Primary IPv4 address ipv6 Primary

dig

1. dig
This network command can be used to troubleshoot networkissues and perform basic network diagnostics. Thecommand has the following syntax:dig domainname [mask]Thedomainname argument is the name of the domain or host you wish to query, while themask argument determines which subnetworks and hosts will be queried.

For example, to query all hosts in the 192.168.1.0/24 subnet, use:
dig 192.168.1.0/24

telnet

If you need to perform a quick Network Administration task, or just want to see what is happening on your network, you can use the Linux telnet command. Telnet is a simple yet powerful networking tool that allows you to log in to remote systems and view their status or logs.

To start telnet, type the following command:

telnet 192.168.1.101
The above command will open a prompt on your local machine and login to the system at IP address 192.168.1.101 as user “root”. If you don’t know the IP address of the target machine, simply type “ip addr” followed by the desired IP address into the terminal window and hit enter. Once logged in, you can use standard Linux commands such as ls, cat, grep, and more to administer your network!

nslookup

There are a number of Linux networking commands you can use to manage your network connection. Some of these include nslookup, hostname, ifconfig, and route.

nslookup is a powerful tool for managing DNS records on your system. You can use nslookup to lookup the IP address or domain name for any host in your network. You can also use nslookup to query DNS records for specific hostnames.

You can use the -type flag with nslookup to determine the type of record you are looking for. For example, you can use the -type flag to look up a IP address by using the following command:

nslookup -type=ipaddr myhostname

If you want to look up the domain name for a particular hostname, you can use the following command:

nslookup -type=domain myhostname

You can also use the -server flag with nslookup to specify a different DNS server than the default server. If you don’t specify a server, nslookup uses its own internal DNS server. The -port flag specifies which port nslookup should connect to when querying DNS servers. The default port number is 53.

Conclusion

In this article, we have summarized 14 useful Linux networking commands that can be of use when troubleshooting and administering a network. These commands include such essential utilities as ipconfig, netstat, nmap, and ifconfig. By understanding these tools and their various uses, you will be able to resolve most network issues with ease. So whether you are a novice or an experienced Linux user, these commands should prove to be helpful in your quest for mastery of the OS.

Logo