Networking Basics in Linux

Understanding Network Fundamentals: IP Addresses, Subnets, and Gateways
IP Address
identifies device on network
  • IPv4 - dotted quad
  • IPv6 - hexadecimal
Subnet Mask
is the network ID
255.255.255.0
first 3/4s of the dotted quad identify the network (192.168.1)
the last number identifies the computer on the network
computers on the network can communicate directly with each other
computers on different networks can communicate through a gateway

Gateway
gateway connects network to the Internet
typically sits at .1 (192.168.1.1)

Interface
physical or virtual hardware
  • eth0 or enp3s0 - wired ethernet card
  • wlan0 or wlp2s0 - wifi card
  • lo - loopback interface

Network Configuration Commands: ip, ifconfig
standard command for networking was ifconfig
officially deprecated
modern replacement is the ip command

Viewing Interfaces (ip addr)
to view IP addresses use command
ip addr
prints a block of text for each interface
ifconfig provides the same information in a more readable format

Viewing the Routing Table (ip route)
command
ip route
output
default via 192.168.1.1 dev eth0 
192.168.1.0/24 dev eth0 proto kernel...
the first line sends packets with unknown addresses to the gateway via device eth0

Testing Network Connectivity: ping, traceroute
The Pulse Check: ping
sends ICMP Echo Request packet to a server and waits for a response
a simple Linux ping command will execute continuously unless the -c flag is used
ping -c <count> <target IP address>
trouble shooting steps using ping
  1. ping yourself - ping 127.0.0.1
    failure indicates issue with local networking software
  2. ping the gateway - ping 192.168.1.1
    failure indicates issue with connection to router
  3. ping the Internet - ping 8.8.8.8 (Google's Public DNS)
    failure indicates issue with router's connection to the Internet
  4. ping a domain - ping google.com
    failure indicates issue with DNS

The Map: traceroute
if ping fails where was the point of failure
traceroute <target IP address>
prints every hop the packet takes
flags
  • -I - use ICMP echo packets
  • -m - maximum number of hops
  • -w - seconds to wait for a response

DNS Resolution: nslookup, dig, host
DNS translates names to numbers

The Simple Check: host
host google.com
google.com has address 142.250.180.14
The Standard Tool: nslookup
provides more information
nslookup google.com
The Power Tool: dig
dig is Domain Information Groper
shows the raw query and response
dig google.com
Network Configuration Files: /etc/network/interfaces, NetworkManager, netplan
how a Linux computer's IP address is permanently changed depends on the distribution

The Modern Ubuntu Way: Netplan
Netplan uses YAML config files found in/etc/netplan/
ls /etc/netplan
to set a static IP edit the file 00-installer-config.yaml
file is indentation-sensitive, use spaces and not tabs
example
network:
  version: 2
  ethernets:
    enp3s0:
      dhcp4: no
      addresses:
        - 192.168.1.50/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]
to apply changes
sudo netplan apply
Connecting to Networks: Ethernet and Wi-Fi
Ethernet
plug and play
kernel detects carrier when cable is plugged in, DHCP runs automatically
IP address is set check the link status
ip link show
Wi-Fi
harder because of encryption
easy to do using graphical tool nmtui (Network Manager Terminal UI)
run in terminal

Understanding Network Services: DHCP and Static IP Configuration
DHCP - Dynamic Host Configuration Protocol

servers should always have a static IP

Summary
covered
  • Identification - use of ip addr command
  • Connectivity - use of ping and traceroute
  • Resolution - dig or nslookup to test DNS
  • Configuration - using netplan to set static IP address
key points
  • IP address - unique ID on network
  • Gateway - router connecting to Internet
  • ping - test connectivity
  • ip addr - view network interfaces
  • traceroute - shows path of a packet
  • DNS - name service
  • netplan - network config tool
  • DHCP vs Static IP - DHCP for clients, static IP for servers
index