Useful network command for Linux

Vineet Kumar
2 min readMar 12, 2020

--

  1. nc (netcat) command: used for port scanning, port redirection, as a port listener
    $ nc -v -w 2 z <ip-address> 22 #scan a single port
    $ nc -v -w 2 z <ip-address> 22 80 #scan multiple ports
    $ nc -v -w 2 z <ip-address> 20–25 #scan range of ports
  2. nmap command: Nmap is used for exploring networks, perform security scans, network audit and finding open ports on remote machine
    The Nmap tool offers various methods to scan a system. In this example, I am performing a scan using hostname to find out all open ports, services
    and MAC address on the system
    # nmap [Scan Type(s)] [Options] {target specification}
    # yum install nmap [on Red Hat based systems]
    $ sudo apt-get install nmap [on Debian based systems]
    with “-v” option is giving more detailed information about the remote machine.
    nmap <hostname or IP>
    nmap -v <IP>
    You can scan multiple hosts by simply writing their IP addresses or hostnames with Nmap.
    nmap <IP1><IP2>
    nmap -sU <IP> : find UPD services
  3. Netstat Command: Netstat command allows you a simple way to review each of your network connections and open sockets.Package for netstat command
    # yum install net-tools [On CentOS/RHEL]
    # apt install net-tools [On Debian/Ubuntu]
    -s argument will show you overall stats where you can pay attention to packets discarded messages.
    netstat -s : show you overall stats where you can pay attention to packets discarded messages.
    netstat -tnlp : tcp port info
    netstat -unlp: upd posts info
    netstat -anlp: all ports using by services
    An excellent option when troubleshooting services crash related issues. Let’s say an application is crashing randomly every few minutes. But, not sure when exactly. You can use -c argument which will continuously show the results.
    netstat -anlpc |grep 8080
    netstat -r :
    connectivity is not working as expected due to connection is traveling through a different route?
  4. nslookup: nslookup is a program to query Internet domain name servers.
    nslookup <domain-name>
  5. dig (Domain Information Groper): is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name servers.
    dig <domain name>

--

--

No responses yet