Lesson 7.3: Networking from the command line
The basic network facts of a Linux machine and the commands that show them: IP address and network interface (ip a, hostname -I), the default gateway (ip r), testing reachability (ping), name resolution (/etc/hosts, /etc/resolv.conf, host, dig), listening ports (ss, and the older netstat) and a first HTTP request with curl.
20 min
You will learn to
- Find the machine's IP address, network size and interface
- Find the default gateway
- Test whether a host answers with ping and read the result
- Explain how a name becomes an address (/etc/hosts, DNS, resolv.conf)
- List the ports this machine listens on with ss
- Fetch HTTP headers with curl -I
Key terms
- IP address
- A machine's number on a network. IPv4 addresses are four numbers 0-255 separated by dots.
- Network interface
- A connection point to a network, physical (a network card) or virtual. lo is the loopback interface; names like eth0, ens3 or enp0s3 are network cards.
- Prefix /24 (CIDR)
- How many leading bits of the address name the network. /24 means the first three numbers are the network (10.0.2.0/24) and the last one the host: 254 usable addresses.
- Default gateway
- The router that receives every packet meant for another network.
- MAC address
- The hardware address of a network card (link/ether 52:54:00:...), used only inside the local network.
- DNS
- Domain Name System: the distributed directory that turns names like www.lhm.example into addresses. An A record holds an IPv4 address, AAAA an IPv6 address.
- /etc/hosts and /etc/resolv.conf
- /etc/hosts is a local list of names and addresses, checked first. /etc/resolv.conf names the DNS server to ask for everything else.
- ICMP and ping
- ICMP is the network's control and error protocol. ping sends ICMP echo requests and measures how long each echo reply takes (round-trip time).
- Port
- A number from 1 to 65535 that picks one service on a machine: 22 SSH, 53 DNS, 80 HTTP, 443 HTTPS. A program that waits for connections on a port is listening.
- TCP and UDP
- The two main transport protocols. TCP sets up a connection and guarantees order and delivery (SSH, web); UDP sends single messages without a connection (DNS queries, time sync).
- ip, ss and net-tools
- ip (addresses, routes) and ss (sockets) come from the iproute2 package and replace the older ifconfig, route and netstat from net-tools.
← Transforming text: cut, tr, sed and awk · All lessons · Transferring files: wget, curl, scp and rsync →