Network Information and Connection

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you'll learn how to use essential Linux commands to gather network information and test network connections. These skills are crucial for system administrators and network professionals to diagnose and troubleshoot network issues. We'll guide you through each step, assuming you're new to Linux networking concepts.

Achievements

By the end of this lab, you'll be able to:

  • Use ip to view and manage network interfaces
  • Test network connectivity with ping
  • Examine network statistics using netstat

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/RemoteAccessandNetworkingGroup(["`Remote Access and Networking`"]) linux/RemoteAccessandNetworkingGroup -.-> linux/netstat("`Network Monitoring`") linux/RemoteAccessandNetworkingGroup -.-> linux/ping("`Network Testing`") linux/RemoteAccessandNetworkingGroup -.-> linux/ip("`IP Managing`") subgraph Lab Skills linux/netstat -.-> lab-387338{{"`Network Information and Connection`"}} linux/ping -.-> lab-387338{{"`Network Information and Connection`"}} linux/ip -.-> lab-387338{{"`Network Information and Connection`"}} end

View Network Interfaces

Let's start by examining your network interfaces using the ip command.

  1. Open a terminal window. You should see a prompt ending with a $ symbol.

  2. Type the following command and press Enter:

    ip addr

    This command shows information about all network interfaces on your system.

  3. You should see output similar to this:

    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
     inet 127.0.0.1/8 scope host lo
        valid_lft forever preferred_lft forever
    86484: eth1@if86485: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
     link/ether 02:42:ac:14:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
     inet 172.20.0.3/16 brd 172.20.255.255 scope global eth1
        valid_lft forever preferred_lft forever

    Let's break down this output:

    • lo: This is the loopback interface. It's a special network interface that your computer uses to communicate with itself.
    • eth1: This is your main Ethernet interface. It's used for connecting to networks.
    • inet: This line shows the IP address assigned to the interface. For eth1, it's 172.20.0.3 in this example.

    Note: The LabEx VM environment may change, so your output might be slightly different. The important part is recognizing the structure of the output.

Examine a Specific Network Interface

Now, let's focus on a specific network interface, typically eth1 for the primary Ethernet connection.

  1. In the same terminal window, type the following command and press Enter:

    ip addr show eth1

    This command displays detailed information about the eth1 interface.

  2. You should see output similar to this:

    86484: eth1@if86485: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
     link/ether 02:42:ac:14:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
     inet 172.20.0.3/16 brd 172.20.255.255 scope global eth1
        valid_lft forever preferred_lft forever

    Let's understand this output:

    • eth1: This is the name of the interface.
    • <BROADCAST,MULTICAST,UP,LOWER_UP>: These are flags indicating the interface's capabilities and state.
    • link/ether 02:42:ac:14:00:03: This is the MAC address of the interface, a unique identifier for the network hardware.
    • inet 172.20.0.3/16: This is the IPv4 address assigned to the interface, followed by the subnet mask in CIDR notation.

    Note: If you don't see eth1, your main interface might have a different name. In that case, replace eth1 with the interface name you saw in Step 1.

Test Network Connectivity

The ping command is used to test basic network connectivity. We'll use it to check our connection to a well-known server.

  1. In your terminal, type the following command and press Enter:

    ping -c 4 8.8.8.8

    This command sends 4 ping requests to Google's public DNS server at IP address 8.8.8.8.

  2. You should see output similar to this:

    PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
    64 bytes from 8.8.8.8: icmp_seq=1 ttl=117 time=1.61 ms
    64 bytes from 8.8.8.8: icmp_seq=2 ttl=117 time=1.55 ms
    64 bytes from 8.8.8.8: icmp_seq=3 ttl=117 time=1.57 ms
    64 bytes from 8.8.8.8: icmp_seq=4 ttl=117 time=1.57 ms
    
    --- 8.8.8.8 ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3004ms
    rtt min/avg/max/mdev = 1.545/1.573/1.607/0.022 ms

    This output shows successful ping responses. The exact times may vary in your environment.

    Note: If you see "100% packet loss" or "Destination Host Unreachable", it might indicate network connectivity issues in the LabEx VM. Free acounts have limited network access, so you may need to upgrade to a paid account to resolve this issue.

Test Domain Name Resolution

Now, let's test our ability to resolve domain names using the ping command.

  1. In your terminal, type the following command and press Enter:

    ping -c 4 google.com

    This command is similar to the previous one, but instead of an IP address, we're using a domain name (google.com).

  2. You should see output similar to this:

    PING google.com (172.217.16.142) 56(84) bytes of data.
    64 bytes from ham02s14-in-f14.1e100.net (172.217.16.142): icmp_seq=1 ttl=117 time=11.8 ms
    64 bytes from ham02s14-in-f14.1e100.net (172.217.16.142): icmp_seq=2 ttl=117 time=11.7 ms
    64 bytes from ham02s14-in-f14.1e100.net (172.217.16.142): icmp_seq=3 ttl=117 time=11.7 ms
    64 bytes from ham02s14-in-f14.1e100.net (172.217.16.142): icmp_seq=4 ttl=117 time=11.7 ms
    
    --- google.com ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3004ms
    rtt min/avg/max/mdev = 11.677/11.719/11.814/0.052 ms

    This output demonstrates successful domain name resolution and connectivity. The IP address and exact times may vary in your environment.

    Note: If you see an error like "could not resolve google.com", it might indicate DNS issues in the LabEx VM. Free acounts have limited network access, so you may need to upgrade to a paid account to resolve this issue.

View Active Network Connections

The netstat command is a powerful tool for viewing network statistics and active connections. We'll use it to see what network connections are currently active on your system.

  1. In your terminal, type the following command and press Enter:

    sudo netstat -tuln

    You'll be prompted for your password. Enter it to proceed.

  2. You should see output similar to this:

    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
    tcp        0      0 0.0.0.0:3001            0.0.0.0:*               LISTEN
    tcp        0      0 0.0.0.0:3002            0.0.0.0:*               LISTEN
    tcp        0      0 127.0.0.11:42051        0.0.0.0:*               LISTEN
    tcp6       0      0 :::22                   :::*                    LISTEN
    udp        0      0 0.0.0.0:3001            0.0.0.0:*
    udp        0      0 127.0.0.11:40380        0.0.0.0:*

    This output shows active TCP and UDP connections. The exact ports and addresses may vary in your LabEx VM environment.

    Note: The specific entries you see will depend on the services running in your LabEx VM at the time you run the command.

Summary

Congratulations! You've completed the Network Information and Connection lab. In this lab, you've learned how to:

  1. View network interface information using the ip command
  2. Test network connectivity and domain name resolution with the ping command
  3. Examine active network connections using the netstat command

These tools are essential for understanding and troubleshooting network issues in Linux systems. As you continue your journey in Linux system administration, you'll find these commands invaluable for diagnosing and resolving network-related problems.

Remember, the LabEx VM environment may change, so always be prepared to adapt these commands to your specific situation. Practice using these commands in different scenarios to become more familiar with their output and options.

Happy networking!

Other Linux Tutorials you may like