CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Networking / ip

ip

Show and change interfaces, addresses and routes

Intermediatenetworkroutinginterfacesessential

ip is the modern tool for the kernel's network configuration: interfaces (ip link), IP addresses (ip addr), the routing table (ip route) and ARP neighbours (ip neigh). Use it to answer 'what's my IP?', 'which way does traffic leave?' and to make temporary changes.

Syntaxip [-br] [-s] [-4|-6] OBJECT { show | add | del | set | get } ... (OBJECT: link addr route neigh)

Watch it run

You're on an unfamiliar cloud VM and need its private IP, interface name and MTU.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
ip -br a

Brief mode: one line per interface with its state and addresses. The machine has one real interface, ens5, with the private IP 10.0.1.25 in a /24 subnet.

Anatomy of a command

$
commandsudo

Showing is allowed for everyone; changing interfaces, addresses or routes needs root (CAP_NET_ADMIN).

How it works

ip sends rtnetlink messages to the kernel (RTM_GETLINK, RTM_GETADDR, RTM_GETROUTE to read; RTM_NEWADDR, RTM_NEWROUTE and friends to change) and prints the replies. Nothing is read from or written to files: changes take effect immediately and vanish at reboot, or sooner when systemd-networkd or NetworkManager reapplies their configuration (netplan on Ubuntu, NetworkManager on RHEL). For a packet, the kernel picks the route with the longest matching prefix (a /32 beats a /24 beats the 0.0.0.0/0 default), then the lowest metric; ip route get runs that exact lookup and shows the outgoing interface, next hop and source address. ip neigh shows the ARP cache that maps next-hop IPs to MAC addresses on the local link. ip link shows layer-2 state: UP means administratively enabled, LOWER_UP means the link (cable or virtual NIC) is actually connected. It replaces ifconfig, route and arp from the deprecated net-tools.

Options you'll actually use

ip a / ip addr show [dev X]Addresses on all (or one) interface
ip -br a / ip -br linkBrief one-line-per-interface view
ip r / ip routeRouting table (main)
ip route get ADDRWhich route, interface and source IP a packet to ADDR would use
ip -s link show XInterface counters: bytes, packets, errors, drops
ip link set X up|down|mtu NEnable, disable or change MTU of an interface
ip addr add|del IP/N dev XAdd or remove an address (until reboot)
ip route add|del NET via GWAdd or remove a route
ip neighARP/NDP neighbour cache: IP to MAC, and its state
-4 / -6Only IPv4 or IPv6
-cColour output
-jJSON output, for scripts (ip -j a | jq ...)
ip netnsNetwork namespaces (how containers get their own stack)

Common mistakes

Changing addresses or routes with ip and expecting them to survive a reboot

ip only edits the running kernel state; netplan/systemd-networkd or NetworkManager rebuild it from their config at boot (and sometimes at DHCP renewal).

Put the change in /etc/netplan/*.yaml (Ubuntu) or nmcli (RHEL), then apply
sudo ip link set ens5 down over SSH to 'bounce' the interface

Your session goes through that interface, and taking it down also removes its routes, so the up command never arrives.

Use the console, or one line: sudo ip link set ens5 down && sudo ip link set ens5 up (still risky)
ip route add ... in a provisioning script

Re-running the script fails with 'RTNETLINK answers: File exists'.

ip route replace 10.20.0.0/16 via 10.0.1.1
Reading 'state UNKNOWN' on lo as a problem

Loopback and some virtual interfaces have no carrier concept; UNKNOWN is normal for them.

Check the flags: UP and LOWER_UP mean the interface works.

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Show every interface in this sandbox with its state and addresses, one line each.

  2. 2

    Show the routing table, then ask the kernel which route it would use to reach 8.8.8.8.

  3. 3

    Try to add the address 192.0.2.10/32 to lo without sudo, read the error, then add it with sudo and confirm.

  4. 4

    Print the receive and transmit counters of the loopback interface in human-readable form.

Related commands

ifconfigLegacy interface configuration (read it, prefer ip)ssSee listening ports and open connectionspingCheck if a host answers and how fasttracerouteTrace the routers between you and a host
PreviousnetstatNextifconfig
Linux / Networking / ip

ip

Show and change interfaces, addresses and routes

Intermediatenetworkroutinginterfacesessential

ip is the modern tool for the kernel's network configuration: interfaces (ip link), IP addresses (ip addr), the routing table (ip route) and ARP neighbours (ip neigh). Use it to answer 'what's my IP?', 'which way does traffic leave?' and to make temporary changes.

Syntaxip [-br] [-s] [-4|-6] OBJECT { show | add | del | set | get } ... (OBJECT: link addr route neigh)

Watch it run

You're on an unfamiliar cloud VM and need its private IP, interface name and MTU.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
ip -br a

Brief mode: one line per interface with its state and addresses. The machine has one real interface, ens5, with the private IP 10.0.1.25 in a /24 subnet.

Anatomy of a command

$
commandsudo

Showing is allowed for everyone; changing interfaces, addresses or routes needs root (CAP_NET_ADMIN).

How it works

ip sends rtnetlink messages to the kernel (RTM_GETLINK, RTM_GETADDR, RTM_GETROUTE to read; RTM_NEWADDR, RTM_NEWROUTE and friends to change) and prints the replies. Nothing is read from or written to files: changes take effect immediately and vanish at reboot, or sooner when systemd-networkd or NetworkManager reapplies their configuration (netplan on Ubuntu, NetworkManager on RHEL). For a packet, the kernel picks the route with the longest matching prefix (a /32 beats a /24 beats the 0.0.0.0/0 default), then the lowest metric; ip route get runs that exact lookup and shows the outgoing interface, next hop and source address. ip neigh shows the ARP cache that maps next-hop IPs to MAC addresses on the local link. ip link shows layer-2 state: UP means administratively enabled, LOWER_UP means the link (cable or virtual NIC) is actually connected. It replaces ifconfig, route and arp from the deprecated net-tools.

Options you'll actually use

ip a / ip addr show [dev X]Addresses on all (or one) interface
ip -br a / ip -br linkBrief one-line-per-interface view
ip r / ip routeRouting table (main)
ip route get ADDRWhich route, interface and source IP a packet to ADDR would use
ip -s link show XInterface counters: bytes, packets, errors, drops
ip link set X up|down|mtu NEnable, disable or change MTU of an interface
ip addr add|del IP/N dev XAdd or remove an address (until reboot)
ip route add|del NET via GWAdd or remove a route
ip neighARP/NDP neighbour cache: IP to MAC, and its state
-4 / -6Only IPv4 or IPv6
-cColour output
-jJSON output, for scripts (ip -j a | jq ...)
ip netnsNetwork namespaces (how containers get their own stack)

Common mistakes

Changing addresses or routes with ip and expecting them to survive a reboot

ip only edits the running kernel state; netplan/systemd-networkd or NetworkManager rebuild it from their config at boot (and sometimes at DHCP renewal).

Put the change in /etc/netplan/*.yaml (Ubuntu) or nmcli (RHEL), then apply
sudo ip link set ens5 down over SSH to 'bounce' the interface

Your session goes through that interface, and taking it down also removes its routes, so the up command never arrives.

Use the console, or one line: sudo ip link set ens5 down && sudo ip link set ens5 up (still risky)
ip route add ... in a provisioning script

Re-running the script fails with 'RTNETLINK answers: File exists'.

ip route replace 10.20.0.0/16 via 10.0.1.1
Reading 'state UNKNOWN' on lo as a problem

Loopback and some virtual interfaces have no carrier concept; UNKNOWN is normal for them.

Check the flags: UP and LOWER_UP mean the interface works.

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Show every interface in this sandbox with its state and addresses, one line each.

  2. 2

    Show the routing table, then ask the kernel which route it would use to reach 8.8.8.8.

  3. 3

    Try to add the address 192.0.2.10/32 to lo without sudo, read the error, then add it with sudo and confirm.

  4. 4

    Print the receive and transmit counters of the loopback interface in human-readable form.

Related commands

ifconfigLegacy interface configuration (read it, prefer ip)ssSee listening ports and open connectionspingCheck if a host answers and how fasttracerouteTrace the routers between you and a host
PreviousnetstatNextifconfig