I have setup a box/small server with three interfaces. One interface leads to an internal net and owns a default route in routing table rt1. Another interface is connected to a Fritz!Box and leads into the internet and also has a default route in routing table rt2.
I have put up two default gateways (table rt1 and rt2) and now I want to ping something in the internet on a certain interface (eth0.103), which leads to the Fritz!Box (and the internet), or even on both, but that does not work, although traceroute and even an SSH connection are working on this interface. I mean, I can even contact/connect to that box (eth0.103) from outside/over the Fritz!Box/internet. Also, on eth0.101 there is no routing or pinging happening.
The Fritz!Box has the address 192.168.178.1 and eth0.103 (192.168.178.20) is connected to it directly.
command
ping -I eth0.103 8.8.8.8
ping -I eth0.101 8.8.8.8
/etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
1 rt1
2 rt2
/etc/network/interfaces
auto eth0.101
iface eth0.101 inet static
address 172.19.2.2
netmask 255.255.255.0
post-up ip route add 172.19.2.0/24 dev eth0.101 src 172.19.2.2 table rt1
post-up ip route add default via 172.19.2.1 dev eth0.101 table rt1
post-up ip rule add from 172.19.2.2/32 table rt1
post-up ip rule add to 172.19.2.2/32 table rt1
auto eth0.102
iface eth0.102 inet manual
auto eth0.103
iface eth0.103 inet static
address 192.168.178.20
netmask 255.255.255.0
post-up ip route add 192.168.178.0/24 dev eth0.103 src 192.168.178.20 table rt2
post-up ip route add default via 192.168.178.1 dev eth0.103 table rt2
post-up ip rule add from 192.168.178.20/32 table rt2
post-up ip rule add to 192.168.178.20/32 table rt2
auto br0
iface br0 inet static
bridge_ports eth0.102 wlan0
bridge_waitport 0
address 192.168.1.254
network 192.168.1.0
netmask 255.255.255.0
ip route show
172.19.2.0/24 dev eth0.101 proto kernel scope link src 172.19.2.2
192.168.1.0/24 dev br0 proto kernel scope link src 192.168.1.254
192.168.178.0/24 dev eth0.103 proto kernel scope link src 192.168.178.20
ip route show table rt1
default via 172.19.2.1 dev eth0.101
172.19.2.0/24 dev eth0.101 scope link src 172.19.2.2
ip route show table rt2
default via 192.168.178.1 dev eth0.103
192.168.178.0/24 dev eth0.103 scope link src 192.168.178.20
I cannot figure out, if I did something wrong with those gateways or the routing rules/tables maybe. Also, I find it weird, that I can connect over the Fritz!Box's public IP address to the server, while pinging from it does not work. Thank you in advance, guys.
Alright, with a lot of googling and reading on Linux sites and here in Stack Overflow I found the solution.
The routing tables were fine, but somehow not transmitting the default gateways to the main table. Therefore I could not ping or achieve anything, but still traceroute was working. Even static routes were working.
So, I added those two important lines (with the metric values) in /etc/network/interfaces and now the default gateways of both routing tables are transmitted to the main routing table.
/etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
101 rt1
102 rt2
/etc/network/interfaces
auto eth0.101
iface eth0.101 inet static
address 172.19.2.2
netmask 255.255.255.0
post-up ip route add 172.19.2.0/24 dev eth0.101 src 172.19.2.2 table rt1
post-up ip route add default via 172.19.2.1 dev eth0.101 table rt1
post-up ip rule add from 172.19.2.2/32 table rt1
post-up ip rule add to 172.19.2.2/32 table rt1
post-up ip route add default via 172.19.2.1 metric 100 dev eth0.101
post-down ip rule del from 0/0 to 0/0 table rt1
post-down ip rule del from 0/0 to 0/0 table rt1
auto eth0.102
iface eth0.102 inet manual
auto eth0.103
iface eth0.103 inet static
address 192.168.178.20
netmask 255.255.255.0
post-up ip route add 192.168.178.0/24 dev eth0.103 src 192.168.178.20 table rt2
post-up ip route add default via 192.168.178.1 dev eth0.103 table rt2
post-up ip rule add from 192.168.178.20/32 table rt2
post-up ip rule add to 192.168.178.20/32 table rt2
post-up ip route add default via 192.168.178.1 metric 101 dev eth0.103
post-down ip rule del from 0/0 to 0/0 table rt2
post-down ip rule del from 0/0 to 0/0 table rt2
auto wlan0
iface wlan0 inet manual
auto br0
iface br0 inet static
bridge_ports eth0.102 wlan0
bridge_waitport 0
address 192.168.1.254
netmask 255.255.255.0