The ip is a very powerful utility that is used to perform many tasks. Multiple older utilities such as ifconfig and route command were earlier used to perform these functions. In this article I will share different examples to configure network interfaces and routes using ip command.
Changes made using the ip command are temporary and will not persist after a reboot.
This command is mainly used for:
- Temporary network configuration
- Rescue or emergency mode
- Troubleshooting connectivity issues
To make changes permanent, use tools like nmcli command or edit network configuration files.
Quick Cheat Sheet: ip Command
| Task | Command |
|---|---|
| Show all IP addresses | ip addr show |
| Show IP of specific interface | ip addr show dev eth0 |
| Show only IPv4 address | ip -4 addr show |
| Show only IP (clean output) | ip -4 addr show eth0 | grep inet |
| List all interfaces | ip link show |
| Bring interface up | ip link set eth0 up |
| Bring interface down | ip link set eth0 down |
| Change MAC address | ip link set dev eth0 address 00:11:22:33:44:55 |
| Rename interface | ip link set eth0 name eth1 |
| Add IP address | ip addr add 192.168.1.10/24 dev eth0 |
| Add multiple IPs | ip addr add 192.168.1.11/24 dev eth0 |
| Replace IP address | ip addr replace 192.168.1.20/24 dev eth0 |
| Delete IP address | ip addr del 192.168.1.10/24 dev eth0 |
| Remove all IPs | ip addr flush dev eth0 |
| Show routing table | ip route show |
| Add default route | ip route add default via 192.168.1.1 |
| Delete default route | ip route delete default |
| Add route | ip route add 192.168.2.0/24 via 192.168.1.1 |
| Replace route | ip route replace 192.168.2.0/24 via 192.168.1.1 |
| Delete route | ip route delete 192.168.2.0/24 |
| Check route for IP | ip route get 8.8.8.8 |
| Show interface statistics | ip -s link show |
| Flush routing cache | ip route flush cache |
Show and Verify IP Address
Show All Interfaces and IP Addresses
Use the following command to display all network interfaces along with their assigned IP addresses:
ip addr showShow IP of Specific Interface
To display IP address details for a specific interface:
ip addr show dev eth0Show Only IP Address
To display only the IP address without extra details:
ip -4 addr show eth0 | grep inetList Interfaces Based on Type
To filter interfaces based on type such as bridge, bond, or vlan:
ip addr show type bridge
ip addr show type bondManage IP Address on Interface
Add IP Address to Interface
Assign an IP address to a network interface:
ip addr add 192.168.1.10/24 dev eth0Add Multiple IP Addresses
You can assign multiple IP addresses to the same interface:
ip addr add 192.168.1.11/24 dev eth0
ip addr add 192.168.1.12/24 dev eth0Replace Existing IP Address
Replace an existing IP address with a new one:
ip addr replace 192.168.1.20/24 dev eth0Remove IP Address from Interface
Delete a specific IP address from an interface:
ip addr del 192.168.1.10/24 dev eth0Remove All IP Addresses (Flush)
Remove all assigned IP addresses from an interface:
ip addr flush dev eth0Manage Network Interface State
List All Network Interfaces
To list all available network interfaces on the system:
ip link showBring Interface Up or Down
Bring an interface up:
ip link set eth0 upBring an interface down:
ip link set eth0 downChange MAC Address of Interface
To change the MAC address of an interface:
ip link set dev eth0 address 00:11:22:33:44:55Rename Network Interface
To rename a network interface:
ip link set eth0 name eth1Configure Routing in Linux
Show Routing Table
Display the current routing table using ip route command:
ip route showAdd Default Route
Add a default gateway:
ip route add default via 192.168.1.1Delete Default Route
Remove the default route:
ip route delete defaultAdd or Replace Route
Add a new route:
ip route add 192.168.2.0/24 via 192.168.1.1Replace an existing route:
ip route replace 192.168.2.0/24 via 192.168.1.1Check Route for Specific IP
Check which route will be used for a destination:
ip route get 8.8.8.8Real-World Scenarios
Add IP Address to Interface in Linux (Step-by-Step)
- Identify the interface:
ip link show- Assign IP address:
ip addr add 192.168.1.10/24 dev eth0- Verify configuration:
ip addr show dev eth0Bring Network Interface Up After Boot Issue
If a network interface is down after boot:
ip link set eth0 upVerify status:
ip link show eth0Temporary Network Setup in Rescue Mode
Assign temporary IP and gateway:
ip addr add 192.168.1.10/24 dev eth0
ip route add default via 192.168.1.1Assign Multiple IPs for Applications or Services
Assign multiple IP addresses to the same interface:
ip addr add 192.168.1.10/24 dev eth0
ip addr add 192.168.1.11/24 dev eth0Verify assigned IPs:
ip addr show dev eth0Fix Common Errors and Issues
RTNETLINK answers: File exists
This error occurs when a route or configuration already exists.
Fix by deleting the existing route before adding a new one:
ip route delete default
ip route add default via 192.168.1.1You can also use replace instead of add:
ip route replace default via 192.168.1.1Cannot Assign Requested Address
This error appears when the IP address is invalid or the interface is not ready.
Fix:
- Verify the interface name
- Ensure the interface is up
- Check subnet and prefix
ip link set eth0 up
ip addr add 192.168.1.10/24 dev eth0Interface Not Found Error
This happens when the interface name is incorrect.
List available interfaces:
ip link showThen use the correct interface name in your command.
ip command not persistent after reboot
Changes made using the ip command are temporary and will not persist after reboot.
To make changes permanent:
- Use NetworkManager tools like
nmcli - Modify network configuration files based on your distribution
Frequently Asked Questions
1. How do I add an IP address in Linux using ip command?
Use ip addr add 192.168.1.10/24 dev eth0 to assign an IP address to a network interface.2. How do I bring a network interface up in Linux?
Use ip link set eth0 up to bring the interface up.3. What is the difference between ip and ifconfig?
The ip command is a modern replacement for ifconfig, providing more advanced and flexible networking features.4. Why does ip command not persist after reboot?
Changes made using the ip command are temporary and reset after reboot unless configured using persistent network settings tools.Conclusion
The ip command is a powerful and modern utility to manage network interfaces, IP addresses, and routing in Linux. It replaces older tools like ifconfig and route with a unified and flexible approach.
By understanding common commands, real-world scenarios, and troubleshooting techniques, you can efficiently configure and debug network settings in Linux environments.
Official Documentation
For more details, refer to the official manual:









