1

I have a web server with installation of Cent OS 5.6, cPanel/WHM. Currently the server have 2 ethernet and the configuration for both is listed below:

--------------------------------------------------------------
      | IP              | Subnet Mask     | Gateway     
--------------------------------------------------------------
eth0  | XXX.XX.XXX.150  | 255.255.255.252 | XXX.XX.XXX.149
--------------------------------------------------------------
eth1  | 192.168.86.2    | 255.255.255.252 | 192.168.86.1
--------------------------------------------------------------

Current default route is eth1 with gateway 192.168.86.1

Now what I need is to set eth0 as a default route for all connection except for 3 IPs (10.10.6.2, 10.10.6.3 and 10.10.6.4). I also need to set route for those 3 IPs from eth1.

eth0 is connected to optical fiber for internet connection whereas eth1 is connected to a DSL router for intranet connection

so can anyone help me to set this properly and permanently?

1 Answer 1

1

There are a few things you need to configure. First of all, a router attached to the 192.168.86.2/30 interface must be configured to route traffic destined for this network to it. Assuming you're in some hosted environment where this has already been completed, you only have to configure the routing table on the server.

You can specify a default route for all traffic in /etc/sysconfig/network by setting the GATEWAY option:

GATEWAY=XXX.XX.XXX.149

Next, you'll need custom routing for the IPs you specified. You do this with the /etc/sysconfig/network-scripts/route-eth1 file by adding:

10.10.6.2/32 via 192.168.86.1
10.10.6.3/32 via 192.168.86.1
10.10.6.4/32 via 192.168.86.1

(I'm making the assumption that the router listed as 'Gateway' next to eth1 will get you there, of course.)

You should be able to restart networking (service network restart) and verify the routing table with route -n.

6
  • to change the default gateway to eth0 I simply added GATEWAYDEV=eth0 on /etc/sysconfig/network and I added the rule on route-eth1 but got this reply from 192.168.86.1 "Destination Host Unreachable". This means the route is working and may be destination is probably down.
    – Prakash
    Jun 13, 2011 at 21:41
  • I also want to know do I need to add subnet mask? If so how? As route -n shows 255.255.255.255 as a genmask whereas I think it should be 255.255.255.252
    – Prakash
    Jun 13, 2011 at 21:46
  • The /32 is the subnet mask written in CIDR format. The mask specifies which IPs in the network (based on the network address) to include. I have listed 3 individual IPs so the network mask is 255.255.255.255. This could be expressed in a /30 (255.255.255.252) as well, but I was unsure about the .1 address.
    – Kyle Smith
    Jun 13, 2011 at 22:04
  • I added following on route-eth1 10.10.6.2/30 via 192.168.86.1 10.10.6.3/30 via 192.168.86.1 10.10.6.4/30 via 192.168.86.1 and restarted the network service. But which checking route -n it output error like RTNETLINK answers: Invalid argument
    – Prakash
    Jun 14, 2011 at 0:47
  • Please put the contents of that file into a pastebin and add the URL to your question or via a comment here.
    – Kyle Smith
    Jun 14, 2011 at 4:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .