# Problem with routing with multiple gateways

## cheater512

I have two different networks with one interface. One running on 10.0.0.0 and the other on 192.168.0.0 both on eth0.

I've got two separate net connections, one gateway is 10.1.1.1 and the other is 192.168.0.1.

I've followed various sites including here and here and everything looks correct, but if something is bound to the 10.1.1.20 address, it doesnt get any internet.

Can anyone spot a problem with my routes?

```
cheater@pterodactyl ~ $ sudo ip route show

192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.2 

10.0.0.0/8 dev eth0  proto kernel  scope link  src 10.1.1.20 

127.0.0.0/8 via 127.0.0.1 dev lo  scope link 

default via 192.168.0.1 dev eth0 

cheater@pterodactyl ~ $ sudo ip route show table T0

192.168.0.0/24 dev eth0  scope link  src 192.168.0.2 

default via 192.168.0.1 dev eth0 

cheater@pterodactyl ~ $ sudo ip route show table T1

10.0.0.0/8 dev eth0  scope link  src 10.1.1.20 

default via 10.1.1.1 dev eth0 

cheater@pterodactyl ~ $ sudo ip rule show

0:      from all lookup local 

100:    from 192.168.0.1 iif eth0 lookup T0 

101:    from 10.1.1.20 iif eth0 lookup T1 

32766:  from all lookup main 

32767:  from all lookup default 

cheater@pterodactyl ~ $ sudo ip addr show

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 scope host lo

    inet6 ::1/128 scope host 

       valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

    link/ether 00:24:8c:63:5b:1b brd ff:ff:ff:ff:ff:ff

    inet 192.168.0.2/24 brd 192.168.0.255 scope global eth0

    inet 10.1.1.20/8 brd 10.255.255.255 scope global eth0

    inet6 fe80::224:8cff:fe63:5b1b/64 scope link 

       valid_lft forever preferred_lft forever

cheater@pterodactyl ~ $ ping -I 10.1.1.20 google.com

PING google.com (66.102.11.104) from 10.1.1.20 : 56(84) bytes of data.

^C

--- google.com ping statistics ---

27 packets transmitted, 0 received, 100% packet loss, time 26000ms

cheater@pterodactyl ~ $ ping -I 192.168.0.2 google.com

PING google.com (66.102.11.104) from 192.168.0.2 : 56(84) bytes of data.

64 bytes from syd01s01-in-f104.1e100.net (66.102.11.104): icmp_seq=1 ttl=57 time=46.4 ms

64 bytes from syd01s01-in-f104.1e100.net (66.102.11.104): icmp_seq=2 ttl=57 time=144 ms

64 bytes from syd01s01-in-f104.1e100.net (66.102.11.104): icmp_seq=3 ttl=57 time=92.9 ms

^C

--- google.com ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2002ms

rtt min/avg/max/mdev = 46.448/94.529/144.158/39.904 ms
```

I can access both 10.1.1.1 and 192.168.0.1, the 10.1.1.1 gateway rule simply isnt working.

The 192.168.0.1 gateway is working fine.

----------

## cheater512

Has no one done this before?  :Confused: 

----------

## nativemad

I don't know if it has anything to do with the alias interface... I have a separate nic for the second subnet!

----------

## cheater512

Thats what I was afraid of. Most of the examples I see use another interface as well.

I cant see why it shouldnt be possible with a single interface though.

----------

## nativemad

 *cheater512 wrote:*   

> I cant see why it shouldnt be possible with a single interface though.

  Ok, thats true... and it works definitively with vlans on one nic! https://forums.gentoo.org/viewtopic-t-823198-start-0.html But i'm really not sure, if the kernel/routing thingy divides it differently with vlans or aliases...

----------

## cheater512

Ok I fluked the right config.  :Very Happy: 

Its based on what you posted in that other thread. Thanks for that.

```
eth0      Link encap:Ethernet  HWaddr 00:24:8c:63:5b:1b  

          inet addr:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0

          inet6 addr: fe80::224:8cff:fe63:5b1b/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:15893352 errors:0 dropped:0 overruns:0 frame:0

          TX packets:13276741 errors:0 dropped:0 overruns:0 carrier:18

          collisions:0 txqueuelen:1000 

          RX bytes:15415218005 (14.3 GiB)  TX bytes:2227852744 (2.0 GiB)

          Interrupt:28 

eth0:1    Link encap:Ethernet  HWaddr 00:24:8c:63:5b:1b  

          inet addr:10.1.1.20  Bcast:10.255.255.255  Mask:255.0.0.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          Interrupt:28 

```

```
pterodactyl ~ # ip route flush table T1

pterodactyl ~ # ip route flush table T2

pterodactyl ~ # ip route flush table main

pterodactyl ~ # 

pterodactyl ~ # ip route add 10.1.1.0/24 dev eth0:1 src 10.1.1.20

pterodactyl ~ # ip route add 192.168.0.0/24 dev eth0 src 192.168.0.2

pterodactyl ~ # 

pterodactyl ~ # ip route add 10.1.1.0/24 dev eth0:1 src 10.1.1.20 table T2

pterodactyl ~ # ip route add default via 10.1.1.1 dev eth0:1 table T2

pterodactyl ~ # ip rule add from 10.1.1.20 table T2

pterodactyl ~ # 

pterodactyl ~ # ip route add 192.168.0.0/24 dev eth0 src 192.168.0.2 table T1

pterodactyl ~ # ip route add default via 192.168.0.1 dev eth0 table T1

pterodactyl ~ # ip rule add from 192.168.0.2 table T1

pterodactyl ~ # 

pterodactyl ~ # route add default gw 192.168.0.1

pterodactyl ~ # route add default gw 10.1.1.1
```

----------

