Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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  | | XXX.XX.XXX.149
eth1  |    | |

Current default route is eth1 with gateway

Now what I need is to set eth0 as a default route for all connection except for 3 IPs (, and 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?

share|improve this question
up vote 1 down vote accepted

There are a few things you need to configure. First of all, a router attached to the 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:


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: via via via

(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.

share|improve this answer
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 "Destination Host Unreachable". This means the route is working and may be destination is probably down. – Prakash Jun 13 '11 at 21:41
I also want to know do I need to add subnet mask? If so how? As route -n shows as a genmask whereas I think it should be – Prakash Jun 13 '11 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 This could be expressed in a /30 ( as well, but I was unsure about the .1 address. – Kyle Smith Jun 13 '11 at 22:04
I added following on route-eth1 via via via and restarted the network service. But which checking route -n it output error like RTNETLINK answers: Invalid argument – Prakash Jun 14 '11 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 '11 at 4:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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