Linux Networking Commands
Overview
Linus Torvalds created Linux entirely from scratch. It is created as open-source software, which is inherently very strong and secure. Anyone can install Linux and modify it to create their own Linux version. These Linux versions are known as "distros" or "distributions."
The Linux kernel's unrivaled security and reliability, combined with its open-source nature, make it one of the most widely used software tools. Servers and software development both employ Linux. One or more Linux distributions are used by the majority of devices and embedded systems worldwide. Linux servers account for around 90% of all internet servers worldwide. Furthermore, the Linux kernel is used by approximately 80% of the world's smartphones. So, we also use Linux for various networking operations such as configuration and troubleshooting using various Linux networking commands.
Linux Networking Commands
Various Linux networking commands are used in networking for configuration and troubleshooting purposes. Some of the popular and essential commands are:
ifconfig
It is a network interface configuration command-line interface that is also used to initialize interfaces at system boot. Once a server is operational, it can be used to assign an IP address to an interface and enable or disable the interface as needed. The IP address, hardware MAC address, and MTU (Maximum Transmission Unit) size of the active interfaces are also displayed with this tool. Thus, ifconfig is helpful for system tuning or debugging.
Syntax
Example
Output
ip
The ip command is one of the fundamental commands that every administrator will need on a regular basis, from configuring new systems and assigning IP addresses to troubleshoot existing ones. The ip command can display address information, alter routing, and display network devices, interfaces, and tunnels. It is the replacement of the ifconfig command.
Syntax
You will get various options and objects by using the following commands.
Example
To display the IP addresses associated with a server interface, use the following:
Output
traceroute
Traceroute is a command-line utility that allows you to trace the whole path from your local system to another network system. It prints the number of hops (router IPs) traveled to reach the destination server. After the ping command, it is a simple network troubleshooting command.
Syntax
Note:- To install traceroute in your system, you can use the following command.
Example The following command will give you
- Size of the packets.
- The IP address
- The number of hops required.
- Hostname
Output
Tracepath
This command in Linux is similar to the traceroute command. It is employed in the detection of network delays. It does not, however, necessitate root access. This command also traces the path to the selected destination and recognizes each hop. If your network is weak, it detects the weak point.
Syntax
Example
Output
ping
Ping (Packet INternet Groper) is a Linux command that is typically used to verify network connectivity between two systems (Local Area Network (LAN) or Wide Area Network (WAN). It communicates with network nodes via ICMP (Internet Control Message Protocol).
Syntax
Example
To test the connectivity, we use
Output
netstat
It gives statistical data about various interfaces, such as open sockets, routing tables, and connection information.
Syntax
To install netstat, run the following command
Example To get details about ports, use the following command
Output
ss(Socket Statistics)
Socket Statistics (ss) is a robust command-line utility for investigating sockets. It dumps socket statistics and presents similar information to netstat. Furthermore, it displays more TCP and status information than other similar commands.
Syntax
- To display TCP/UDP or UNIX sockets, use the -t, -u, or -x options in the command. Each of them can be combined with "a" to display the connected and listening sockets.
- Combine it with "l" to see only the listening sockets of TCP/UDP or UNIX sockets.
Example
To get the list of all the TCP ports (sockets) open on a server.
Output
dig
The dig command in Linux stands for Domain Information Groper. In DNS lookup, this command is used to query the DNS name server. It is also used to debug DNS problems.
Syntax
Example
Output
nslookup
Another command used for DNS-related searches on Linux is nslookup. It is the earlier version of dig.
Syntax
Example
Output
route
A Linux system's IP routing table can be viewed or modified using the command-line tool route. It is primarily used to set up static routes via an interface to particular hosts or networks.
Syntax
Example
You can view the Kernel IP routing table by using the following command.
Output
host
This Linux command displays the domain name and IP address for a given hostname. It is also used to retrieve DNS lookup results for DNS-related queries.
Syntax
Example
Output
arp
The arp command in Linux stands for Address Resolution Protocol. It is used to see and modify the kernel's ARP table. Every system has a list of IP addresses and their related MAC addresses. The ARP Lookup table is the name given to this table. When a destination is requested to connect via IP address, your router will look in this table for the MAC address. The table will not be used if it is cached.
Syntax
Example
By default arp command gives the hostname, but we can use the command given below to get IP address.
Output
iwconfig
The wireless network interface is configured using the Linux iwconfig command. It is used to configure and view basic WI-FI settings such as SSID and encryption.
Syntax
hostname
The Linux commandhostnameis used to view and change a system's hostname.
Syntax
Example
To set the hostname, use the following command.
Note:- This command does not set a permanent hostname. When the computer reboots, it will be reset to the name in the hostname file.
curl or wget
The curl and wget commands in Linux are used to download files from the internet via the command line interface. To get the file, use the curl command with the option "O," whereas the wget command is used directly.
Syntax
- curl
Example
- wget
Example
mtr
The mtr command in Linux is a combination of ping and traceroute. It displays information about the packets sent as well as the ping time of each hop in real-time. It is also used to view network problems.
Syntax
Example
Output
whois
The whois command in Linux is used to retrieve all information about a website. You can obtain all the information about a website, including its registration and owner details.
Syntax
To install whois command, use the following command
Example
Output
ifplugstatus
The ifplugstatus command in Linux determines whether a cable is connected to a network interface. On Ubuntu, this command is not directly available.
To install ifplugstatus use the following command sudo apt-get install ifplugd Syntax
Example
Run the following command
If you get “link beat detected” then everything is working fine.
iftop
It is a network analyzing utility system administrators use to view bandwidth statistics. It displays a high-level summary of the networking operations on an interface. It is an abbreviation for Interface TOP, and the top is derived from the op command in Linux. It can even be used as a diagnostic tool to determine which program is causing the network problem.
Syntax
To install iftop, use the following command.
Example
To display bandwidth usage, use the following command.
Output
tcpdump
Among other Linux network commands, the tcpdump command is the most commonly used in network analysis. It gathers and shows network traffic as it passes via the network interface. Syntax
Example
To specify the protocol, use the command.
To specify the port number, use the following command.
ifup
The ifup command activates a network interface, making it ready for data transport and reception.
Syntax
ethtool
The ethtool is Linux command software that queries and changes network interface controller parameters and device drivers.
Syntax
To install ethtool, use the following command.
Example
nmcli
The nmcli is a simple, scriptable Linux command for reporting network status, managing network connections, and controlling the NetworkManager.
Syntax
Example To view all network devices, use the following command.
Output
nc
NC (NetCat), often known as the "Network Swiss Army knife," is a versatile command that can handle practically any operation using TCP, UDP, or UNIX-domain sockets. It can open TCP connections, listen on arbitrary TCP and UDP ports, and do port scanning, among other things. It can also be used as a rudimentary TCP proxy to test network daemons, see if remote ports are reachable, and much more.
Syntax
Example
Output
nmap
It can be used to learn more about a single host or to investigate a whole network. Nmap is also used for network audits, network security scans, port discovery on distant computers, and much more.
Syntax
To install nmap, use the following command.
Example
Output
Wireshark
Wireshark is a widespread, powerful, adaptable, and simple-to-use command for real-time packet capture and analysis on a packet-switched network. System administrators and network engineers use it to monitor and examine packets for security and troubleshooting.
Syntax
bmon
It collects networking statistics and displays them visually in a human-friendly style. It's a trustworthy and efficient real-time bandwidth monitor and rate estimator.
Syntax
Iptables
The IP packet filtering and NAT ruleset can be configured, maintained, and inspected using the Linux command iptables. It is employed to configure and oversee the Linux firewall (Netfilter). You can list already-existing packet filter rules, add, remove, or alter packet filter rules, and list individual rule counts.
Syntax
Where,
- -A is append
- -C is check
- -D is delete
Firewalld
Network/firewall zones, which specify the trust level of network connections or interfaces, are supported by Firewalld's dynamically managed firewall. Ethernet bridges, IP sets, IPv4, and IPv6 firewall configurations are all supported.
UFW firewall
On Linux distributions running Debian and Ubuntu, UFW is a well-liked and default firewall configuration tool. It is used to add, delete, alter, and reset packet filtering rules, among other things, as well as to enable or stop the system firewall.
Syntax
Example
To check firewall status, use the following command
Output
Conclusion
- Linus Torvalds created Linux entirely from scratch and it is the kernel of an operating system.
- The Linux kernel's unrivaled security and reliability, combined with its open-source nature, make it one of the most widely used operating systems.
- Linux servers account for around 90% of all internet servers worldwide. Furthermore, the Linux kernel is used by approximately 80% of the world's smartphones. So, we also use Linux for various networking operations.
- There are various Linux networking commands that network administrators use to configure and troubleshoot the network.
- Some of the popular Linux networking commands are:
- ping
- ip
- ifconfig
- nslookup
- mtr
- route
- iftop