Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make my default (or any static) route permanent on Linux (Fedora 9 specifically)? [closed]

I've just performed a new installation of the very latest (Fall, 2008) version of Fedora 9 Linux and am perplexed that it never set the default route properly and that even traveling the labyrinthine ways of this OS, there's no obvious way.

Of course, it's clear that one can do it on a one-off basis like this:

   route add default gw gw1 metric 0 eth0

or like this:

   ip route add to default via 192.168.2.1 protocol static

However, neither of these survives reboot. In reading through /etc/rc.d/init.d/network, it attempts to find data from a file in /etc/sysconfig/static-routes, but that file never existed. So, I tried to create it and populate it with data. The trouble with that is that the script places a dash (minus sign) in an odd spot that I'm not sure how to deal with.

Of course, one can just edit /etc/rc.d/init.d/network, but that would be non-standard. As it is, my only other recourse seems to be editing rc.local, but that doesn't come early enough in the boot sequence to be there for things like, for example, the network time daemon.

I've done my homework - I've read all the man pages, info entries, tried apropos, and I've even done a fair bit of web searching, all to no avail - my next step, sans answer here, will be to sign up to the Fedora mailing lists and ask there! Or, give up and edit the scripts.

So, how is one supposed to do this?

like image 936
Richard T Avatar asked Oct 13 '08 20:10

Richard T


People also ask

How do I make a static route permanent in Linux?

Using the route command is the only way that you can manually make routes persistent across system reboots. To make the changes persist across system reboots, use the –p option with the route command. In this release, naming of persistent static routes is also supported.

How do I create a permanent static route?

To make the route persistent just add the -p option to the command. For Example: route -p add 192.168. 151.0 MASK 255.255.

How do I permanently add a static route in Linux Ubuntu?

On Ubuntu, there are three ways of adding a permanent route to your Linux machine : You can add it to your Network Manager configuration file; You can edit your Netplan YAML configuration file; You can add your route to the “/etc/network/interfaces” file if you are using an old Ubuntu distribution.


1 Answers

The gateway is normally set in /etc/sysconfig/network-scripts/ifcfg-eth0, not in /etc/sysconfig/network. For example, on my current machine:

/etc/sysconfig/network

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=flyboys
NISDOMAIN=ekcineon

/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
ONBOOT=yes
HWADDR=00:1d:09:31:3a:cc
NETMASK=255.255.255.0
IPADDR=150.102.65.30
GATEWAY=150.102.65.252
TYPE=Ethernet

Note that I set HWADDR because I have two ethernet cards and I want to make sure the right one is assigned to eth0. The configuration for the second card is in /etc/sysconfig/network-scripts/ifcfg-eth1

like image 141
Paul Tomblin Avatar answered Nov 13 '22 01:11

Paul Tomblin