Need of Two default gateway

Issues related to configuring your network
Anilbakhtani
Posts: 12
Joined: 2021/02/09 13:57:36

Need of Two default gateway

Post by Anilbakhtani » 2021/06/13 07:50:08

Hello team,
I am using Centos 8 with two network card.
I tried but still not resolved, I need two default gateway
One card is connected to Pri (sip pri) , as default gateway
second card for local network/internet.

ens128: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.14 netmask 255.255.255.0 broadcast 192.168.1.255


ens133: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.204.55.22 netmask 255.255.255.252 broadcast 10.204.55.23

ens133 using with default gateway

ip route add 192.168.1.0/24 dev ens128 src 192.168.1.14 table rt2
ip route add default via 192.168.1.1 dev ens128 table rt2
ip rule add from 192.168.1.14/32 table rt2
ip rule add to 192.168.1.14/32 table rt2

cat /etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
1 rt2

pls guide

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

Re: Need of Two default gateway

Post by jlehtone » 2021/06/13 08:14:49

Lets say that you need to connect to IP x.y.z.w. The x.y.z.w is not in any link-local subnet.
Could there be x.y.z.w in both Pri and internet?
Which interface should the outgoing packet use?

Anilbakhtani
Posts: 12
Joined: 2021/02/09 13:57:36

Re: Need of Two default gateway

Post by Anilbakhtani » 2021/06/13 08:56:48

thanks for reply
ens133: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.204.55.22 netmask 255.255.255.252 broadcast 10.204.55.23

above network is belong to its gateway 10.204.55.21 and 10.232.130.170 only for connectivity with Airtel Pri service provider.

My internet for all other work/services should work with second network . 192.168.1.14

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

Re: Need of Two default gateway

Post by jlehtone » 2021/06/13 10:24:28

Code: Select all

$ ipcalc -n -b -p 10.204.55.22 255.255.255.252
PREFIX=30
BROADCAST=10.204.55.23
NETWORK=10.204.55.20
Very small subnet:
* 10.204.55.20 network address
* 10.204.55.21 router
* 10.204.55.22 your machine
* 10.204.55.23 broadcast address

If I understood correctly, the address 10.232.130.170 should be reached through router 10.204.55.21.
You don't need default route to reach 10.232.130.170.
You can use a static route: 10.232.130.170 via 10.204.55.21

Are there any other addresses that are behind router 10.204.55.21?
If you know them, then you could add static routes for them too.

Anilbakhtani
Posts: 12
Joined: 2021/02/09 13:57:36

Re: Need of Two default gateway

Post by Anilbakhtani » 2021/06/13 12:23:32

thanks for reply.
pls guide to create static route file for same as you understand.
I am waiting for final setting for my both card to go ahead as per requirement.

thanks

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

Re: Need of Two default gateway

Post by jlehtone » 2021/06/13 14:22:05


Anilbakhtani
Posts: 12
Joined: 2021/02/09 13:57:36

Re: Need of Two default gateway

Post by Anilbakhtani » 2021/06/23 13:51:28

Hello , following is my current list

0.0.0.0 via 192.168.1.1 dev ens128 proto static metric 102
default via 10.204.55.21 dev ens133 proto static metric 101
default via 192.168.1.1 dev ens128 proto static metric 102
10.204.55.20/30 dev ens133 proto kernel scope link src 10.204.55.22 metric 101
10.232.130.170 via 10.204.55.21 dev ens133 proto static metric 101
142.250.71.46 via 192.168.1.1 dev ens128 proto static metric 102
142.250.71.48 via 192.168.1.1 dev ens128 proto static metric 102
164.100.88.149 via 192.168.1.1 dev ens128 proto static metric 102
164.100.213.171 via 192.168.1.1 dev ens128 proto static metric 102
192.168.1.0/24 dev ens128 proto kernel scope link src 192.168.1.14 metric 102
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
202.153.32.16 via 192.168.1.1 dev ens128 proto static metric 102

I am using static routes as of now , I want to use internet through 192.168 network.
My default gateway would be default via 10.204.55.21 , connected with Pri line
I tried few nmcli commands but still need solution
pls see
thanks

Anilbakhtani
Posts: 12
Joined: 2021/02/09 13:57:36

Re: Need of Two default gateway

Post by Anilbakhtani » 2021/06/23 14:06:34

ping yahoo.com -I 192.168.1.14
PING yahoo.com (74.6.231.20) from 192.168.1.14 : 56(84) bytes of data.



not working.

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

Re: Need of Two default gateway

Post by jlehtone » 2021/06/23 14:21:44

Anilbakhtani wrote:
2021/06/23 13:51:28
I want to use internet through 192.168 network.
You want to use 192.168 network, i.e. you want to send to other networks via 192.168.1.1. That is the default.

Which basically means that you only need these routes:

Code: Select all

default via 192.168.1.1
10.204.55.20/30 dev ens133 proto kernel scope link src 10.204.55.22 metric 101
10.232.130.170 via 10.204.55.21
192.168.1.0/24 dev ens128 proto kernel scope link src 192.168.1.14 metric 102
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
Do not set gateway for the ens133 connection. If you have one now, remove it:

Code: Select all

nmcli con mod ens133 ipv4.gateway ""
If the one static route: 10.232.130.170 via 10.204.55.21 is not sufficient, then add
necessary x via 10.204.55.21 routes.

Anilbakhtani
Posts: 12
Joined: 2021/02/09 13:57:36

Re: Need of Two default gateway

Post by Anilbakhtani » 2021/06/23 14:27:40

Thanks for reply,

Issue is ens133 is connected to PRI line (Sip Pri) , and its need default connection.
if I undefault same , pri line trop working properly.

So In this case , default would be always ens133 and I need to use internet for second network.

Can we use iptables for my issue, pls guide .

Post Reply

Return to “CentOS 8 - Networking Support”