Linux command
ip-route-add 命令
安全
权限或系统影响较大,执行前请核对目标。
常用示例
Example
sudo ip route add default via [gateway_ip]
Example
sudo ip route add default dev [eth0]
Example
sudo ip route add [192.168.1.0/24] via [gateway_ip] dev [eth0]
Example
sudo ip route add [192.168.2.0/24] via [gateway_ip] metric [100]
Example
sudo ip route add [10.0.0.0/8] dev [eth0] table [100]
Example
sudo ip route add [192.168.1.0/24] dev [eth0] src [192.168.1.5]
说明
ip route add adds new routes to the kernel routing tables. Routes determine how packets are forwarded to their destinations based on the destination address. A route specifies either a gateway (next-hop router) to forward packets to, or an interface for directly connected networks. Multiple routing tables can be used for policy routing.
参数
- default
- Default route (0.0.0.0/0 or ::/0)
- via _GATEWAY_
- Next-hop gateway address
- dev _DEVICE_
- Output device name
- table _TABLE_
- Routing table (number or name)
- metric _NUM_
- Route preference (lower = preferred)
- src _ADDRESS_
- Preferred source address
- proto _PROTOCOL_
- Routing protocol identifier (static, boot, dhcp, etc.)
- scope _SCOPE_
- Scope of the route (global, link, host)
- mtu _NUM_
- Maximum Transmission Unit for the route
- nexthop _NEXTHOP_
- Define multipath route with multiple next hops
FAQ
What is the ip-route-add command used for?
ip route add adds new routes to the kernel routing tables. Routes determine how packets are forwarded to their destinations based on the destination address. A route specifies either a gateway (next-hop router) to forward packets to, or an interface for directly connected networks. Multiple routing tables can be used for policy routing.
How do I run a basic ip-route-add example?
Run `sudo ip route add default via [gateway_ip]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does default do in ip-route-add?
Default route (0.0.0.0/0 or ::/0)