0

I have dual NIC machine running CentOS 6.7 and asterisk. First NIC is for LAN & Internet connectivity and second is for trunk provider's connectivity. Both of these have gateways configured. I don't seem to be able to access the Internet as the traffic is routed thru the Second NIC's gateway, also the second NIC is taken as default route by the kernel. I do not understand how default gateway is assigned in this case and what correction should I do.

Eth0 Config:

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.0.1
NETMASK=255.255.255.0
GATEWAY=192.168.0.100
DNS1=8.8.8.8
DNS2=8.8.4.4

Eth1 Config:

DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=10.165.11.139
NETMASK=255.255.255.248
GATEWAY=10.165.11.137

Ping Internet

ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
From 10.165.11.137 icmp_seq=1 Destination Net Unreachable

Ping SIP Trunk

ping 10.232.130.170
PING 10.232.130.170 (10.232.130.170) 56(84) bytes of data.
64 bytes from 10.232.130.170 (10.232.130.170): icmp_seq=1 ttl=253 time=3.14 ms

Routing Table

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.165.11.136   *               255.255.255.248 U     0      0        0 eth1
192.168.0.0     *               255.255.255.0   U     0      0        0 eth0
link-local      *               255.255.0.0     U     1002   0        0 eth0
link-local      *               255.255.0.0     U     1003   0        0 eth1
default         10.165.11.137   0.0.0.0         UG    0      0        0 eth1
1

Edit the eth1 config file and comment out/delete the gateway line and restart network service as follows:

service network restart

Now you should see 192.168.0.100 as your default router and everything should be working as expected.

By default, all the traffic related with the subnet of the eth1 interface, will go through that interface because the kernel will create that entry.

It's good to mention that all the traffic (except 10.165.11.136/255.255.255.248), will go through your default gateway, but in case you want to route some specific traffic through eth1 interface you can do as follows:

Runtime:

ip route add X.X.X.X/32 via 10.165.11.137 dev eth1

Permanent:

  1. Create the file /etc/sysconfig/network-script/route-eth1
  2. Add a line like this

    X.X.X.X/32 via 10.165.11.137

  3. Restart network service to apply

    service network restart

I hope this helps.

  • I tried removed gateway from eth1, I can ping 10.165.11.137 (gateway), but 10.232.130.170 (remote host) is surprisingly not reachable. ip route add X.X.X.X/32 via 10.165.11.137 dev eth1, how do I make this generic for all 255 hosts of 10.232.130.X subnet? – user1263746 Jan 1 at 20:00
  • @user1263746 The IP 10.232.130.170 is out the subnet of eth1 interface. You should add a route. Something like this: ip route add 10.232.130.0/24 via 10.165.11.137 dev eth1. – Manuel Florian Jan 1 at 20:11

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.