Skip to main content

Network Connection verification and Troubleshooting commands in Linux


There are several commands which can help to diagnose the computer networking in Linux.

  • ifconfig Command

Interface configuration(ifconfig) is a command-line interface tool used for configuring, controlling and querying TCP/IP network interface parameters.It is used to initialize an interface, set the IP address and netmask of a network interface and enabling or disabling an interface on demand. 

This command is mainly used to know the IP address and MAC address assigned to an interface.




-->ifconfig command with no arguments will display will display all network interfaces currently in operation.

$ifconfig -a 

It will display all available details of the system irrespective of status.It doesn't bother whether the interface is inactive or active. 




$ifconfig eth0

It will show the configuration of a specific interface i.e. it will display the configuration of eth0 only.


We can change the status of a specific network interface from active to inactive, or vice-versa.Only a superuser can enable or disable an interface.So we need to be logged in as root or prefix the command with sudo

To disable an active network interface, enter ifconfig with the interface name followed by the down keyword.

$ sudo ifconfig eth0 down

Similarly to enable an inactive network interface, enter ifconfig with the interface name followed by the up keyword.

$sudo ifconfig eth0 up


It can also be used to assign IP address and Gateway to an interface.To assign a static IP address and the network mask to an interface, specify the interface name, IP address, and network mask. 

This command also requires superuser privileges.


$sudo ifconfig eth0 192.168.10.12 netmask 255.255.255.0 

  • PING Command
The PING command is used to test the connection and latency between two network connections(i.e. nodes).These connections can be either in a local area network(LAN) or a wide area network(WAN).PING uses ICMP(Internet Control Message Protocol).It sends ICMP ECHO_REQUEST packets to network hosts.

$ping 192.168.10.1 

In Linux ping command keep executing until we forcefully stop by interrupting it with the Ctrl+C keystroke.Ping with -c option exit after N number of requests.

$ping -c 7 www.google.com

  • TRACEROUTE Command
The Internet is a large and complex aggregation of network hardware connected together by gateways.

It is a network troubleshooting utility which shows the path to the destination and the number of hops taken to reach the destination.It utilizes the IP protocol "time to live" field and attempts to elicit ICMP TIME_EXCEEDED response from each gateway along the path to some host.

$traceroute 192.168.10.12

  • NETSTAT Command
It is a  command line TCP/IP networking utility for monitoring network connections both incoming and outgoing.It displays various network related information such as network connections, routing tables, interface statistics, masquerade connections, multicast memberships etc.

$netstat -a

It lists out all the current connections.

To list out only tcp connections use the t option

$netstat -at

To list out only udp connections use u option

$netstat -au

To list out all listening connections

$netstat -l

To display routing table information

$netstat -r 

  • ARP Command
ARP stands for Address Resolution Protocol.It is one of the major protocol in TCP/IP suit. This protocol is used to match IP addresses(32-bit Ethernet address) to MAC addresses(48-bit Hardware address).

To view the ARP cache table

$arp -a

To delete manually an entry from ARP cache

$arp -d ip-address


  • NSLOOKUP Command
It is a command-line tool for querying the Domain Name System(DNS) to obtain domain name or IP address mapping or for other specific DNS records. 

$nslookup www.fb.com

  • DIG Command
We can use dig command to query DNS lookup related task.It is used to query information like A Record, CNAME, MX Record etc.

$dig www.google.com



  • Route Command

It is used to show and manipulate the IP routing table.

There are multiple paths available to communicate over a network.This information is dynamically provided by routers.We can have a specific path to communicate by configuring it manually.

To show the routing table

$route -n

To add a new route

$route add -net<network_address>gw<gateway><interface_name>

Similarly to delete, use del in place of add



Comments

Popular posts from this blog

Configuring 2 backend servers and a load balancer with HAProxy

A load balancer is a device that distributes the traffic across a cluster of servers. In computing, load balancing improves the distribution of workloads across multiple computing resources, such as computers, a computer cluster, network links, central processing units, or disk drives.As a result, it improves responsiveness and increases the availability of applications.  For load balancing, we need to install LAMP server on backend servers and HAProxy on the load balancer. HAProxy is a free, open source software that provides a high availability load balancer and proxy server for TCP and HTTP based applications that spread requests across multiple servers. Here we will make two backend servers and one load balancer. At two backend servers enter the following commands— $sudo apt-get install apache2 $sudo apt-get install mysql-server $sudo apt-get install php libapache2-mod-php php-mysql $sudo gedit /var/www/html/index.html (Mak...

Packet capturing of different protocols using Wireshark

Wireshark is the world’s foremost and widely-used network protocol analyzer . It is used for network troubleshooting, analysis, software and communications protocol development, and education. It is a free and an open-source packet analyzer.It is cross-platform. To trace the packets first of all download and install Wireshark in the windows operating system. Open Wireshark and then choose the interface. 1.Tracking FTP Packets Step 1:   $sudo apt-get install vsftpd  command on Ubuntu terminal Step 2: Start Wireshark and open command prompt in windows. In the command prompt enter the IP address of Ubuntu Machine. It asks for username and password authentication for the Ubuntu  machine. Step 3 : Start capturing by clicking the green button in Wireshark.   Step 4: In the filter of Wireshark ,  enter ftp followed by IP address to track. Step 5 : Press the red button to stop capturing. ...

Fundamental Concepts of Arrays

  An   array   is a collection of elements of the same data type stored in   contiguous memory cells . It has a   fixed size   and is by default   passed by reference   to a function.  Eg. int arr[6] = {4, -3, 8, 5, -1, 6}; It initializes an integer array 'arr' storing 6 elements.  Assuming the size of an integer to be 4 bytes and base cell address to be 2000. It can be represented as -  A  dynamic array  is similar to a static array but it has the ability to  automatically resize  itself when an element is inserted or deleted.  They are available as  vectors in C++  and likewise l ists in Java .  Eg. list<int> l;      vector<int> v; Vectors are slightly less efficient than static arrays due to the occasional resizing and copying of elements.   The amortized time complexity of insertion in a dynamic array is O(1).  [Amortized Time complexity ...