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...

Network Connection verification and Troubleshooting commands in Windows

To ensure the proper network connection in the system, we do the following three types of checking: ---   Check the NIC card --- Check whether we have an IP or not or our gateway is active or not by a ping test -----  Check if the port no or the service is active or not To check the connection go to command prompt and enter the commands >ping localhost  then NIC  working. >ping 172.29.0.1 then gateway working >ipconfig In computing, ipconfig (internet protocol configuration) is a console application (command line tool) in Microsoft Windows used to control the network connections on windows.It displays all current TCP/IP network configuration values and can modify DHCP and DNS settings. Usually, ipconfig command is used with the command-line switch  /all. > ipconfig /all This command shows the various network configurations, MAC address, default gateway and IP addresses of different servers on the ne...

Application Layer

Application Layer(Layer 7): This layer lies at the top of the OSI model. It enables the user, human or software to access the network. It is responsible for providing services to the user. High-level APIs including resource sharing, remote file access. Services provided by Application layer: Network Virtual terminal: A network virtual terminal is a software version of a physical terminal. This layer is responsible for facilitating the user to log on to a remote host through setting up network virtual terminal. File transfer, access, and management: It allows a user to access files    in a remote host(to make changes or read data), to retrieve files from a remote computer for use in the local computer