0
0
Linux-cliHow-ToBeginner · 3 min read

How to Use ip Command in Linux: Syntax and Examples

The ip command in Linux is used to show and manipulate routing, devices, and tunnels. You can use it to display network interfaces, assign IP addresses, and manage routes with simple syntax like ip addr or ip route.
📐

Syntax

The basic syntax of the ip command is:

  • ip [ OPTIONS ] OBJECT { COMMAND | help }
  • OBJECT: The network object to manage, such as addr (addresses), link (interfaces), route (routing table).
  • COMMAND: The action to perform, like show, add, del.
  • OPTIONS: Optional flags like -4 for IPv4 or -6 for IPv6.

This structure lets you perform many network tasks in a clear way.

bash
ip [ OPTIONS ] OBJECT { COMMAND | help }
💻

Example

This example shows how to display all network interfaces and their IP addresses using ip addr show. It helps you see your current network setup.

bash
ip addr show
Output
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 01:23:45:67:89:ab brd ff:ff:ff:ff:ff:ff inet 192.168.1.100/24 brd 192.168.1.255 scope global dynamic eth0 valid_lft 86392sec preferred_lft 86392sec inet6 fe80::1234:5678:9abc:def0/64 scope link valid_lft forever preferred_lft forever
⚠️

Common Pitfalls

Common mistakes when using ip include:

  • Trying to use ifconfig commands instead of ip syntax.
  • Forgetting to run commands with sudo when changing settings.
  • Mixing IPv4 and IPv6 options incorrectly.
  • Not specifying the correct interface name.

Always check interface names with ip link show before making changes.

bash
Wrong:
ip addr add 192.168.1.10 dev eth0

Right:
sudo ip addr add 192.168.1.10/24 dev eth0
📊

Quick Reference

CommandDescription
ip addr showShow all IP addresses on all interfaces
ip link showShow all network interfaces
sudo ip addr add 192.168.1.10/24 dev eth0Add IP address to interface
sudo ip addr del 192.168.1.10/24 dev eth0Remove IP address from interface
ip route showDisplay routing table
sudo ip route add default via 192.168.1.1Add default gateway route

Key Takeaways

Use ip command to manage network interfaces, addresses, and routes in Linux.
Always check interface names with ip link show before making changes.
Use sudo when adding or deleting network settings to avoid permission errors.
Remember the syntax: ip [options] object command for clear commands.
Refer to ip addr show and ip route show to view current network configuration.