Network Information and Connection

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn to use some command to get network information and test the network connection.

Achievements

  • ifconfig - get network interfaces information.
  • ip - a powerful tool for configure network interfaces.
  • ping - test the network connection.
  • netstat - show network status and protocol statistics.

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/RemoteAccessandNetworkingGroup(["`Remote Access and Networking`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) shell(("`Shell`")) -.-> shell/BasicSyntaxandStructureGroup(["`Basic Syntax and Structure`"]) shell(("`Shell`")) -.-> shell/SystemInteractionandConfigurationGroup(["`System Interaction and Configuration`"]) linux/RemoteAccessandNetworkingGroup -.-> linux/ifconfig("`Network Configuring`") linux/RemoteAccessandNetworkingGroup -.-> linux/netstat("`Network Monitoring`") linux/RemoteAccessandNetworkingGroup -.-> linux/ping("`Network Testing`") linux/RemoteAccessandNetworkingGroup -.-> linux/ip("`IP Managing`") linux/UserandGroupManagementGroup -.-> linux/set("`Shell Setting`") shell/BasicSyntaxandStructureGroup -.-> shell/comments("`Comments`") shell/SystemInteractionandConfigurationGroup -.-> shell/shell_options("`Shell Options and Attributes`") subgraph Lab Skills linux/ifconfig -.-> lab-45{{"`Network Information and Connection`"}} linux/netstat -.-> lab-45{{"`Network Information and Connection`"}} linux/ping -.-> lab-45{{"`Network Information and Connection`"}} linux/ip -.-> lab-45{{"`Network Information and Connection`"}} linux/set -.-> lab-45{{"`Network Information and Connection`"}} shell/comments -.-> lab-45{{"`Network Information and Connection`"}} shell/shell_options -.-> lab-45{{"`Network Information and Connection`"}} end

Show Network Interfaces Information with ifconfig Command

Linux provides a command called ifconfig to get network interfaces information.

The ifconfig command can be used to show all network interfaces information. Please run the command below to get the output.

ifconfig

The output is include IP address, MAC address, network mask, broadcast address, etc.

Show Specific Interface with ifconfig Command

The ifconfig command can be used to show specific network interface information. Please run the command below to get the output.

ifconfig eth0

Set Interface Up and Down with ifconfig Command

The ifconfig command can be used to up and down network interface.

Please do not execute the following commands in the environment!

ifconfig eth0 up

ifconfig eth0 down

Show All Interfaces with ip Command

ifconfig command can get network interfaces information. But it's a legacy command and is not recommended to use. The ip command is a more powerful tool for configuring network interfaces.

The ip command can be used to show all network interfaces information. Please run the command below to get the output.

ip a

The output is include IP address, MAC address, network mask, broadcast address, etc.

Show Specific Interface with ip Command

The ip command can be used to show specific network interface information. Please run the command below to get the output.

ip a show eth0

Set Interface Up and Down with ip Command

The ip command can be used to up and down network interface.

Please do not execute the following commands in the environment!

ip link set eth0 up

ip link set eth0 down

Test Network Connection and Latency

Linux provides a command called ping to test the network connection and latency.

The ping command can test basic network connectivity to a remote machine with a domain or ip address. Please run the command below to get the output.

ping google.com

The ping command will send ICMP packets to the target host. The target host will reply with ICMP packets. The ping command will calculate the time between sending and receiving the ICMP packets.

In Windows, the ping command will stop after 4 times. But in linux, it will not stop until you press Ctrl + C.

Set the Number of Tests

The ping command can be used to test specific count. Please run the command below to get the output.

## stop after 5 times
ping -c 5 google.com

Test Specific Interface

The ping command allows you to test the specified network interface when you have more than one. Please run the command below to get the output.

ping -I eth0 google.com

Show All Network Status and Protocol Statistics

Linux provides a command called netstat to show network status and protocol statistics.

The netstat command can be used to show all network status. Please run the command below to get the output.

netstat

The output is include network connections, routing tables, interface statistics, masquerade connections, multicast memberships, and packet/byte statistics for IP, ICMP, TCP, and UDP.

Show Specific Network Status

netstat have many parameters, you can use them to show specific network status.

  • the output is include TCP connections.
netstat -t
  • the output is include UDP connections.
netstat -u
  • the output is include listening TCP and UDP connections.
netstat -l
  • the output is include PID and name of the program to which each socket belongs.
netstat -p
  • the output is include numeric addresses and port numbers.
netstat -n

Combined Usage Parameters

if you want to get the output include TCP connections, listening TCP and UDP connections, PID and name of the program to which each socket belongs, and numeric addresses and port numbers, you can use the following command.

netstat -tunlp

Summary

Congratulations! You have completed the network information and test lab.

In this lab, you learned four network information and test commands ifconfig, ip, ping, netstat.

These commands that are used frequently, so be sure to keep them in mind.

Keep exploring!

Other Linux Tutorials you may like