Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How do I set two gateways for one ethernet card in linux?

Thanks a lot.

share|improve this question

4 Answers 4

up vote 3 down vote accepted

It depends on the linux distribution you're using. under debian like systems you have to change the contents of the file /etc/network/interfaces on rhel systems you have to edit the file /etc/sysconfig/networking-scripts/ifcfg- (where is the name of your ethernet card e.g. eth0)

you can add the entry "gateway" followed by the ip adress. as soon as you restart your network interface the routes will be added automatically to your routing table.

Like Michael already wrote you can also just add the corresponding route instead of editing the configuration files.

share|improve this answer

Take a look at the 'route' program on Linux (man route). If you are trying to accomplish static routing, something along the lines of:

route add [-host|-net] ...[etc]

What are you trying to do exactly? With some more details someone could probably lead you to exactly the solution you're looking for.

share|improve this answer

Let's assume you are using RedHat ES 5. Let's also assume that you want eth0 to route packets destined for 192.168.1.0/25 to route through 192.168.1.1 and packets destined for 192.168.1.128/25 to route through 192.168.1.129.

In /etc/sysconfig/network-scripts , create a file route-eth0 . In here, put:

192.168.1.0/25 via 192.168.1.1
192.168.1.128/25 via 192.168.1.129

Now:

/sbin/service network restart

And you should be good to go. You can check your current routing table with

netstat -nr

A good resource for RedHat can be found here:

http://www.redhat.com/docs/en-US/Red%5FHat%5FEnterprise%5FLinux/5.4/html/Deployment%5FGuide/s1-networkscripts-static-routes.html

share|improve this answer

The answer will depend on which distribution you are using.

Also, could you please add more detail about what you are trying to accomplish?

share|improve this answer

Your Answer

 
discard

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.