Net-tools installation

netstat is a command line network utility that shows network connections for the Transmission Control Protocol (both incoming and outgoing), routing tables and a series of network interfaces (network interface controller or interface software defined network) and network protocol statistics. It is available on Unix-like operating systems, including macOS, Linux, Solaris and BSD, and is available on IBM OS / 2 and on Microsoft Windows NT-based operating systems, including Windows XP, Windows Vista, Windows 7, Windows 8 and Windows 10.

Netstat, derived from the words network and statistics and is a command line utility used by system administrators to analyze network statistics. Show a whole set of statistics such as open ports and corresponding addresses on the host system, routing table and more.

The package that contains netstat is called net-tools. In modern systems the netstat utility is preinstalled and it is not necessary to install it in the case of not installing the minimum version of the Linux system, in the case of installing the minimum version of the system we may not be able to execute the netstat command because it is not  installed in our system.

On older systems you are likely to encounter some error when executing the netstat command. One way to correct this error is to reinstall the net-tools.

To install the net-tools and to be able to execute the netstat command on our system we execute the following command to install the tool.

CentOS/RHEL
# yum install net-tools

Debian/Ubuntu
# apt install net-tools   

OpenSuse
# zypper install net-tools

Arch Linux
# pacman -S netstat-nat

We can check the version of netstat installed in our system with the following command.

# netstat -v

We can display the help information of the tool with the command (help)

# netstat help

[root@serv23 ~]# netstat help
usage: netstat [-vWeenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}
netstat [-vWnNcaeol] [<Socket> ...]
netstat { [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]
-r, --route              display routing table
-I, --interfaces=<Iface> display interface table for <Iface>
-i, --interfaces         display interface table
-g, --groups             display multicast group memberships
-s, --statistics         display networking statistics (like SNMP)
-M, --masquerade         display masqueraded connection
-v, --verbose            be verbose
-W, --wide               don't truncate IP addresses
-n, --numeric            don't resolve names
--numeric-hosts          don't resolve host names
--numeric-ports          don't resolve port names
--numeric-users          don't resolve user names
-N, --symbolic           resolve hardware names
-e, --extend             display other/more information
-p, --programs           display PID/Program name for sockets
-o, --timers             display timers
-c, --continuous         continuous listing
-l, --listening          display listening server sockets
-a, --all                display all sockets (default: connected)
-F, --fib                display Forwarding Information Base (default)
-C, --cache              display routing cache instead of FIB
-Z, --context            display SELinux security context for sockets
<Socket>={-t|--tcp} {-u|--udp} {-U|--udplite} {-S|--sctp} {-w|--raw}
{-x|--unix} --ax25 --ipx --netrom
<AF>=Use '-6|-4' or '-A <af>' or '--<af>'; default: inet
List of possible address families (which support routing):
inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
x25 (CCITT X.25)

Some examples of the execution of the netstat command

1.Tabla de enrutamiento de red

Using the [-r] parameter it will show us information related to the routing of our network and [-n] displays information related to the active connections tcp protocol.

[root@serv ~]# netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.254   0.0.0.0         UG        0 0          0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0

Using the parameter [-i] we can obtain information about the configuration of our network and with the option [-a] it prints all the interfaces present.

2. Interfaz de red

[root@serv23 ~]# netstat -ai
Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0             1500   161831      0      6 0         43092      0      0      0 BMRU
lo              65536      240      0      0 0           240      0      0      0 LRU

Was this answer helpful?

Related Articles

Commandos Basicos Linux

Información del sistema arch: mostrar la arquitectura de la máquina (1). uname -m: mostrar la...