I need to set up the following rules:
- If IP is in range 192.168.0.0-192.168.0.255 then route iut from gateway 1 (let's say 192.168.2.1)
- otherwise for all other IP addresses route it through default gateway 192.168.1.1
I tried to set up this:
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
However this doesn't work - when I traceroute to 192.168.0.5
the packet goes through 192.168.1.1
gateway. Could you help me to resolve the problem?
UPDATE here is full routes table
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
===========================================================================