Skip to main content

Command Palette

Search for a command to run...

Lecture # 26 - Networking in Linux

Networking Commands in Linux

Published
5 min read
Lecture # 26 - Networking in Linux

ifconfig:

ifconfig is used to show the configuration of different network interfaces. This command is written as ifconfig .

Here inet shows the IP Address, netmask shows the subnet mask, RX shows received packets and TX shows transmitted packets.

  • Show one Interface:

    To show the configuration of only one interface ifconfig [interface-name] is used.

  • Disable an Interface:

    To disable or down an interface sudo ifconfig [interface-name] down is used.

  • Enable an Interface:

    To enable or up an interface sudo ifconfig [interface-name] up is used.

ip:

  • Show Information of Interfaces:

To show the information of different interfaces there are two commands:

  1. ip a:

    This command is written as ip a .

  1. ip addr:

    This command is written as ip addr .

  • Show Information of one interface:

To show information of only one interface there are two commands

  1. ip a:

    To show information of only one interface using ip a, ip a show [interface-name] is used.

  2. ip addr:

To show information of only one interface using ip addr, ip addr show [interface-name] is used.

  • Disable an Interface:

To disable an interface sudo ip link set [interface-name] down is used.

  • Enable an Interface:

    To enable an interface sudo ip link set [interface-name] up is used.

ping:

  • Check Internet Connectivity:

    To check internet connectivity ping [website-url] is used. Press ctrl + C to stop.

  • Send Specified Number of Packets:

    To send specified number of packets ping -c [number-of-packets] [website-url] is used.

  • Show the Timestamp of Packets:

    To show the timestamp of sent packets ping -D [website-url] is used.

traceroute:

Traceroute is used to trace the hops(devices) to reach the destination. If [* * *], this means no response from the hops. This command is written as traceroute [website-url] .

netstat:

Netstat is used to show the socket details. This command is written as netstat .

  • To show TCP and UDP sockets:

    To show details of TCP and UDP sockets netstat -tuln is used.

  • To show TCP sockets:

    To show details of TCP sockets netstat -t is used.

  • To show UDP sockets:

    To show details of UDP sockets netstat -u is used.

  • To show Summary or Protocols:

    To show summary of protocols netstat -s is used.

  • To show Routing Table:

    To show routing table netstat -r is used.

  • To show TCP and UDP sockets with Process ID:

    To show TCP and UDP sockets details with Process ID of each socket sudo netstat -tulnp is used.

ss:

ss is used to show the socket statistics.

  • Show all sockets:

    To show all sockets statistics ss -all is used.

  • Show Established Sockets:

    To show the statistics of established sockets ss -e is used.

  • Show TCP Sockets:

    To show the statistics of TCP sockets ss -t is used.

  • Show UDP Sockets:

    To show the statistics of UDP sockets ss -u is used.

dig:

The dig command is used to perform Domain Name System (DNS) queries. This command is written as dig [website-url] .

nslookup:

nslookup is used to query Domain Name System (DNS) servers to obtain various types of DNS information. This command is written as nslookup [website-url] .

host:

The host command is used for performing Domain Name System (DNS) lookups to obtain various information related to domain names and IP addresses. This command is written as host [website-url] .

arp:

arp is used to display and manipulate the Address Resolution Protocol (ARP) cache, which is a table maintained by the operating system that maps IP addresses to MAC addresses on a local network segment. There are two ways to write this command.

  1. Method 1: arp

  1. Method 2: arp -a

Show Specific Interface:

To display ARP of a specific interface arp -i [interface-name] is used.

hostname:

This command displays the hostname of the machine. This command is written as hostname .

  • Change Hostname:

    To change the hostname of a machine sudo hostnamectl set-hostname [new-host-name] is used.

curl:

This command is used to display the html code of a website. This command is written as curl [website-url] .

  • To save the code into a file:

    To save the html code of the file curl -o [file-name] [website-url] is used.

wget:

This command is used to download the contents of a website into a file. This command is written as wget [website-url] .

  • Save the output in a file:

    To save the output in a file after downloading the contents from the website wget -o [file-name] [website-url] is used.

  • Save the HTML code of a website recursively:

    To save the html code of a website recursively or you can say save the html code of a whole website wget --mirror [website-url] is used.