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

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


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

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

GATEWAY=<default gateway IP>
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


share|improve this answer

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.