0

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
 ===========================================================================
Shane Madden
  • 114,520
  • 13
  • 181
  • 251
seeker
  • 231
  • 1
  • 3
  • 13
  • give output of `ROUTE PRINT` – ETL Jan 22 '15 at 21:05
  • @ETL updated my post – seeker Jan 22 '15 at 21:11
  • Uhh, `192.168.1.1` is in the `Interface` column.. is that this system? – Shane Madden Jan 22 '15 at 21:30
  • What is your IP address and subnet mask? –  Jan 22 '15 at 21:32
  • 2
    It looks to me like you don't have an IP address defined for 192.168.2.1 on this host. Therefore your traffic would have to go via 192.168.1.1 to reach 192.168.2.1 in the first place. – john Jan 22 '15 at 21:32
  • @ChrisV, My IP is `192.168.1.1` – seeker Jan 22 '15 at 21:43
  • Assuming a 24 bit mask (you didn't say) this will not work because the 192.168.2.1 gateway is not directly connected (as suggested by @john ). –  Jan 22 '15 at 21:49
  • 2
    If this computer doesn't have an interface and/or an ip address in the 192.168.2.x subnet then you can't get there without going through the DG at 192.168.1.1. Additionally, routing is best accomplished at the router not at your hosts. Where is the 192.168.2.1 router in relation to the 192.168.1.x network and router? – joeqwerty Jan 22 '15 at 22:10

0 Answers0