linux doc: ip command
This commit is contained in:
148
Linux/LPIC1/20-ip.md
Normal file
148
Linux/LPIC1/20-ip.md
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
|
||||||
|
# 🌐 IP Command Cheat Sheet
|
||||||
|
|
||||||
|
The `ip` command is a powerful tool for network configuration and management in Linux. It replaces many of the older `ifconfig` functionalities.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📌 General Syntax
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip [ OPTIONS ] OBJECT { COMMAND | help }
|
||||||
|
```
|
||||||
|
|
||||||
|
**Common OBJECTS:**
|
||||||
|
|
||||||
|
* `addr` – IP addresses
|
||||||
|
* `link` – Network interfaces
|
||||||
|
* `route` – Routing tables
|
||||||
|
* `neigh` – ARP table
|
||||||
|
* `rule`, `netns`, etc.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔍 View Network Information
|
||||||
|
|
||||||
|
### Show All IP Addresses
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip addr show
|
||||||
|
# or shorthand:
|
||||||
|
ip a
|
||||||
|
```
|
||||||
|
|
||||||
|
### Show IP for Specific Interface
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip addr show dev eth0
|
||||||
|
```
|
||||||
|
|
||||||
|
### Show Link Layer Information
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip link show
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 Interface Management
|
||||||
|
|
||||||
|
### Bring Interface Down
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip link set eth0 down
|
||||||
|
```
|
||||||
|
|
||||||
|
### Bring Interface Up
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip link set eth0 up
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🌐 IP Address Configuration
|
||||||
|
|
||||||
|
### Add an IP Address
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip addr add 192.168.1.10/24 dev eth0
|
||||||
|
```
|
||||||
|
|
||||||
|
### Delete an IP Address
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip addr del 192.168.1.10/24 dev eth0
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛣️ Routing
|
||||||
|
|
||||||
|
### Show Routing Table
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip route show
|
||||||
|
```
|
||||||
|
|
||||||
|
### Add a Default Gateway
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip route add default via 192.168.1.1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Add a Specific Route
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip route add 192.168.10.0/24 via 192.168.5.2
|
||||||
|
```
|
||||||
|
|
||||||
|
### Delete a Specific Route
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip route del 192.168.10.0/24 via 192.168.5.2
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧱 Bridge Interface Management
|
||||||
|
|
||||||
|
### Create a Bridge
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip link add name br0 type bridge
|
||||||
|
```
|
||||||
|
|
||||||
|
### Delete a Bridge
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip link delete br0
|
||||||
|
```
|
||||||
|
|
||||||
|
### Bring Bridge Up
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip link set br0 up
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛠️ Example: Set a Static IP Address
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip link set ens33 up
|
||||||
|
ip addr add 10.10.40.12/24 dev ens33
|
||||||
|
ip route add default via 10.10.40.1
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### ✅ Tip:
|
||||||
|
|
||||||
|
Always verify with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ip a
|
||||||
|
ip r
|
||||||
|
```
|
||||||
|
|
||||||
Reference in New Issue
Block a user