Networking for Developers – part 3: Network and Physical layers
Tags: networking, ifconfig, network, ping
Published: 2019-02-22 09:39:50

---
title: Networking for Developers – part 3: Network and Physical layers
published: true
tags: networking,ifconfig,network,ping
canonical_url: https://flaviabastos.ca/2019/02/22/networking-for-developers-part-3-network-and-physical-layers/
---

> NOTE: Catch up with the previous posts in this post series:
> 
> [Part 1: Overview](https://wp.me/pa0b0y-2s)
> 
> [Part 2: Application and Transport layers](https://wp.me/pa0b0y-2G)

In the Internet, the network layer uses the **Internet Protocol** and it’s responsible to analyse the destination address in the packets and direct them to where they should go. The job to actually move the packets around belongs to the **Physical layer** , the bottom-most layer who sits on top of the hardware.

If you are the person configuring a local network (a small office, for example) you will need to learn how subnets mask and network prefixes work in order to route the packets properly to send them either to another host (computer) in your internal network or to tell the GATEWAY to send packets to another network, which could be the internet. I will not cover that kind of information because that is not the focus of this series.

Two main protocols used by the network layer are the **ICMP (Internet Control Message Protocol)**, responsible for connectivity and routing, and the **DNS (Domain Name Service)**, responsible for mapping host names to IP addresses.

When it comes to actually moving the data around, the physical layer takes over: all devices in a network have a physical address, the MAC (Media access Control) address. The data here is wrapped and is sent around as frames. The frame will have the origin and the destination MAC address, so the device in the physical layer of the network will know to which device it should move the data to.

A router (a physical device in the network), can re-frame some data in case it needs to send it to a host in a different physical network.

The main tools to troubleshoot the **network** layer are the following:

#### ifconfig

If used with no arguments will display the status of the host’s network interface. This is <u>the command you should use to find out the IP address</u> of the host. The output will display at least Ethernet (eth0) or Wifi (wlan0) interfaces, the localhost (lo) interface, which is a virtual network interface called loopback, among others.

```
ifconfig
```

#### ping

It will send an ICMP echo request to a network host. If the receiving host gets the packet and is configured to respond, it will send back an ICMP echo response. Two main things to pay attention in the output of this command are the **icmp\_seq** which ideally will be in sequence so this tells you that no packets were lost in this transmission and the **time** , which tells you how long the round-trip took. If you see a number higher than 1000ms, that means a slow connection.

You can use a host name or an IP address:

```
ping www.google.com
```

You can stop _ping_‘s output with CTRL+C or you can limit the output count by using the -c option like this:

```
ping -c 3 www.google.com
```

#### traceroute

It tracks the path that the packets take to reach a remote host. It can be helpful to detect in which point of the path there’s a hold up or block, for example. This command can take a host name or IP address:

```
traceroute www.google.com
```

#### host

It’s a DNS lookup utility and will convert names to IP addresses and vice-versa.

```
host www.google.com
```

Two useful tools to troubleshoot the **physical** layer:

#### ethtool

It displays information about network driver and hardware settings. It takes as an argument a network interface name – that we just learned we can find out by using _ifconfig_ ![😉](https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f609.png) The main thing to pay attention on _ethtool_‘s output is the **link detected** which will tell you that the hardware is actually on and connected. It might also be helpful to check the **speed** , which is the speed that the hardware is able to transmit data, and the **duplex** that will tell you what is the current [duplex mode](https://en.wikipedia.org/wiki/Duplex_(telecommunications)). Note that not all interfaces will have these extra info.

```
ethtool eth0
```

#### arp

_arp_ stands for Address Resolution Protocol and is used to find the MAC address of a device in the network. This can be useful to check that there aren’t conflicts in the network configuration. It can take an IP address as argument or no arguments at all, in which case will display all known MAC addresses.

```
arp
```

* * *

Once again, there’s a lot more that could be said about these layers and network in general. Here are some resources to expand the information I shared in this series (most of them are from [Julia](https://jvns.ca/) because she rocks explaining stuff!):

- Julia’s [computer networking zine](https://wizardzines.com/zines/networking/) (free to read online) and [upcoming networking tools comics](https://jvns.ca/blog/2019/02/10/a-few-networking-tool-comics/) (blog post)
- Julia’s blog post on [IP addresses and routing](https://jvns.ca/blog/2018/07/24/ip-addresses-routing/)
- [Saron](https://saron.io/) invited Julia on the [Code Newbie podcast](https://www.codenewbie.org/podcast) to explain [How does the internet work?](https://jvns.ca/blog/2018/03/05/codenewbie-networking-podcast/)
- Julia’s blog post on [what’s a network interface](https://jvns.ca/blog/2017/09/03/network-interfaces/)
- [How does the Internet zine](https://shop.bubblesort.io/products/how-does-the-internet-zine) by [Amy Wibowo](https://twitter.com/sailorhg) (paid)
- [Networking for Web Developers](https://www.udacity.com/course/networking-for-web-developers--ud256) Udacity course (free)

> _The post_ [Networking for Developers – part 3: network and physical layers](https://wp.me/pa0b0y-2P)_ was originally published at _[flaviabastos.ca](https://flaviabastos.ca/)