How do I make my default (or any static) route permanent on Linux (Fedora 9 specifically)?
Solution 1
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
Solution 2
just edit the /etc/sysconfig/network-scripts/route-ethXX
and write inside: default via ip_address dev device , replace ip_address with your gateway ip and device with the name of the right eth device. but for the Device option its ... optional, set it in the case of multiple eth devices. Works even in case of network restart, the route directive in rc.local works at boot only.
Solution 3
I have not used recent versions of Fedora, but it was often set as a GATEWAY variable in /etc/sysconfig/network.
Of course, if you just wanted it to work, you could just put the commands in /etc/rc.local to be executed when the boot sequence completes.
Ben Cracknell
Updated on June 05, 2021Comments
-
Ben Cracknell almost 3 years
I'm working on a GUI that displays a list of elements.
All the elements are in a one dimensional iterable array, so displaying them would normally look something like this:
foreach (Element e: elements) { display.Display(e); }
I now need a way to organize the elements in a tree structure like in this example:
In my system, there is no distinction between "folder" elements and "file" elements, but I can access an element's 'depth' and 'isExpanded' values.
How can I determine whether an element should be displayed based on data taken from iterating through previous elements?
-
Paul Tomblin over 15 yearsGATEWAY is usually in /etc/sysconfig/network-scripts/ifcfg-eth0, not in /etc/sysconfig/network.
-
Richard T over 15 yearsPaul, zigdon was right, there is a GATEWAY entry, but it was there all along and apparently was ineffective.
-
meerkatlookout over 15 yearsI've usually just bodged this into /etc/rc.local when I've needed to set up multiple static routes; as long as you don't have any services that rely on that route early on (like an nfs mount), it may be the most expedient solution.
-
Richard T over 15 yearsAs I wrote in my original question, rc.local is way late.
-
Richard T over 15 yearsThanks, Paul. The answer is: put your gateway line in the appropriate interface's script in /etc/sysconfig/network-scripts/ - just as you suggest.
-
codeforester over 6 yearsThis should be a comment rather than an answer.