Linux: Mastering Linux Network Commands

linux logo

Your Comprehensive Guide to Network Commands.

In the world of Linux, an essential set of tools empowers users and administrators to interact with the vast and intricate realm of computer networks. Whether you’re troubleshooting connectivity issues, securing your network, or exploring its depths, Linux network commands offer a treasure trove of utilities for all your networking needs.

Checking Network Status

Understanding the current state of your network is the first step in any troubleshooting or management task. Key commands for network status include:

  • ifconfig: Display network interface configuration details.
  • ip: A versatile command for network configuration and status.
  • netstat: Show network statistics and active connections.

Diagnosing Connectivity

When network issues arise, Linux provides a toolkit of diagnostic commands to identify and resolve problems. Some of these include:

  • ping: Test connectivity to a remote host or IP address.
  • traceroute: Trace the route to a remote host, revealing the network path taken.
  • nc: A versatile tool for network connection testing and data transfer.

Analyzing Network Traffic

For in-depth analysis of network traffic, these commands are indispensable:

  • tcpdump: Capture and analyze network packets.
  • wireshark: A graphical tool for packet analysis.
  • iftop: Monitor network bandwidth usage by interface.

Securing the Network

Network security is paramount, and Linux offers several commands to bolster your defenses:

  • iptables: A powerful firewall tool for configuring packet filtering and network address translation.
  • ufw: Uncomplicated Firewall simplifies the management of iptables rules.
  • sshd: Secure Shell daemon configuration for remote access security.

Managing Network Services

Linux network commands can help you start, stop, and manage network services:

  • systemctl: Control system services, including network-related ones.
  • netcat: A versatile networking utility for data transfer and port scanning.

File Transfer over the Network

When it comes to moving files across a network, scp (Secure Copy Protocol) is a secure and efficient tool for the job:

scp localfile.txt username@remote_server:/path/to/destination/

The Network Manager

The commands can be used to start, stop, and restart the Network Manager service. 

  • Start Network Manager:
sudo service network-manager start
  • Stop Network Manager:
sudo service network-manager stop
  • Restart Network Manager:
sudo service network-manager restart
  • To Check the Network Manager Status:
sudo service network-manager status
Start, Stop, or Restart Network Manager Service with systemctl:

You can also use the systemctl command to start, stop, or restart the Network Manager service. The following commands demonstrate how to control the service:

  • Start Network Manager:
sudo systemctl start NetworkManager
  • Stop Network Manager:
sudo systemctl stop NetworkManager
  • Restart Network Manager:
sudo systemctl restart NetworkManager

These commands provide more control over the service state.

Enable or Disable Network Manager Service at Boot:

To ensure that Network Manager starts automatically at boot, use the systemctl command to enable it:

sudo systemctl enable NetworkManager

To disable automatic startup:

sudo systemctl disable NetworkManager
Check the Status of Network Manager:

You can check the status of the Network Manager service to verify whether it is active, inactive, or if there are any issues. Use the following command:

sudo systemctl status NetworkManager

This command displays detailed information about the service’s current status, including logs and error messages.

Reload Network Manager Configuration:

In some cases, you might need to reload the Network Manager configuration without fully restarting the service. You can do this using the following command:

sudo systemctl reload NetworkManager

This command refreshes the configuration and applies any changes without interrupting the service.

These commands allow you to manage the Network Manager service in Linux, ensuring that it functions as expected and applies any network configuration changes effectively. Depending on your distribution and preferences, you can choose the appropriate command for controlling the Network Manager service.

The Network Interface Card (NIC)

Controlling the status of network interfaces, including starting, stopping, and restarting NICs, is vital for network management. Linux provides a few commands to manage the state of NICs:

  • Starting a NIC: To activate a network interface, use the ifconfig or ip command with the “up” option. Replace interface_name with the actual name of the NIC (e.g., eth0):
sudo ifconfig interface_name up


sudo ip link set dev interface_name up
  • Stopping a NIC: To deactivate a NIC, use the ifconfig or ip command with the “down” option:
sudo ifconfig interface_name down


sudo ip link set dev interface_name down
  • Restarting a NIC: You can restart a NIC by first stopping it and then starting it again. Here’s how to do it:
sudo ifconfig interface_name down
sudo ifconfig interface_name up


sudo ip link set dev interface_name down
sudo ip link set dev interface_name up

By starting, stopping, and restarting NICs, you can troubleshoot network connectivity issues, apply configuration changes, or reset the network interface as needed.

Configuring Network Interface Cards (NICs)

In Linux, Network Interface Cards (NICs) are the hardware components responsible for network communication. Proper configuration of NICs is essential for managing network connectivity. Here are some commands and techniques to work with NICs:

  • List available NICs: To view the NICs present in your system, you can use the ifconfig or ip link command. This will display a list of network interfaces, such as eth0, eth1, wlan0, etc.

  • Modify NIC settings: The ifconfig and ip commands can also be used to configure NIC settings, such as setting IP addresses, netmasks, and enabling or disabling interfaces.

  • Change NIC parameters: The ethtool command allows you to change and view NIC parameters like speed, duplex mode, and more. For example, to set the speed of an interface to 1000 Mbps (1 Gbps), you can use:
sudo ethtool -s interface_name speed 1000
  • Set up bonding: Network bonding, also known as NIC teaming, allows you to combine multiple NICs into a single logical interface for redundancy and load balancing. The ifenslave tool, along with configuration files, is commonly used to set up bonding.

  • View NIC information: The lshw or lspci command can provide detailed information about your NICs, including their make and model, which can be helpful when troubleshooting or identifying hardware.

  • Use udev rules: You can configure custom udev rules to ensure NICs have consistent names across reboots or in specific circumstances. This is particularly useful in environments with dynamic hardware changes.

Working with NICs in Linux is a crucial part of network administration, especially when it comes to optimizing network performance and ensuring reliable connectivity. It allows you to fine-tune and manage your network hardware to suit your specific needs.


Netstat is a versatile command-line utility in Linux used for displaying network-related information. It provides valuable insights into network connections, routing tables, interface statistics, masquerade connections, and more. Here’s an in-depth explanation of using netstat and its common command-line arguments:

Understanding netstat and Its Functions

netstat stands for “network statistics” and is primarily used for querying network information. Its basic syntax is:

netstat [options]

The common options and their functions include:

  • -a (or --all): Display all sockets, including listening and non-listening connections. This is particularly useful for a comprehensive view of network activity.

  • -t (or --tcp): Show only TCP connections. This option narrows down the displayed information to TCP protocol-related data.

  • -u (or --udp): Display only UDP connections. Similar to the -t option, this focuses on UDP protocol-related information.

  • -n (or --numeric): Show numerical addresses instead of resolving hostnames. This can speed up the output generation and is useful when you don’t need to resolve IP addresses to hostnames.

  • -l (or --listening): Display only listening sockets. This is helpful when you want to see which services are actively listening for incoming connections.

  • -p (or --programs): Show the process that owns each socket. This is particularly useful for identifying which program or service is associated with a specific network connection.

  • -r (or --route): Display the kernel routing table. This provides information about how packets are routed within your network.

  • -s (or --statistics): Show network statistics. This option provides a summary of network-related statistics, including protocols, error counts, and more.

  • -c (or --continuous): Continuously display network information, updating the data in real-time. This is useful for monitoring network activity as it occurs.

Common Usage Examples:

Here are some common use cases of netstat along with their corresponding command-line options:

  • List all listening TCP ports:
netstat -tuln
  • Show all network statistics:
netstat -s
  • Display the routing table:
netstat -r
  • Show all listening and non-listening sockets, including process details:
netstat -ap
  • Monitor network connections in real-time:
netstat -c
Advanced Usage and Additional Options

The examples provided cover the most common use cases of netstat, but the utility offers a wide range of additional options and capabilities. These advanced options can be valuable for specific troubleshooting, analysis, and network management tasks.

To explore these advanced options and gain a deeper understanding of netstat, you can refer to the command’s manual page by using:

man netstat

Working with DNS

DNS (Domain Name System) settings are important for ensuring that your Linux system can resolve domain names to IP addresses correctly. Here are some commands and techniques for checking DNS settings in Linux:

Check DNS Configuration:

To check your system’s DNS configuration, you can view the contents of the /etc/resolv.conf file, which contains the DNS server information. Use a text editor or a command like cat to display the file:

cat /etc/resolv.conf

This file typically includes lines like nameserver IP_address, where IP_address is the DNS server your system is configured to use.

Query DNS Servers:

You can use the nslookup or dig command to query DNS servers for specific domain name information. For example, to query the DNS server for the IP address of a domain, use nslookup:


Or with dig:


These commands provide detailed DNS information, including the IP address of the queried domain and details about the DNS server that responded.

Test DNS Resolution:

You can test DNS resolution by using the ping command to check if your system can resolve and reach a specific domain. For example:


If you receive successful replies, it means DNS resolution is working for that domain. If not, you might have DNS configuration or network issues.

Query Specific DNS Servers:

You can use the nslookup or dig commands to query specific DNS servers. This can help troubleshoot DNS issues related to a specific DNS server. For example:


This queries Google’s public DNS server ( for the IP address of

Check DNS Cache:

Linux systems often have a local DNS cache to speed up repeated DNS queries. To view and clear the DNS cache, you can use the systemctl command. For example, to view the status:

sudo systemctl status systemd-resolved

To flush the cache:

sudo systemctl restart systemd-resolved

This command restarts the systemd-resolved service, effectively clearing the DNS cache.

Configure DNS Servers:

If you need to configure DNS servers, you can edit the /etc/resolv.conf file. For example:

sudo nano /etc/resolv.conf

Add or modify nameserver lines with the IP addresses of the DNS servers you want to use.

These commands and techniques help you check and configure DNS settings in Linux, ensuring proper DNS resolution and network connectivity. DNS issues can impact your ability to access websites and services, so it’s essential to keep your DNS settings in check.


Whether you’re a seasoned network administrator or a Linux enthusiast, mastering network commands is crucial for effective network management and troubleshooting. These tools enable you to monitor, diagnose, secure, and manage your network infrastructure with confidence.

With a comprehensive understanding of Linux network commands, you’ll be equipped to navigate the intricate world of computer networks, ensuring connectivity and security across your systems. Dive in, explore, and unlock the full potential of Linux networking.

That’s All Folks!

You can find all of our Linux guides here: Linux Guides

Luke Barber

Hello, fellow tech enthusiasts! I'm Luke, a passionate learner and explorer in the vast realms of technology. Welcome to my digital space where I share the insights and adventures gained from my journey into the fascinating worlds of Arduino, Python, Linux, Ethical Hacking, and beyond. Armed with qualifications including CompTIA A+, Sec+, Cisco CCNA, Unix/Linux and Bash Shell Scripting, JavaScript Application Programming, Python Programming and Ethical Hacking, I thrive in the ever-evolving landscape of coding, computers, and networks. As a tech enthusiast, I'm on a mission to simplify the complexities of technology through my blogs, offering a glimpse into the marvels of Arduino, Python, Linux, and Ethical Hacking techniques. Whether you're a fellow coder or a curious mind, I invite you to join me on this journey of continuous learning and discovery.

Leave a Reply

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

Verified by MonsterInsights