2 nic 2 gateway

Issues related to configuring your network
Post Reply
milos87
Posts: 4
Joined: 2017/03/27 13:43:48

2 nic 2 gateway

Post by milos87 » 2017/03/27 13:50:34

Hello to everyone.

I have just installed PBX. I have problem.
Well, I have 2 NIC in the server, eth1 only for SIP with IP 10.1.xx.xx no internet acess, and the other eth0 with 192.168.xx.xx. LAN + Internet.

ifcfg for eth0
DEVICE=eth0
BOOTPROTO=static
ONBOOT='yes'
IPADDR=192.168.xx.xx
NETMASK=255.255.255.0
GATEWAY=192.168.xx.xx
ZONE=external

ifcfg for eth1
DEVICE=eth1
BOOTPROTO=static
ONBOOT='yes'
IPADDR=10.1.xx.xx
NETMASK=255.255.255.252
GATEWAY=10.1.xx.xx
ZONE=internal

How to setup one gw for eth0 and another for eth1.
Thanks in advance.

User avatar
TrevorH
Site Admin
Posts: 33220
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: 2 nic 2 gateway

Post by TrevorH » 2017/03/27 14:00:05

Don't put a GATEWAY= line in both ifcfg files or the last one to start will set the default route to that and that's not what you want.

You need to create a /etc/sysconfig/network-scripts/route-eth1 file and put ip route add x.x.x.x/yy via gg.aa.te.way/tt] lines in that but without the 'ip route add' portion of that. That will create specific routes for each x.x.x.x/yy subnets that you specify to go via the correct gateway.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

milos87
Posts: 4
Joined: 2017/03/27 13:43:48

Re: 2 nic 2 gateway

Post by milos87 » 2017/03/27 14:49:37

TrevorH, thanks for the quick answer.

Well, i do this.

ifcfg for eth0

Code: Select all

DEVICE=eth0
BOOTPROTO=static
ONBOOT='yes'
IPADDR=192.168.3.xxx
NETMASK=255.255.255.0
GATEWAY=192.168.3.x
ZONE=external
new ifcfg for eth1

Code: Select all

DEVICE=eth1
BOOTPROTO=static
ONBOOT='yes'
IPADDR=10.1.19.22
NETMASK=255.255.255.252
ZONE=internal
create route-eth1

Code: Select all

10.1.19.22/30 via 10.1.19.21
And i got this

#netstat -rn

Code: Select all

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.3.x     0.0.0.0         UG        0 0          0 eth0
10.1.19.20      0.0.0.0         255.255.255.252 U         0 0          0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth1
192.168.3.x     0.0.0.0         255.255.255.0   U         0 0          0 eth0
Last edited by milos87 on 2017/03/28 07:54:43, edited 2 times in total.

User avatar
TrevorH
Site Admin
Posts: 33220
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: 2 nic 2 gateway

Post by TrevorH » 2017/03/27 15:23:07

10.1.19.20 21 22 and 23 are all within 10.1.19.20/30 (which is the same thing as 10.1.19.22/30). It probably doesn't add your route since it already knows it can reach .22 via that interface using the subnet mask. Use ip route get 10.1.19.22 (for example) to see which route it would take to get to your target ip.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

milos87
Posts: 4
Joined: 2017/03/27 13:43:48

Re: 2 nic 2 gateway

Post by milos87 » 2017/03/27 16:36:17

This is what i got

# ip route get 10.1.19.22

Code: Select all

local 10.1.19.22 dev lo  src 10.1.19.22
    cache <local>
But now i have trouble with netmask if i use route-eth1 just like this

Code: Select all

10.1.19.22 via 10.1.19.21
#netstat -rn

Code: Select all

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.3.x     0.0.0.0         UG        0 0          0 eth0
10.1.19.20      0.0.0.0         255.255.255.252 U         0 0          0 eth1
10.1.19.22      10.1.19.21      255.255.255.255 UGH       0 0          0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth1
192.168.3.x     0.0.0.0         255.255.255.0   U         0 0          0 eth0
I also try this for route-eth1 and i lost route.

Code: Select all

ADDRESS0=10.1.19.22
NETMASK0=255.255.255.252
GATEWAY0=10.1.19.21
Last edited by milos87 on 2017/03/28 07:53:59, edited 1 time in total.

User avatar
TrevorH
Site Admin
Posts: 33220
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: 2 nic 2 gateway

Post by TrevorH » 2017/03/27 17:18:50

Wait, .22 appears to be your own ip address?
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

milos87
Posts: 4
Joined: 2017/03/27 13:43:48

Re: 2 nic 2 gateway

Post by milos87 » 2017/03/28 07:47:33

TrevorH wrote:Wait, .22 appears to be your own ip address?
My mistake. I copied the wrong eth1 ip adress here. eth1 IPADDR=10.1.19.22

User avatar
TrevorH
Site Admin
Posts: 33220
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: 2 nic 2 gateway

Post by TrevorH » 2017/03/28 08:38:27

That's exactly the same ip address.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

Post Reply