0

I have a centos 7 server, with 4 interfaces. i am trying to give each of these interfaces a different ip, gateway and netmask.

I want each interface to respond requests itself. so if a request has came in on interface enp2s0, i want enp2s0 to respond to request.

I have one interface for Management (guess enp2s0) and it should be only available in internal network and stuff like that.

So, i have a default gateway set in /etc/sysconfigs/network :

GATEWAY=192.168.0.1

in the test case, 192.168.0.1 has access to internet.

then, i have my interfaces setup this way:

enp2s0 (static ip: 192.168.0.176):

192.168.0.0/24 via 192.168.0.176 dev enp2s0

enp3s0(static ip: 192.168.50.40):

default via 192.168.0.1 dev enp3s0
192.168.50.0/24 via 192.168.50.1 dev enp3s0

enp4s0 (static ip: 192.168.30.40):

192.168.30.0/24 via 192.168.30.1 dev enp4s0

and this is my ip route show all command:

default via 192.168.0.1 dev enp2s0  proto static  metric 100 
default via 192.168.0.1 dev enp4s0  proto static  metric 101 
192.168.0.0/24 dev enp2s0  proto kernel  scope link  src 192.168.0.176  metric 100 
192.168.0.1 dev enp4s0  proto static  scope link  metric 100 
192.168.30.0/24 dev enp4s0  proto kernel  scope link  src 192.168.30.40  metric 100 
192.168.50.0/24 dev enp3s0  proto kernel  scope link  src 192.168.50.40  metric 100

what should i change? i want to be able to respond to all requests coming in, from the same interface that got the request.

all of the interfaces are connected to a router, so i don't have ip range matching problem, and can receive all the traffic.

senaps
  • 143
  • 1
  • 2
  • 7
  • By default Linux uses a single TCP/IP stack and routing table shared by all interfaces on your system. That is usually very efficient, but it sounds like you want to have each interface completely independent from the others, with their own ip-address and different (default) routes. You usually achieve that by creating separate network namespaces. See for instance http://man7.org/linux/man-pages/man8/ip-netns.8.html – HBruijn Jun 13 '18 at 07:15
  • @HBruijn since no one answered, is there anyway to do it with persistent routes? i am trying to code a script that does it, so we can change networking settings instantly and easily, we have previously have done it with route tables in each `ifcfg-X` file, but i came up with static routes. – senaps Jun 17 '18 at 06:09

1 Answers1

1

I have configured static and persistent rule using nmtui utility. You can play around with route metric to give proper gateway precedence. Attached an example of route config across two NICs. And here is the sample o/p:

[root@demo-host ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.15.1.1      0.0.0.0         UG    100    0        0 ens224
10.10.0.0       192.168.7.254   255.255.255.0   UG    0      0        0 ens192
10.70.0.0       192.168.7.254   255.255.255.0   UG    0      0        0 ens192
172.15.1.0      0.0.0.0         255.255.255.0   U     100    0        0 ens224
192.168.7.0     0.0.0.0         255.255.255.0   U     100    0        0 ens192
192.168.8.0     192.168.7.254   255.255.255.0   UG    0      0        0 ens192
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
[root@demo-host ~]#

nmtui edit ens192

m_r_nadh
  • 11
  • 3
  • I needed a way to change the routes from the code. while this method of yours works, is not the correct answer to my question. thank you for the answer, I gave you a + for the question. – senaps Jun 01 '19 at 04:47