Two interfaces, two gateways

Issues related to configuring your network
Post Reply
jeremani
Posts: 2
Joined: 2021/01/24 08:43:21

Two interfaces, two gateways

Post by jeremani » 2021/01/24 09:46:11

Hello everybody,

Sorry, I know, this has been discussed before, but I still can't get it to work and need to ask for help now.

CentOS 7.9 on a server with two interfaces eno1, eno2.
I want both interfaces to access the internet via their respective gateways.

ifcfg-eno1

Code: Select all

NM_CONTROLLED=NO
TYPE=Ethernet
HWADDR=MA:CA:DD:RE:SS
NAME=eno1
DEVICE=eno1
ONBOOT=yes
BOOTPROTO=none
ZONE=public
IPADDR=192.168.6.12
PREFIX=24
GATEWAY=192.168.6.99
DNS1=192.168.6.99
ifcfg-eno2

Code: Select all

NM_CONTROLLED=NO
TYPE=Ethernet
HWADDR=MA:CA:DD:RE:SS
NAME=eno2
DEVICE=eno2
ONBOOT=yes
BOOTPROTO=none
ZONE=public
IPADDR=10.1.1.12
PREFIX=8
GATEWAY=10.1.1.99
DNS1=10.1.1.99

Code: Select all

# ip r
default via 10.1.1.99 dev eno2
10.0.0.0/8 dev eno2 proto kernel scope link src 10.1.1.12
169.254.0.0/16 dev eno1 scope link metric 1002
169.254.0.0/16 dev eno2 scope link metric 1003
192.168.6.0/24 dev eno1 proto kernel scope link src 192.168.6.12
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1

Code: Select all

# ping google.com -c4 -I eno2
PING google.com (172.217.18.14) from 10.1.1.12 eno2: 56(84) bytes of data.
64 bytes from fra15s28-in-f14.1e100.net (172.217.18.14): icmp_seq=1 ttl=116 time=16.1 ms
64 bytes from fra15s28-in-f14.1e100.net (172.217.18.14): icmp_seq=2 ttl=116 time=15.8 ms
64 bytes from fra15s28-in-f14.1e100.net (172.217.18.14): icmp_seq=3 ttl=116 time=15.5 ms
64 bytes from fra15s28-in-f14.1e100.net (172.217.18.14): icmp_seq=4 ttl=116 time=15.7 ms

Code: Select all

# ping google.com -c4 -I eno1
PING google.com (172.217.18.14) from 192.168.6.12 eno1: 56(84) bytes of data.

--- google.com ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 2999ms
Both can actually access the internet when the other interface is disabled.
With both interfaces enabled only eno2 has internet access. With the above configuration and yet no static routes being set this is what I expected.

I have tried to set static routes in a few different ways (route-enoX, rule-enoX, /etc/iproute2/rt_tables; with NetworkManager enabled via nmtui) but still to no avail. So I'd really appreciate if someone could help me how to do this properly.

Thanks in advance

User avatar
jlehtone
Posts: 4523
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Two interfaces, two gateways

Post by jlehtone » 2021/01/24 15:39:21

jeremani wrote:
2021/01/24 09:46:11
I want both interfaces to access the internet via their respective gateways.
The fundamental issue is that you have one machine and therefore only one default route.

The default route is where the machine sends packets for which it does not have more specific routes (e.g. link-local or static). By definition, there can be only one default.


I don't say that it is totally impossible. Just quite mind-boggling.

jeremani
Posts: 2
Joined: 2021/01/24 08:43:21

Re: Two interfaces, two gateways

Post by jeremani » 2021/01/24 16:15:04

Yes, that's indeed clear to me. I have already read many posts, tutorials and such about that. Policy-based routing seems to be the path to follow.
Currently I have enabled/started NetworkManager and NetworkManager-dispatcher again. Here's what I have at the moment, Internet now only via eno1. The route for eno2 is being ignored. I have set HWADDR and UUID btw.

ifcfg-eno1

Code: Select all

TYPE=Ethernet
NAME=eno1
DEVICE=eno1
ONBOOT=yes
BOOTPROTO=none

IPADDR=192.168.6.12
PREFIX=24
GATEWAY=192.168.6.99
DNS1=192.168.6.99
ZONE=public
DEFROUTE=yes
ifcfg-eno2

Code: Select all

TYPE=Ethernet
NAME=eno2
DEVICE=eno2
BOOTPROTO=none
ONBOOT=yes

IPADDR=10.1.1.12
PREFIX=24
DNS1=10.1.1.99
ZONE=public
DEFROUTE=no
route-eno2

Code: Select all

10.1.1.0/24 dev eno2 scope link table rt2
default via 10.1.1.99 dev eno2 table rt2
rule-eno2

Code: Select all

from 10.1.1.0/24 table rt2

Code: Select all

# ip route show table rt2
default via 10.1.1.99 dev eno2
10.1.1.0/24 dev eno2 scope link
#
# ip rule
0:      from all lookup local
32765:  from 10.1.1.0/24 lookup rt2
32766:  from all lookup main
32767:  from all lookup default
#
# netstat -rn
Kernel IP Routingtable
Dest		Router		Genmask		Flags   MSS Window	irtt	Iface
0.0.0.0		192.168.6.99	0.0.0.0		UG	0 0          	0 	eno1
10.1.1.0	0.0.0.0		255.255.255.0	U	0 0          	0 	eno2
192.168.6.0	0.0.0.0		255.255.255.0	U	0 0          	0 	eno1
192.168.122.0	0.0.0.0		255.255.255.0	U	0 0          	0 	virbr0

User avatar
jlehtone
Posts: 4523
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Two interfaces, two gateways

Post by jlehtone » 2021/01/24 18:37:12

jeremani wrote:
2021/01/24 16:15:04
The route for eno2 is being ignored.
How do you test that?

AFAIK, your rule and routes are meaningful only when routing a reply. For example:
Some external machine has sent a packet to your 10.1.1.12. Process in your machine sends a reply.
Initially the SRC in that reply is probably 10.1.1.12. Due to your rule, table rt2 should be used to
make the routing decision.

Post Reply