Tuesday, January 18, 2011

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

Hi,

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

Thanks a lot.

  • The answer will depend on which distribution you are using.

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

  • Hello,

    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.

    From Michael
  • Hi

    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.

    From grub
  • 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

0 comments:

Post a Comment