SkillPilotAI

Host IP configuration: static vs DHCP, gateway and DNS

A cable or Wi-Fi link alone is not enough: every interface needs four settings (IP address, subnet mask, default gateway, DNS server) before it can talk. They are typed in by hand (static) or handed out by a DHCP server, and knowing which setting does what is the base of every network troubleshooting.

14.1 Why is it used?

  • A new laptop plugged into the switch still cannot send a single packet: its interface has no IP address.
  • An interface = the network card connecting a device to the network (Ethernet port, Wi-Fi adapter); each has its own configuration.
  • Wrong or missing settings give very specific symptoms: LAN only, IPs work but names fail, or nothing at all.

14.2 The 4 settings of every interface

SettingExampleJob
IP address192.168.34.117The device's identity
Subnet mask255.255.255.0 (/24)Where the own LAN ends
Default gateway192.168.34.1Router for all traffic leaving the LAN
DNS server1.1.1.1Converts a name (example.com) into an IP

14.3 Static vs dynamic (DHCP)

PointStaticDynamic (DHCP)
Who sets itAdmin types it by handDHCP server hands it out
Changes?Stays until someone changes itComes with a lease, renewed when it runs out
Typical devicesServers, printers, routers (reached at a fixed address)Laptops, phones
RiskTypo or duplicate IP breaks the linkNo DHCP reply -> APIPA 169.254.x.x
DHCP: the laptop gets its config
  1. 1.Laptop broadcasts DHCP Discover

  2. 2.Switch delivers it to the DHCP server 192.168.34.2

  3. 3.Server sends an Offer with a free IP from its pool

  4. 4.Mask, gateway and DNS come along with the IP

  5. 5.Laptop accepts: 192.168.34.117/24, gw 192.168.34.1, DNS 1.1.1.1, lease 3600 s

14.4 How the gateway and DNS are used

  • To 192.168.34.20: the mask says same LAN, so the packet goes through the switch directly.
  • To 8.8.8.8: not on the LAN, so the laptop hands it to the gateway (router), which forwards it to the internet.
  • No gateway set: everything inside the LAN works, but there is no way out (Network unreachable).
  • Browser needs an IP, not a name: the laptop first asks DNS 1.1.1.1 (via switch and gateway), gets example.com = 104.20.23.154, then sends the real request.
Opening example.com
  1. 1.Laptop checks the mask: is 1.1.1.1 on my LAN? No

  2. 2.DNS query goes to the gateway 192.168.34.1 and out to 1.1.1.1

  3. 3.Answer: example.com = 104.20.23.154 comes back via router and switch

  4. 4.Same check for 104.20.23.154: off-LAN, so again via the gateway

  5. 5.Browser request reaches the web server

14.5 Practical: static config on Linux

  • ip addr add sets the IP + mask, ip route add default sets the gateway, /etc/resolv.conf holds the DNS server.
  • These commands are not persistent: they reset after a reboot.
Terminal
ip addr flush dev eth0ip addr add 192.168.34.20/24 dev eth0ip route add default via 192.168.34.1echo nameserver 8.8.8.8 > /etc/resolv.confip -4 addr show eth0ip routecat /etc/resolv.conf
Output
$ ip -4 addr show eth0    inet 192.168.34.20/24 scope global eth0$ ip routedefault via 192.168.34.1 dev eth0192.168.34.0/24 dev eth0 proto kernel$ cat /etc/resolv.confnameserver 8.8.8.8

14.6 Practical: DHCP on Linux

  • udhcpc (BusyBox DHCP client): discover, select, then the lease from 192.168.34.2 for 3600 s.
  • Mask, gateway (default via 192.168.34.1) and DNS (nameserver 1.1.1.1) all came from the DHCP server.
Terminal
ip addr flush dev eth0udhcpc -i eth0 -n -qip -4 addr show eth0ip routecat /etc/resolv.conf
Output
$ udhcpc -i eth0 -n -qudhcpc: started, v1.36.1udhcpc: broadcasting discoverudhcpc: broadcasting select for  192.168.34.117, server 192.168.34.2udhcpc: lease of 192.168.34.117 obtained  from 192.168.34.2, lease time 3600$ ip -4 addr show eth0    inet 192.168.34.117/24 scope global eth0$ ip routedefault via 192.168.34.1 dev eth0 metric 202192.168.34.0/24 dev eth0 proto kernel$ cat /etc/resolv.confnameserver 1.1.1.1

14.7 Practical: remove DNS and gateway

  • Wrong DNS (192.168.34.99): nslookup fails, but ping 8.8.8.8 works, so the internet is fine and only names fail.
  • Default route deleted: 8.8.8.8 gives Network unreachable, but the same-LAN server 192.168.34.20 still replies.
Terminal
echo nameserver 192.168.34.99 > /etc/resolv.confnslookup -timeout=2 -retry=1 example.comping -c 2 8.8.8.8ip route del defaultping -c 2 8.8.8.8ping -c 2 192.168.34.20
Output
$ nslookup -timeout=2 -retry=1 example.com;; communications error to   192.168.34.99#53: timed out;; no servers could be reached$ ping -c 2 8.8.8.864 bytes from 8.8.8.8: ttl=63 time=46.3 ms64 bytes from 8.8.8.8: ttl=63 time=25.6 ms$ ip route del default$ ping -c 2 8.8.8.8ping: connect: Network unreachable$ ping -c 2 192.168.34.2064 bytes from 192.168.34.20: time=1.37 ms64 bytes from 192.168.34.20: time=0.195 ms

14.8 Where it is set: Windows, Linux, macOS

OSGUICommand line
Windows 11Settings > Network & internet > adapter > IP assignment: Edit (Automatic DHCP / Manual)New-NetIPAddress, Set-DnsClientServerAddress
LinuxNetworkManager IPv4 tabnmcli, Netplan on servers
macOSSystem Settings > Network > Wi-Fi > Details > TCP/IP and DNS tabsnetworksetup -setmanual / -setdnsservers / -setdhcp

Syntax from the docs (not run on the office PC):

Output
# Windows (PowerShell, admin)New-NetIPAddress -InterfaceAlias Ethernet ` -IPAddress 192.168.1.50 -PrefixLength 24 ` -DefaultGateway 192.168.1.1Set-DnsClientServerAddress Ethernet ` -ServerAddresses 1.1.1.1# Linux (NetworkManager)nmcli con mod eth0 ipv4.method manual \ ipv4.addresses 192.168.1.50/24 \ ipv4.gateway 192.168.1.1 ipv4.dns 1.1.1.1# macOSnetworksetup -setmanual Wi-Fi 192.168.1.50 \ 255.255.255.0 192.168.1.1networksetup -setdnsservers Wi-Fi 1.1.1.1networksetup -setdhcp Wi-Fi

14.9 Practical: DHCP or static on Windows

  • ipconfig (next video) is the main viewer; here netsh and PowerShell were run only on the loopback interface.
  • DHCP enabled: No / Dhcp: Disabled means the interface is static.
PowerShell
netsh interface ipv4 show config `  "Loopback Pseudo-Interface 1"Get-NetIPInterface -AddressFamily IPv4 `  -InterfaceAlias "Loopback*" |  Format-List InterfaceAlias, Dhcp
Output
Configuration for interface  "Loopback Pseudo-Interface 1"  DHCP enabled:          No  IP Address:            127.0.0.1  Subnet Prefix:         127.0.0.0/8  Statically Configured DNS Servers: None InterfaceAlias : Loopback Pseudo-Interface 1Dhcp           : Disabled

14.10 Common mistakes

  • IP 169.254.x.x (APIPA): set to DHCP but no DHCP reply came, so no gateway and no DNS.
  • Thinking a static IP makes the internet faster: speed comes from the link/ISP plan; static only fixes the address.
  • Duplicate or wrong static IP: it can break the connection.
  • Blaming 'the internet' when only DNS is wrong: test ping 8.8.8.8 vs a name to tell them apart.

14.11 Interview tips

  • Static = manual and fixed; DHCP = automatic, on a lease.
  • Default gateway = the router where the host sends every packet whose destination is outside its subnet.
  • DNS server resolves names to IPs; no DNS = ping by IP works, names fail.
  • No gateway = LAN only; 169.254.x.x = DHCP failed (APIPA).