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

What is a Network Hub?

Hub is the most simple networking device which is used to connect all network devices on an internal network. It detects whether a device is physically connected to it or not. It is a Layer 1 device in OSI reference model and is best for small and simple local area networks. It is not intelligent because it does not filter any data. When a packet is received by one port, the data is copied to all other ports and is seen by all connected devices. It has 4/12 ports . Drawbacks of Hubs are:- Rebroadcast- Forwards packets across all ports. Creates Security concerns- Traffic could not be safeguarded. Unnecessary traffic which reduces bandwidth.   

Network Layer

Network Layer(Layer 3):  It is responsible for the source-to-destination delivery of packets across multiple links(networks).It is also responsible for structuring and managing a multi-node network, including addressing, routing, and traffic control. Functions include: Logical Addressing: IP addressing is defined at the Network Layer of the OSI model. This layer adds a header to the packet coming from the upper layer that, among other things, indicates the logical addresses of the sender and receiver. IP addressing is also known as logical addressing. Routing: When independent networks are connected together to create a large network, the connecting devices(routers/gateways) route the packets to their final destination. The decision which route/path should be followed to reach from source to destination is handled by the network layer. 

Types of Network

What is a Network ? A Network is defined as an arrangement of a set of devices connected together by communication links for the purpose of sharing data. Each device may be called as a node which can be a computer, printer or any other devices capable of sending or receiving data generated by other nodes or devices on the network. Following are the types of Network:- 1. Local Area Network(LAN): LANs are privately owned networks defined within a small physical area such as in a single office, building or campus. LAN size is limited to a few kilometers for which the network management is simple.   Most common LAN topologies are bus, ring, star and have data rates in the range of 4 to 16 megabits per second. LANs often use a transmission technology consisting of a single cable to which all the machines are attached. LANs are mostly used to allow resources to be shared among personal computers or workstations. 2. Metropolitan Area Network(MAN): A MAN is des...