Home Learn Linux 15 basic Linux networking commands you should know

15 basic Linux networking commands you should know

by Karen
basic networking commands

Whether you are a system administrator or a person who uses Linux as the daily drive operating system, you might encounter network issues once in a while. Even if you can do some configurations from the Settings window, command-line tools are more powerful and have more features. You can use these tools to easily configure, monitor, secure, and manage networks.

15 basic Linux networking commands

This post will guide you on the 15 basic Linux commands every Linux user should know.

1. The Ifconfig command

Whether you have used Linux systems for several years or are just getting started, you must have come across the ifconfig command. It is a simple but powerful command-line utility that you can use to manage and configure your network interfaces. You can use it to view IP addresses, turn ON or OFF any network interface, view MAC addresses and Maximum Transmission Units (MTU)

To get started with ifconfig, execute the command below on your Terminal.

ifconfig -a

That should list all the network interfaces on your system, including their assigned IPs, MAC, status, etc. A network interface’s status can either be UP or DOWN. Use the syntax below to set any interface up or down.

ifconfig command

ifconfig command

sudo ifconfig [interface-name] up
sudo ifconfig [interface-name] down
e.g
//To turn off the loopback interface (lo)
sudo ifconfig lo down

Note: Unfortunately, the ifconfig command is deprecated and doesn’t come pre-installed on newer Linux distribution releases. The IP command replaced it.

Execute any of the commands below to install ifconfig, depending on your distribution.

  • Debian/ Ubuntu
    sudo apt install net-tools
  • RHEL/ CentOS/ Fedora
    sudo yum install net-tools

2. The ip command

The IP command is the latest and the default networking command available in most (if not all) Linux systems. It has replaced the ifconfig and route commands, and it comes with additional features like setting default and static routes, configuring IP addresses, and much more. The most popular IP commands are IP link, IP address, and IP route.

  • IP link

The ip link is a command used for adding, configuring, and deleting network interfaces.
To display all network interfaces, we will type the following command.

ip link show
  • IP address

The IP address command is used to show addresses, bind new addresses, or delete old ones. For example, We will type this command to view the IP address assigned to the network interface wlan0.

ip address show dev wlan0
  • IP route

If you want to have a detailed look at the routing table, use the IP route command. Just execute the command below.

ip route show

3. Nmap command

Nmap (Network Mapper) command is a free, open-source, and robust network tool widely used by network administrators, cyber security experts, and system administrators for various purposes. These include:

  • Determining the number of live nodes/ hosts on a network. Therefore, you can use it to know the devices connected to a network
  • Showing the OS and services running on a given device/host.
  • Scanning for open ports on a device on the network.

Nmap doesn’t come pre-installed on most Linux distributions other than those focusing on security (e.g., Kali Linux, Parrot, etc.) To install NMAP execute the commands below depending on your system.

  • Debian/ Ubuntu
    sudo apt install nmap
  • RHEL/ CentOS/ Fedora
    sudo yum install nmap

4. The traceroute command

The traceroute command is a networking command used for troubleshooting a network. This command finds the delay and the pathway to the destination. This command does not come pre-installed in most Linux distributions. To install it, use the followings command.

  • Debian/ Ubuntu
    sudo apt-get install inetutils-traceroute

To get started with the traceroute command, use the syntax below.

traceroute <destination address> 
e.g.
traceroute 192.168.1.63

Here, the ‘destination address’ is the IP address of the device/ host that you want to troubleshoot.

5. Ping command

The Ping command stands for Packet Internet Groper. If you have just finished configuring your network and want to know whether Device A can communicate to Device B, this is the command to use. You can use the Ping command to check whether a device is online and determine the response time. For instance, once we ping any host in a network and get a response, we conclude that the device is reachable and online. However, if we don’t get a response, we suppose the host is not up or blocked by a firewall.

The syntax for this command is :

ping <destination>
e.g.
ping 192.168.1.63

6. The iwconfig command

iwconfig command is a Linux command used to configure the wireless network interface. It is slightly similar to the ifconfig command (as you can see in the name) but dedicated to wireless networks (WIFI). Therefore, you cannot use iwconfig to configure your ethernet interface. Some of the configurations that you can do with the iwconfig command include:

  • Changing the interface name
  • Show and switch frequencies
  • Show and change SSID
  • Enable and disable monitor/ managed mode. Ethical hackers mainly use this feature to capture packets sent over a network.

To use this command, type the following:

iwconfig

7. Netstat command

The netstat (Network Statistics) is commonly used to print network connections, routing tables, and interface statistics. You can also use Netstat to display the status of TCP and UDP endpoints in a table format. This command can display different types of network data depending on the command selected.

netstat -h

This command shows the list of all available options.

8. Telnet command

Telnet command utilizes Telnet protocol to communicate with the host on a LAN or internet. You can use telnet to manage and configure devices over a network like with SSH. One area that greatly uses the telnet command is SDN (Software Defined Networking).

Telnet uses TCP port 23. To install this tool in Linux, use the command below.

  • Debian/ Ubuntu
    sudo apt install telnetd
  • RHEL, CentOS, Fedora
    sudo yum install telnet telnet-server

To get started with telnet, use the syntax below.

telnet [host-ip]e.g.
telnet 192.168.1.63

Type the username of the remote device, and it will prompt you for the password. After successful login, you can proceed to execute commands on the remote machine. 

9. Hostname command

The hostname command is a networking command used to identify the operating system’s hostname. You can also use it to perform several network configurations, including;

  • Obtain DNS information
  • Set hostname
  • Check the IP address assigned to your system

This command comes quite handy when setting up an active directory on your system. Below are some popular hostname command options.

  • Display your computer’s hostname.
    hostname
  • Display the domain name
    hostname -d
    hostname --domain
  • Display the IP address
    hostname -I
  • Display the Full Qualified Domain Name (FQDN)
    hostname -f
    hostname --fqdn

10. The ifplugstatus command

This command checks whether the cable is plugged into a network.
To install this utility, type the command below.

sudo apt-get install ifplugd

To use this command, use the command below.

ifplugstatus

11. The Mtr command

The mtr command is a networking tool used for diagnosing and troubleshooting network problems. The mtr command combines traceroute and ping commands. To install this command in your Linux system, use the following commands.

  • Debian, Ubuntu
    sudo apt install mtr
  • RHEL, CentOS, Fedora
    sudo yum install mtr
    or,
    sudo dnf install mtr

Let’s look at a few examples of the mtr command.

  • Display traceroute report: To get a traceroute report of a remote host, we will execute the mtr command and the IP/ domain of the target host without any additional arguments.
    mtr 192.168.1.63
  • Display JSON, CSV or XML. Unlike the ping or traceroute commands, mtr allows you to set the output format of the scan report. Use the syntax below.
    mtr --[output-format] [target]e.g.
    mtr --xml example.com
    mtr --json example.com
    mtr --csv example.com
  • Set the maximum number of pings using the -c argument. 
    mtr -c 10 example.
    Here, we are only sending ten ping commands to the remote host.

12. The dig command

The dig command stands for Domain Information Groper. Its primary purpose is to query and retrieve information from the Domain Name System, and it’s also used for verifying and troubleshooting DNS problems. Some of the most common DNS records are A, MX, and SIG records.

  • A record: This record maps a hostname to an IP address. It links a domain name and the IP address webserver. For example, you have registered the domain name on GoDaddy, but the server is hosted separately on AWS.
  • MX record: This record specifies the server responsible for handling the emails in place of the domain name. 

To install the dig command on your system, use the commands below.

  • Debian/ Ubuntu
    sudo apt install dnsutils
  • RHEL, CentOS, Fedora
    sudo yum install bind-utils

The default syntax for the dig command is:

dig [server] [name] [type]e.g.
dig example.com
dif mx example.com

13. The ss command

The ss (Socket Statistics)command is an impressive command-line utility used to examine sockets. It displays attachment measurements and showcases data like netstat. The default syntax is:

ss <options>

Let’s look at some of the popular ss commands.

  • List all connections (both listening and non-listening)
    ss -a
  • List only the listening connections
    ss -l
  • List only TCP connections
    ss -t
    or, ss --tcp

14. The Tcpdump command

Tcpdumd command is a powerful and broadly utilized command-line network sniffer. This command captures and analyzes TCP/IP packets transmitted or received over a network on a specific interface.

To install tcpdump on your system, execute the commands below.

  • Debian / Ubuntu
    sudo apt install tcpdump
  • RHEL, CentOS, Fedora
    sudo yum install tcpdump
  • OpenSUSE
    sudo zypper install tcpdump

Let’s look at some tcpdump commands that you can use.

  • Capture packets on a specific network interface.
    tcpdump -i [interface-name}
    e.g.
    tcpdump -i wlan0
  • Capture a specific number of packets
    tcpdump -c [number-of-packets]e.g.
    tcpdump -c 100 -i wlan0

15. The NSLookup command

Nslookup (Name Server Lookup) command is a powerful command-line utility used to carry out DNS servers’ queries and troubleshoot any DNS issues. The basic syntax for nslookup is:

nslookup [options]
  • Get the A record of a domain name
    nslookup google.com
  • Perform a reverse DNS lookup
    nslookup 192.168.1.63
  • Lookup any DNS records
    nslookup -type=any example.com

Conclusion

This post has given you 15 basic networking commands that you should know. They are useful to both network admins and regular users who want to configure or troubleshoot network issues on their systems. Is there any command you feel we should have included in the list? Please let us know in the comments below.

You may also like

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.