我需要设置以下规则:
- 如果 IP 在 192.168.0.0-192.168.0.255 范围内,则从网关 1 路由 iut(假设为 192.168.2.1)
- 否则,对于所有其他 IP 地址,都通过默认网关 192.168.1.1 进行路由
我尝试进行如下设置:
route -p add 192.168.0.0 mask 255.255.255.0 192.168.2.1 metric 1
route -p add 0.0.0.0 mask 0.0.0.0 192.168.1.1 metric 2
但是这不管用——当我跟踪路由时,192.168.0.5
数据包经过了192.168.1.1
网关。你能帮我解决这个问题吗?
更新这是完整的路线表
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.1 7
127.0.0.0 255.0.0.0 On-link 127.0.0.1 306
127.0.0.1 255.255.255.255 On-link 127.0.0.1 306
127.255.255.255 255.255.255.255 On-link 127.0.0.1 306
192.168.1.1 255.255.255.0 On-link 192.168.1.1 261
192.168.1.1 255.255.255.255 On-link 192.168.1.1 261
192.168.1.1 255.255.255.255 On-link 192.168.1.1 261
169.254.129.139 255.255.255.255 On-link 169.254.129.139 286
192.168.0.0 255.255.255.0 192.168.2.1 192.168.1.1 6
192.168.168.1 255.255.255.255 192.168.2.1 192.168.1.1 31
224.0.0.0 240.0.0.0 On-link 127.0.0.1 306
224.0.0.0 240.0.0.0 On-link 192.168.1.1 261
224.0.0.0 240.0.0.0 On-link 169.254.129.139 286
255.255.255.255 255.255.255.255 On-link 127.0.0.1 306
255.255.255.255 255.255.255.255 On-link 192.168.1.1 261
255.255.255.255 255.255.255.255 On-link 169.254.129.139 286
===========================================================================
Persistent Routes:
Network Address Netmask Gateway Address Metric
0.0.0.0 0.0.0.0 192.168.1.1 2
192.168.0.0 255.255.255.0 192.168.2.1 1
===========================================================================