Linux Networking Commands
Linux Networking Commands
Sysadmin
Aaron KiliLast Updated: July 13, 2023 Read Time: 17 minsCategoriesLinux Commands, Networking Commands 10
Comments
885.9K
In this article, we will review some of the most used command-line tools and
utilities for network management in Linux, under different categories. We will
explain some common usage examples, which will make network management
much easier in Linux.
On this page
• ifconfig Command
• ip Command
• ifup Command
• ethtool Command
• ping Command
• traceroute Command
• mtr Command
• route Command
• nmcli Command
• netstat Command
• ss Command
• nc Command
• nmap Command
• host Command
• dig Command
• nslookup Command
• tcpdump Command
• Wireshark Utility
• bmon Tool
• iptables Firewall
• firewalld
• UFW Firewall
This list is equally useful to full-time Linux network engineers.
1. ifconfig Command
It is also used to view the IP Address, Hardware / MAC address, as well as MTU
(Maximum Transmission Unit) size of the currently active interfaces. ifconfig is
thus useful for debugging or performing system tuning.
$ ifconfig
collisions:0 txqueuelen:1000
collisions:0 txqueuelen:1
To list all interfaces which are currently available, whether up or down, use the -
a flag.
$ ifconfig -a
2. IP Command
The following command will show the IP address and other information about a
network interface.
$ ip addr show
3: wlp2s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default
qlen 1000
...
$ ip neigh
192.168.0.1 dev enp1s0 lladdr 10:fe:ed:3d:f3:82 REACHABLE
ifquery command used to parse the network interface configuration, enabling you
to receive answers to query about how it is currently configured.
4. Ethtool Command
100baseT/Half 100baseT/Full
1000baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Speed: 1000Mb/s
Duplex: Full
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
5. Ping Command
ping (Packet INternet Groper) is a utility normally used for testing connectivity
between two systems on a network (Local Area Network (LAN) or Wide Area
Network (WAN)). It uses ICMP (Internet Control Message Protocol) to
communicate to nodes on a network.
$ ping 192.168.0.103
^C
--- 192.168.0.103 ping statistics ---
$ ping -c 4 192.168.0.103
6. Traceroute Command
Traceroute is a command-line utility for tracing the full path from your local
system to another network system. It prints a number of hops (router IPs) in that
path you travel to reach the end server. It is an easy-to-use network
troubleshooting utility after the ping command.
In this example, we are tracing the route packets take from the local system to
one of Google’s servers with IP address 216.58.204.46.
$ traceroute 216.58.204.46
3 * * *
$ mtr google.com
OR
$ mtr 216.58.223.78
Sample Output
You can limit the number of pings to a specific value and exit mtr after those
pings, using the -c flag as shown.
$ mtr -c 4 google.com
8. Route Command
$ route
There are numerous commands you can use to configure routing. Here are some
useful ones:
To view the kernel routing table, use the -r flag (which is equivalent to running
the route command above).
$ netstat -r
11. ss Command
The following example shows how to list all TCP ports (sockets) that are open on
a server.
$ ss -ta
LISTEN 0 100
*:submission *:*
LISTEN 0 128
127.0.0.1:fmpro-internal
*:*
LISTEN 0 100
*:pop3 *:*
LISTEN 0 100
*:imap *:*
LISTEN 0 128
*:sunrpc *:*
LISTEN 0 100
*:urd *:*
LISTEN 0 128
*:domain *:*
LISTEN 0 9
*:ftp *:*
LISTEN 0 128
*:ssh *:*
LISTEN 0 128
127.0.0.1:ipp
*:*
LISTEN 0 100
*:smtp *:*
LISTEN 0 128
*:8090 *:*
LISTEN 0 100
*:imaps *:*
LISTEN 0 100
*:pop3s *:*
ESTAB 0 0
192.168.0.104:ssh
192.168.0.103:36398
ESTAB 0 0
127.0.0.1:34642
127.0.0.1:opsession-prxy
ESTAB 0 0
127.0.0.1:34638
127.0.0.1:opsession-prxy
ESTAB 0 0
127.0.0.1:34644
127.0.0.1:opsession-prxy
ESTAB 0 0
127.0.0.1:34640
127.0.0.1:opsession-prxy
LISTEN 0 80
:::mysql
:::*
...
To display all active TCP connections together with their timers, run the following
command.
$ ss -to
12. NC Command
You can also use it as a simple TCP proxy, for network daemon testing, to check
if remote ports are reachable, and much more. Furthermore, you can
employ nc together with pv command to transfer files between two computers.
Nmap (Network Mapper) is a powerful and extremely versatile tool for Linux
system/network administrators. It is used to gather information about a single
host or explores networks an entire network. Nmap is also used to perform
security scans, network audits and finding open ports on remote hosts and so
much more.
You can scan a host using its hostname or IP address, for instance.
$ nmap google.com
$ nmap 192.168.0.103
host command is a simple utility for carrying out DNS lookups, it translates
hostnames to IP addresses and vice versa.
$ host google.com
dig (domain information groper) is also another simple DNS lookup utility, that is
used to query DNS related information such as A Record, CNAME, MX Record
etc, for example:
$ dig google.com
;; Got answer:
;; OPT PSEUDOSECTION:
;; QUESTION SECTION:
;google.com. IN A
;; ANSWER SECTION:
google.com. 72 IN A 172.217.166.78
;; AUTHORITY SECTION:
;; ADDITIONAL SECTION:
;; SERVER: 192.168.0.1#53(192.168.0.1)
$ nslookup google.com
Server: 192.168.0.1
Address: 192.168.0.1#53
Non-authoritative answer:
Name: google.com
Address: 172.217.166.78
$ nslookup 216.58.208.174
Server: 192.168.0.1
Address: 192.168.0.1#53
Non-authoritative answer:
$ tcpdump -i eth1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
To capture a specific number of packets, use the -c option to enter the desired
number.
$ tcpdump -c 5 -i eth1
You can also capture and save packets to a file for later analysis, use the -w flag
to specify the output file.
Wireshark is a popular, powerful, versatile, and easy-to-use tool for capturing and
analyzing packets in a packet-switched network, in real-time.
You can also save data it has captured to a file for later inspection. It is used by
system administrators and network engineers to monitor and inspect the packets
for security and troubleshooting purposes.
Monitor Local Network Traffic
You can learn how to use Iptables for various purposes from our simple yet
comprehensive guides.
If the UFW firewall is not active, you can activate or enable it using the following
command.
Read our article How to Setup UFW Firewall on Ubuntu and Debian.
If you want to find more information about a particular program, you can consult
its man pages as shown.
$ man programs_name
That’s all for now! In this comprehensive guide, we reviewed some of the most
used command-line tools and utilities for network management in Linux, under
different categories, for system administrators, and equally useful to full-time
network administrators/engineers.