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 (Make some changes in t

Devices used in each layer of OSI Model

Pic: Wikipedia 1.Physical Layer- Bits: Hubs, Repeaters, Fibers, Cables, Microwave, Radio, etc. 2.Data Link Layer- Frames: Bridges, 2-Layer Switches, Ethernet, WiFi AP's 3.Network Layer- Packets: Routers, 3-Layer Switches. 4.Transport Layer- Segments: Load Balancers/Firewalls. 5.Session Layer- Data:  Load Balancers/Firewalls/Computers. 6.Presentation Layer- Data: Load Balancers/Firewalls/Computers. 7.Application Layer- Data:  Load Balancers/Firewalls/Computers.

Modes of Data Communication

Modes of Data Communication refers to the direction of data flow from sender to receiver or vice-versa. There are basically three modes of data communication:- 1. Simplex: In this mode the communication is unidirectional . Only one of the two devices on a link can transmit and the other can only receive .i.e data travels in one direction. Example: radio, television, loudspeaker 2. Half-Duplex: In this mode, each device on the link has   the ability to both transmit and receive, each at a time . When one device is sending, the other can only receive and vice versa. Example: walkie-talkie 3. Full-Duplex: In full-duplex mode, both the devices can transmit and receive simultaneously .i.e data can travel in both directions at the same time. Here the communication is bidirectional . Example: Telephone