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 up a static default route, for a router, in linux? I know that the usual way to go for a static route is to edit the /etc/network/interfaces and add at the proper interfaces the following line:

up route add -net <destination> gw <next-hop>

But how should the line be modified for a default route? Thanks

[EDIT]

Is this a correct scenario: If I have a router R1 directly connected to router R2(R1(eth0) connected to R2(eth1)). If I want to set a default route from R1 to R2 than i modify R1's /etc/network/interfaces and I add under the eth0 interface the line:

up route add default gw <R2 eth1 ip addr> dev eth0
share|improve this question

2 Answers 2

This may differ based on your distro. For example, you can use the following syntax on debain-based systems like ubuntu in file /etc/network/interfaces.

auto eth0
iface eth0 inet static
        address ...
        netmask ...
        network ...
        broadcast ...
        gateway <default gateway IP>

On redhat like systems, you edit the file /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=none
IPADDR=...
NETMASK=...
GATEWAY=<default gateway IP>
ONBOOT=yes
share|improve this answer
    
I don't understand what are you trying to say. I am not trying to configure an interface, but a static default route for the interface of a router. –  biggdman Dec 22 '11 at 14:38
    
This is the usual way to do it. It's part of the network interfaces configuration! –  Khaled Dec 22 '11 at 14:39
    
Yes, i know, but I am interested in configuring a static default route. The interfaces are configured in my /etc/network/interfaces –  biggdman Dec 22 '11 at 14:42
    
This is a static default route! It is not dynamic :) –  Khaled Dec 22 '11 at 14:43
    
@biggdman, GATEWAY is the static default route. Is your interface dynamic and you're trying to reconfigure what the DHCP server is providing you for the gateway? –  cjc Dec 22 '11 at 14:53

The appropriate configuration file to use for a persistent change is going to be vendor and/or distro specific.

For instance, on a redhat or fedora system, you can add the GATEWAY line to the file /etc/sysconfig/network.

(This can also be done for /etc/sysconfig/network-scripts/ifcfg-devN but that's tedious and possibly confusing on a multi-interface box.)

For "one off" runtime use, you should be able to use the ip command (and this should work on any distro): ip route add default via gateway-address

for example:

ip route add default via 192.168.99.254

cheers!

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.