0

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

2 Answers 2

0

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
6
  • 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, 2011 at 14:38
  • This is the usual way to do it. It's part of the network interfaces configuration!
    – Khaled
    Dec 22, 2011 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, 2011 at 14:42
  • This is a static default route! It is not dynamic :)
    – Khaled
    Dec 22, 2011 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, 2011 at 14:53
0

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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .