The Linux ip command is the modern replacement for the older ifconfig, route, and arp tools, and it gives you complete control over network interfaces, addresses, routes, and neighboring devices. This article explains the most useful ip subcommands, shows real examples, and covers common pitfalls so you can manage networking from the terminal with confidence.
Background: Why the ip Command Exists
The ip command comes from the iproute2 package, which was introduced in Linux kernel 2.2 (around 1999) and became the standard network configuration tool in most distributions. The older ifconfig and route commands are part of net-tools, which has not been actively maintained for years and lacks support for many modern features like policy routing, VRF (Virtual Routing and Forwarding), and network namespaces.
Most current distributions (Ubuntu, Debian, Fedora, RHEL, Arch) include ip by default. If you still see ifconfig it is often installed for compatibility, but the system scripts use ip underneath.
How the ip Command Is Structured
The ip command uses a consistent syntax: ip [OPTIONS] OBJECT COMMAND [ARGS]. The main objects you will use are:
link– network interfaces (physical and virtual)addr(oraddress) – IP addresses assigned to interfacesroute– routing table entriesneigh(orneighbour) – ARP/NDISC cache (neighbor discovery)rule– policy routing rulesnetns– network namespaces
Each object has subcommands like show, add, del, and set. For example, ip addr show displays all addresses, and ip route show displays the routing table.
Essential ip Commands and Examples
Here are the commands you will use most often, with real examples.
1. Show Interface Information
ip link show
ip -s link show eth0
The first shows all interfaces. The second adds statistics (-s) for a specific interface, including TX/RX packets and errors.
2. Show IP Addresses
ip addr show
ip -4 addr show
The first shows IPv4 and IPv6 addresses for all interfaces. The second filters to IPv4 only. You can also specify an interface: ip addr show dev wlan0.
3. Add or Remove an IP Address
sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip addr del 192.168.1.100/24 dev eth0
Note that the prefix length (/24) is required. If you omit it, the command fails with an error.
4. Bring an Interface Up or Down
sudo ip link set eth0 up
sudo ip link set eth0 down
This is the modern replacement for ifconfig eth0 up/down.
5. Show and Manipulate Routes
ip route show
sudo ip route add default via 192.168.1.1
sudo ip route del default
The first shows the routing table. The second adds a default gateway. The third deletes the default route.
6. Inspect the ARP/Neighbor Cache
ip neigh show
This shows the IP-to-MAC mappings that the kernel has learned. You can also add or delete entries manually, but that is rarely needed.
Common Problems and How to Avoid Them
- Forgetting the prefix length –
ip addr add 192.168.1.10fails because the subnet mask is mandatory. Always write/24or whatever prefix applies. - Using ifconfig out of habit –
ifconfigdoes not show all routes or policy rules, and it cannot manage network namespaces. Switch toipfor consistency. - Changes are not persistent –
ipcommands change the live kernel state only. After a reboot, they are lost unless you add them to your distribution’s network configuration (e.g.,/etc/network/interfaceson Debian/Ubuntu, or NetworkManager profiles). - Running as non-root – Most
ipcommands that modify state require root privileges. Usesudo. - Mixing up
linkandaddr–ip link setcontrols the interface state (up/down), whileip addr addassigns an IP. They are different operations.
Advanced Tips: Policy Routing and Namespaces
Two features that ifconfig cannot handle are policy routing and network namespaces.
Policy routing lets you route packets based on source address, packet mark, or other criteria. For example, to route traffic from 192.168.2.0/24 through a different gateway:
sudo ip rule add from 192.168.2.0/24 lookup 100
sudo ip route add default via 10.0.0.1 table 100
This creates a rule that sends matching packets to routing table 100, which has its own default route.
Network namespaces allow you to create isolated network stacks. This is used for containers and VPNs. Basic usage:
sudo ip netns add blue
sudo ip link add veth0 type veth peer name veth1
sudo ip link set veth1 netns blue
sudo ip netns exec blue ip addr show
This creates a namespace called blue, a virtual Ethernet pair, and moves one end into the namespace.
Comparing ip with ifconfig and route
| Task | ip command | Old command |
|---|---|---|
| Show all interfaces | ip link show |
ifconfig -a |
| Show IP addresses | ip addr show |
ifconfig |
| Add IP | ip addr add 192.168.1.2/24 dev eth0 |
ifconfig eth0 192.168.1.2 netmask 255.255.255.0 |
| Show routes | ip route show |
route -n |
| Add default route | ip route add default via 192.168.1.1 |
route add default gw 192.168.1.1 |
| ARP cache | ip neigh show |
arp -a |
The ip syntax is more consistent and supports IPv6 fully, which ifconfig does only partially.
Frequently Asked Questions
How do I make ip changes permanent?
The ip command only affects the running kernel. To make changes survive a reboot, you need to edit your distribution’s network configuration files. On Debian/Ubuntu, edit /etc/network/interfaces. On RHEL/Fedora, use nmcli or edit files in /etc/sysconfig/network-scripts/. If you use NetworkManager, you can also use nmcli connection modify to set IPs and routes.
Why does ip addr show two IPs for one interface?
One is likely IPv4 and the other IPv6. The inet line shows IPv4, and inet6 shows IPv6. If you see multiple IPv4 addresses, it means the interface has multiple addresses assigned, which is allowed. You can remove extras with ip addr del.
How do I see only IPv4 addresses?
Use ip -4 addr show. The -4 option filters to IPv4 only. Similarly, -6 filters to IPv6.
What does the state UP mean in ip link show?
It means the interface is administratively up and has carrier (a cable or Wi-Fi connection). If it says state DOWN, the interface is not active. state UNKNOWN often appears for virtual interfaces like lo or bridges and is normal.
How do I flush all IP addresses from an interface?
Use sudo ip addr flush dev eth0. This removes all IPv4 and IPv6 addresses from that interface. Be careful: you will lose connectivity if you are using that interface.
Can I use ip command to configure Wi-Fi?
No, ip does not handle wireless authentication. For Wi-Fi, use iw (for scanning and connecting) or nmcli (NetworkManager). Once connected, ip can show the resulting IP and routes.
Safety and Best Practices
When experimenting with ip on a remote server, be extremely careful: a wrong ip route del or ip link set down can cut off your SSH session immediately. If you are not physically near the machine, always have a recovery plan (like a console session or a scheduled job to restore the network).
Also, avoid using ip commands in scripts that run at boot unless you fully understand the network initialization order. Use the distribution’s official configuration tools instead, as they integrate with services like NetworkManager and systemd-networkd.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Windows 11 Search: Customize & Use It Fully
- Create Administrator Account in Windows 10: 5 Ways
- Browser Automation Scripts: Step-by-Step Guide
- Fix Camera App Error 0x200f4246 0x80040154
- Android Alerts on Windows 10: How to Get Them
- PL2303 Driver Windows 11 Install Guide