107 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			107 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
| ## router table
 | ||
| 
 | ||
| | device  | eth  | ip          |
 | ||
| | ------- | ---- | ----------- |
 | ||
| | PC1     | eth1 | 10.5.0.1/24 |
 | ||
| | PC2     | eth1 | 10.5.1.2/24 |
 | ||
| | router1 | eth1 | 10.5.0.0/24 |
 | ||
| | router2 | eth1 | 10.5.1.1/24 |
 | ||
| 
 | ||
| router -> router
 | ||
| 
 | ||
| ```
 | ||
| sender #   sender eth #    receiver #      receiver eth #          losses #                                            
 | ||
| 1       2       2       2       20                                                                                           
 | ||
| 1       3       3       2       20                                                                                           
 | ||
| 1       4       4       1       0                                                                                            
 | ||
| 2       2       1       2       20                                                                                           
 | ||
| 2       3       3       3       0                                                                                            
 | ||
| 2       4       4       2       0                                                                                            
 | ||
| 3       2       1       3       0                                                                                            
 | ||
| 3       3       2       3       0                                                                                            
 | ||
| 3       4       4       3       0                                                                                            
 | ||
| 4       1       1       4       0                                                                                            
 | ||
| 4       2       2       4       0                                                                                            
 | ||
| 4       3       3       4       0 
 | ||
| ```
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
| router -> pc
 | ||
| 
 | ||
| ```
 | ||
| 
 | ||
| sender #   sender eth #    receiver #   receiver eth #  losses #                                                             │
 | ||
| 1          1               1            1               0                                                                    │
 | ||
| 2          1               1            1               0                                                                    │
 | ||
| 2          1               2            1               0                                                                    │
 | ||
| 2          1               3            1               0                                                                    │
 | ||
| 3          1               3            1               0   
 | ||
| ```
 | ||
| 
 | ||
| pc->pc
 | ||
| 
 | ||
| ```
 | ||
| 
 | ||
| sender #   sender eth #    receiver #   receiver eth #  losses #                                                             
 | ||
| 2          1               1            1               0                                                                    
 | ||
| 2          1               3            1               0     
 | ||
| ```
 | ||
| 
 | ||
| pc->router
 | ||
| 
 | ||
| ```
 | ||
| sender #   sender eth #    receiver #   receiver eth #  losses #
 | ||
| 2          1               2            1               0
 | ||
| 3          1               3            1               0
 | ||
| 
 | ||
| ```
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
| ### 主要工具:`ip`
 | ||
| 
 | ||
| **`ip`** 是 IPRoute2 工具集中最常用的命令,能够管理和配置 IP 地址、路由、链路等多种网络参数。与旧版的 `ifconfig` 和 `route` 命令相比,`ip` 更加灵活和强大。
 | ||
| 
 | ||
| ### **`ip` 命令的常见用法**
 | ||
| 
 | ||
| 1. **查看网络接口**:
 | ||
|    
 | ||
|    ```bash
 | ||
|    ip link show
 | ||
|    ```
 | ||
|    显示所有网络接口及其状态,类似于 `ifconfig`。
 | ||
|    
 | ||
| 2. **启用或禁用网络接口**:
 | ||
|    ```bash
 | ||
|    sudo ip link set dev eth0 up    # 启用接口
 | ||
|    sudo ip link set dev eth0 down  # 禁用接口
 | ||
|    ```
 | ||
| 
 | ||
| 3. **添加/删除 IP 地址**:
 | ||
|    ```bash
 | ||
|    sudo ip address add 192.168.1.10/24 dev eth0  # 为 eth0 接口添加 IP 地址
 | ||
|    sudo ip address del 192.168.1.10/24 dev eth0  # 从 eth0 接口删除 IP 地址
 | ||
|    ```
 | ||
| 
 | ||
| 4. **显示路由表**:
 | ||
|    
 | ||
|    ```bash
 | ||
|    ip route show
 | ||
|    ```
 | ||
|    显示当前的路由表,类似于 `route` 命令。
 | ||
|    
 | ||
| 5. **添加/删除路由**:
 | ||
|    ```bash
 | ||
|    sudo ip route add 192.168.1.0/24 via 192.168.1.1  # 添加路由条目
 | ||
|    sudo ip route del 192.168.1.0/24                 # 删除路由条目
 | ||
|    ```
 | ||
| 
 | ||
| 6. **查看 ARP 表**:
 | ||
|    ```bash
 | ||
|    ip neighbor show
 | ||
|    ```
 | ||
|    显示 ARP 表,类似于 `arp -a`。
 |