Configure Network Interfaces with ip
Configure network interfaces with ip — Linux · networking · telemetry tutorial, lesson 7.
Focus: configure network interfaces with ip
You’ve spent hours chasing a static IP that silently vanished after a reboot, or you’ve opened a firewall rule for a port only to discover your server’s interface was down. Configuring network interfaces with ip is the most direct way to bring a system online, inspect its state, and make changes without the legacy ifconfig baggage. Master ip, and you’ll stop guessing why traffic flows or stalls — you’ll control it.
The problem this lesson solves
The default tools for network configuration on Linux vary by distribution, but one thing is constant: if you don’t know how to view and modify interface state, you’ll be blind-debugging connectivity. The classic ifconfig is deprecated and doesn’t show all modern network namespaces, while network managers like NetworkManager hide crucial details behind abstractions. You need a direct, consistent way to configure network interfaces with ip — set an IP, bring an interface up or down, inspect routes, and verify changes instantly. This lesson gives you that control, so you can fix a broken link, add a second IP, or troubleshoot a missing gateway in seconds.
Core concept / mental model
Think of the ip command as the network Swiss-army knife from the iproute2 suite. It operates on a set of objects: link for the physical/virtual interfaces, addr for IP addresses on those links, and route for the forwarding table. Every operation follows the same pattern:
ip [ OPTIONS ] OBJECT { COMMAND | help }
The mental model: interfaces are the hardware doors (link), addresses are the nameplates on those doors (addr), and routes are the hallways that tell packets which door to exit (route). You configure the door first, then hang the nameplate, then point the hallway.
How it works step by step
Step 1 — List interfaces and their state
Start by seeing what your system has. ip link show lists all interfaces with their state (UP/DOWN), MAC address, and flags. Add -br for a brief output that’s easy to scan.
ip -br link show
# Example output:
# lo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
# eth0 UP 08:00:27:ab:cd:ef <BROADCAST,MULTICAST,UP,LOWER_UP>
# wlan0 DOWN 00:1a:2b:3c:4d:5e <BROADCAST,MULTICAST>
Step 2 — Inspect addresses and routes
ip addr show (or ip a) gives you every IP assigned to each interface. ip route show (or ip r) reveals the routing table — including your default gateway. Together they form a complete snapshot of your connectivity.
ip addr show eth0
ip route show
Step 3 — Bring an interface up or down
To stop traffic on an interface, use ip link set <interface> down. To start it, use up. This is often the quick fix for a “network is unreachable” error caused by a stray down state.
sudo ip link set eth0 down
sudo ip link set eth0 up
Pro tip: Always check the link state with
ip linkbefore chasing DNS or firewall issues. A down link makes every other diagnostic pointless.
Step 4 — Assign or remove IP addresses
Add a temporary IP (lost on reboot) with ip addr add. Remove one with ip addr del. This is the core of configuring network interfaces with ip — you control the address space directly.
sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip addr del 192.168.1.100/24 dev eth0
Step 5 — Manage routes
Add a default gateway or a static route using ip route add. Remove with ip route del. This sets the “hallway” that guides packets off-box.
sudo ip route add default via 192.168.1.1
sudo ip route add 10.0.0.0/8 via 192.168.1.254 dev eth1
Hands-on walkthrough
Scenario: Bring up a secondary interface with a static IP
Assume you have a server with two NICs: eth0 (primary) and eth1 (backup). You’ll bring eth1 up, assign it an IP, and verify the change — all with ip.
# 1. Bring eth1 up
sudo ip link set eth1 up
# 2. Show link state to confirm
ip -br link show eth1
# Output: eth1 UP 02:42:ac:11:00:02 <BROADCAST,MULTICAST,UP,LOWER_UP>
# 3. Assign a static IP
sudo ip addr add 192.168.50.10/24 dev eth1
# 4. Verify the address
ip addr show eth1
# Look for inet 192.168.50.10/24 ...
# 5. Test connectivity (if you have a peer on that subnet)
ping -c 3 192.168.50.1
Scenario: Change the default gateway
If your default gateway is wrong, all external traffic fails. Fix it with these commands:
# Remove the old default route
sudo ip route del default
# Add the new one
sudo ip route add default via 203.0.113.1 dev eth0
# Verify
ip route show
# Output includes: default via 203.0.113.1 dev eth0
Scenario: Persist across reboots (manual, for servers without netplan)
ip changes are volatile. To make them permanent on a system using /etc/network/interfaces, edit that file:
sudo nano /etc/network/interfaces
Add a stanza like this:
iface eth1 inet static
address 192.168.50.10
netmask 255.255.255.0
up ip link set dev eth1 up
Then restart networking (or reboot) and verify with ip again.
Compare options / when to choose what
| Tool | Scope | Persistence | Best for |
|---|---|---|---|
ip (iproute2) |
Runtime commands | No (reboot loses changes) | Quick tests, scripting, troubleshooting |
netplan |
Config file → YAML | Yes (after netplan apply) |
Ubuntu/Debian servers needing permanent config |
/etc/network/interfaces |
Config file | Yes (after ifup/reboot) |
Classic Debian/Ubuntu setups |
NetworkManager (nmcli) |
Full network manager | Yes | Desktop/laptop environments with dynamic networks |
Choose ip when you need immediate, peer-level control without daemons. Choose netplan or /etc/network/interfaces when you need a declarative, persistent configuration. For mixed environments, you can script ip commands and place them in startup scripts (e.g., systemd units) to combine flexibility with persistence.
Troubleshooting & edge cases
“RTNETLINK answers: File exists”
You tried to add an IP that’s already assigned. Fix: remove it first or use replace.
sudo ip addr replace 192.168.1.100/24 dev eth0
“RTNETLINK answers: No such device”
You used the wrong interface name. Run ip link show to list valid names (e.g., ens3, wlp2s0), then retype your command.
The interface stays down after ip link set up
The link may be physically disconnected or a driver is missing. Check ip link show for NO-CARRIER. If present, the cable is unplugged or the opposite switch port is off.
Changes vanish after reboot
By design, ip does not persist. That’s why you need netplan or /etc/network/interfaces. If you used ip only, re-apply your commands after boot or encode them in a systemd service.
Permission denied
Most ip modifications require root. Use sudo or run as a user with CAP_NET_ADMIN.
What you learned & what's next
You can now configure network interfaces with ip — from listing links to adding addresses and routes, verifying with ping, and making changes persistent with config files. You understand the mental model of links, addresses, and routes, and you can troubleshoot common failures like missing devices or duplicate IPs. Next in the track, you’ll build on this by learning how to configure DNS resolution and test connectivity with dig and curl — turning your network into a fully diagnosable system.
Practice recap
Now open your terminal and inspect your current network state with ip -br link and ip route. If you have two NICs, try bringing the second one up and assigning a temporary IP (then clean up with ip addr del). For a deeper challenge, write a small script that pings a gateway after setting a new route, and log the output to a file.
Common mistakes
- Forgetting to bring the interface up after assigning an IP — the address exists but traffic won't flow.
- Using the wrong interface name (e.g.,
eth0vsens3) — always checkip link showfirst. - Adding a default route without removing the old one — results in 'RTNETLINK answers: File exists' when you try to add a duplicate.
- Assuming
ipchanges survive a reboot — they don't; you must use config files or scripts for persistence.
Variations
- Use
ip -4orip -6to filter to IPv4 or IPv6 only, reducing noise. - Combine
ipwithjqto parse JSON output (ip -j link show) for scripting. - Use
ip monitorto watch changes in real time — great for debugging daemons that mutate interfaces.
Real-world use cases
- A sysadmin manually brings up a secondary NIC and assigns a static IP to route a backup VPN connection during a network outage.
- A DevOps engineer adds a temporary test IP to a container host to expose a development service without editing permanent config.
- A network automation script periodically checks link states with
ip -br linkto alert on downed production interfaces.
Key takeaways
- The
ipcommand from iproute2 is the modern, universal tool for viewing and changing link, address, and route state. - Always inspect with
ip link,ip addr, andip routebefore making changes to avoid blind troubleshooting. - Bring an interface up with
ip link set <iface> upand assign addresses withip addr add. - Add default routes using
ip route add default via <gw> dev <iface>— and remove old ones first. ipchanges are temporary; persist them with netplan or/etc/network/interfaces.- Troubleshoot quickly by checking for common errors like 'File exists' and 'No such device'.
Keep learning
Related tutorials, quizzes, and articles for this topic.
Discussion
Questions, corrections, and tips help everyone reading this page.
0 comments
Add a comment
No comments yet — start the thread.