---
title: IP Command Cheatsheet
description: "The Linux `ip` command is a powerful utility for network management. It replaces older networking commands like `ifconfig`, `route`, and `arp`, providing a unified toolset to configure, monitor, and troubleshoot network settings on Linux systems. It's commonly used for setting…"
url: "https://www.relianoid.com/resources/knowledge-base/misc/ip-command-cheatsheet/"
updated: "2025-01-22"
category: Misc
---

# IP Command Cheatsheet

The Linux `ip` command is a powerful utility for network management. It replaces older networking commands like `ifconfig`, `route`, and `arp`, providing a unified toolset to configure, monitor, and troubleshoot network settings on Linux systems. It's commonly used for setting up and managing IP addresses, routes, and network interfaces.

## Key Usage and Syntax of the `ip` Command

The `ip` command follows a structured syntax:

`ip [OPTIONS] OBJECT COMMAND`

- **OPTIONS** include flags for further customization, like **-4** for IPv4 or **-6** for IPv6.
- **OBJECT** represents the network item you want to manage, such as **link** (interface), **addr** (address), **route**, etc.
- **COMMAND** is the action you want to perform, like **add**, **show**, **delete**, or **set**.

## `ip` Command Cheatsheet Table

| Command | Description |
| --- | --- |
| `ip link show` | List all network interfaces |
| `ip addr show` | Show IP addresses for all interfaces |
| `ip addr add <IP>/<subnet> dev <iface>` | Add IP address to an interface |
| `ip addr del <IP>/<subnet> dev <iface>` | Remove IP address from an interface |
| `ip route show` | Display all routing table entries |
| `ip route add <dest> via <gateway>` | Add a new route |
| `ip route del <dest>` | Delete an existing route |
| `ip neigh show` | Display neighbor cache (ARP table) |
| `ip rule show` | Show all routing rules |
| `ip rule add from <IP>/<prefix> table <table-id>` | Add a rule to route from a specific source using a table |
| `ip rule del from <IP>/<prefix> table <table-id>` | Delete a rule based on source IP |

## The `ip addr` Subcommand

The `ip addr` command displays and manages IP addresses for network interfaces.

### Show

`ip addr show`

### Example Output

This command lists each network interface with details such as IP address, subnet mask, broadcast address, and link state. Here’s an example:

```
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:1a:02:50 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 brd 192.168.1.255 scope global dynamic enp0s3
valid_lft 86320sec preferred_lft 86320sec
inet6 fe80::a00:27ff:fe1a:250/64 scope link
valid_lft forever preferred_lft forever
```

### Explanation of the Output

- **Interface Info**: The line starting with `2: enp0s3` shows the network interface name (`enp0s3`), along with flags like `BROADCAST`, `MULTICAST`, `UP`, `LOWER_UP`, indicating the interface supports broadcast and multicast and is up and running.
- **MAC Address**: The `link/ether` line displays the MAC address (`08:00:27:1a:02:50`) of the interface.
- **IPv4 Address**: The `inet` line provides the IPv4 address (`192.168.1.10/24`) assigned to the interface, with `/24` indicating the subnet mask.
- **IPv6 Address**: The `inet6` line lists the IPv6 address (`fe80::a00:27ff:fe1a:250`), if available.

This command is essential for checking network interfaces' IP addresses and their status.

### Add

Assign an IP Address to a Network Interface

`ip addr add 192.168.1.100/24 dev enp0s3`

**Output**

This command doesn't provide output if successful, which is common in Linux for configuration commands. If there’s an issue (e.g., an IP conflict), it will display an error message.

### Delete

Remove an IP Address from an Interface

`ip addr del 192.168.1.100/24 dev enp0s3`

**Output**
 Similar to `add`, this command is silent on success. You would only see output if the IP address isn't assigned to the specified interface or if there’s another error.

### Flush

Clear All IP Addresses from an Interface
 `ip addr flush dev enp0s3`

**Output**
 This command gives no output on success. It's typically used to reset the IP configuration of an interface.

## The `ip route` Subcommand

The `ip route` command manages routing entries in the kernel's IP routing table, specifying where packets should be forwarded.

### Show

Display the Routing Table

`ip route show`

**Example Output**

```
default via 192.168.1.1 dev enp0s3 proto static
192.168.1.0/24 dev enp0s3 proto kernel scope link src 192.168.1.10
```

**Explanation of the Output**

- **default via**: Indicates the default route, pointing to the gateway IP (`192.168.1.1`) for outgoing traffic.
- **192.168.1.0/24 dev enp0s3**: Shows a route to the local subnet, handled by the `enp0s3` interface with `192.168.1.10` as the source address.

### **Add**

Create a New Route
 `ip route add 10.0.0.0/24 via 192.168.1.1 dev enp0s3`

**Output**
 This command adds a route to the `10.0.0.0/24` subnet, routing traffic through `192.168.1.1` via `enp0s3`. It won’t display any output on success.

### **Delete**

Remove a Route

`ip route del 10.0.0.0/24`

**Output**
 Removes the specified route, with no output if it succeeds.

### **Flush**

Clear Routing Table Entries
 `ip route flush dev enp0s3`

**Output**
 Flushes all routes for `enp0s3`, typically used for reconfiguration or troubleshooting.

## The `ip rule` Subcommand

### **Show**

List All Routing Rules
 `ip rule show`

**Example Output**

```
0:	from all lookup local
32766:	from all lookup main
32767:	from all lookup default
```

**Explanation of the Output**
 Each line shows a rule with a priority number (e.g., `0`, `32766`). These rules determine which routing table (`local`, `main`, or `default`) to use for different types of traffic.

### **Add**

Define a New Routing Rule

`ip rule add from 192.168.1.100/32 table 100`

**Output**
 This rule directs traffic originating from `192.168.1.100` to consult table `100` for routing. There is no output if the command succeeds.

### **Delete**

Remove a Specific Rule
 `ip rule del from 192.168.1.100/32 table 100`

**Output**
 Deletes the specified rule, with no output if successful.

## The `ip link` Subcommand

### **Show**

Display Link Layer Information
 `ip link show`

**Example Output**

```
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:1a:02:50 brd ff:ff:ff:ff:ff:ff
```

**Explanation of the Output**

- **Interface Info**: Shows the interface name (`enp0s3`), flags (like `UP`), and other parameters like MTU (1500).
- **link/ether**: Displays the MAC address (`08:00:27:1a:02:50`).

### **Set**: Configure Interface Parameters

`ip link set dev enp0s3 up`

**Output**

Sets the interface `enp0s3` to `up`, activating it without displaying any output on success.

### **Add**

Create a Virtual Link (e.g., VLAN)
 `ip link add link enp0s3 name enp0s3.10 type vlan id 10`

**Output**

Creates a VLAN with ID `10` associated with `enp0s3`. No output indicates the command succeeded.

### **Delete**: Remove a Virtual Link

`ip link del dev enp0s3.10`

**Output**
 Deletes the specified virtual link (`enp0s3.10`) with no output if the operation is successful.

## Examples of Using the `ip` Command

### Display Detailed Interface Information

To view all available network interfaces with their IP addresses, states, and additional details:

`ip addr show`

This displays information like IP address, subnet mask, broadcast address, and interface state. You can specify a particular interface, like `ip addr show eth0`, to see details for a single interface.

### Add and Remove IP Addresses

To assign an IP address to a network interface:

`ip addr add 192.168.1.10/24 dev eth0`

This command assigns the IP `192.168.1.10` with a subnet mask of `/24` to `eth0`. This is useful for configuring interfaces or adding virtual IPs on a load balancer for high availability.

To remove an IP address from an interface:
 `ip addr del 192.168.1.10/24 dev eth0`

### Configuring a Static Route

To add a static route, which is essential for directing traffic to specific networks:

`ip route add 192.168.2.0/24 via 192.168.1.1`

This sets a route for the `192.168.2.0/24` network, directing packets through the `192.168.1.1` gateway.

### Configuring IP Neighbor Entries (ARP Table)

To add a permanent entry to the ARP table:

`ip neigh add 192.168.1.5 lladdr 00:11:22:33:44:55 dev eth0`

This manually maps the IP address `192.168.1.5` to the MAC address `00:11:22:33:44:55` on `eth0`.

To delete an ARP entry:

`ip neigh del 192.168.1.5 dev eth0`

### Using `ip rule` for Advanced Routing

The `ip rule` object in the `ip` command is used for policy-based routing, allowing you to set rules that direct packets differently based on source, destination, or other packet attributes. This is especially useful in advanced network setups where multiple routing tables are required, such as multi-homed setups or specific routing policies for certain IP ranges.

For example, to add a rule that routes all packets from a specific source IP (`192.168.1.100`) using a custom routing table (`table 100`):

`ip rule add from 192.168.1.100/32 table 100`

To route traffic to a specific destination using a different table:
 `ip rule add to 10.10.0.0/24 table 100`

To view all rules:
 `ip rule show`

## Using the `ip` Command with RELIANOID Load Balancer

In RELIANOID’s load balancer environment, the `ip` command can be instrumental for network configuration and optimization. Here’s how you can use it effectively:

### **Assigning Virtual IPs**

On a RELIANOID load balancer, virtual IP addresses are crucial for load distribution and high availability. Use the following to assign a VIP:

`ip addr add 10.10.10.1/24 dev eth0`

This creates a virtual IP on the primary interface, helping distribute client requests across multiple backend servers.

### Route Management for Backend Communication

To ensure that the load balancer forwards traffic to backend servers on a specific subnet, configure a static route:

`ip route add 10.10.20.0/24 via 10.10.10.2`

This configuration ensures traffic destined for `10.10.20.0/24` is correctly routed through the specified gateway.

### Monitoring Network Interface Stats

Checking interface statistics is helpful for monitoring traffic load and troubleshooting. For example:

`ip -s link show eth0`
 This command provides real-time stats on packet transmission, errors, and drops on the `eth0` interface, which can help monitor load and adjust balancing settings as needed.

Using the `ip` command, RELIANOID’s load balancer can maintain efficient network configuration, manage IP addresses and routes dynamically, and provide a robust foundation for secure and optimized traffic handling.

## Summary

In summary, the Linux `ip` command is a versatile and essential tool for network configuration and management, allowing fine-grained control over interfaces, routes, and policies. Its flexibility enables efficient handling of complex network setups, like those in load balancer environments, by allowing administrators to manage IP addresses, define routes, and implement policy-based rules. For RELIANOID load balancers, leveraging the `ip` command ensures robust traffic management, optimized routing, and a resilient architecture ready for high availability and efficient load distribution.

### 📄 Download this document in PDF format
