Operating System - Linux
1819870 Members
2465 Online
109607 Solutions
New Discussion юеВ

Add routing entry at system startup

 
peterchu
Super Advisor

Add routing entry at system startup

I hv added the below routing entry to my system , but it will be erased after system reboot , how to set it as a permanent routing so that it still vaild even system reboot ? thx
4 REPLIES 4
ramkumar
Valued Contributor

Re: Add routing entry at system startup

Hi
what linux system you are using . if you are using redhat

go to /etc/sysconfig/network-scripts/
in that you can find the files with name ifcfg-eth(interface no) example your net interface is eth0 then edit
ifcfg-eth0 in that there is an option called
GATEWAY . enter your gateways ip address

That all man why your are worried .
if you stiil having probs feel freee to contact me
Manuel Wolfshant
Trusted Contributor

Re: Add routing entry at system startup

The most general way of solving your problem is to add a command which sets the routing in one of the startup scripts. Depending on the distribution, this script could be /etc/rc.local (RH, fedora, Mdk), /etc/rc.inet2 (slackware) and so on.
However, you should look into the proper way to accomplish what you want in the proper way specific to the distribution you use. For instance, while adding the route command to /etc/rc.inet2 IS the proper slackware way, 'the right way' for RH (below 9.0) is to add the static route to a file named /etc/sysconfig/static-routes, while for RH 9.0 and Fedora Core, the static routes should be placed in files named /etc/sysconfig/network-scripts/route-ethN (N being the index of the interface for which you define the routes), while on Debian you could place a script in /etc/network/if-up.d/

Examples:
RH (below 9.0):
# cat /etc/sysconfig/static-routes
eth1 net 192.168.100.128 netmask 255.255.255.128 gw 192.168.100.102
eth1 net 192.168.100.120 netmask 255.255.255.248 gw 192.168.100.102

Fedora:
# cat /etc/sysconfig/network-scripts/route-eth0
193.231.236.0/27 via 81.196.24.1
193.231.191.40 via 81.196.24.1
213.157.160.0/19 via 81.196.24.1


If you still cannot figure out what to do, give more details (mostly what distribution you are using) and you will receive more detailed help.
Ranjith_5
Honored Contributor

Re: Add routing entry at system startup

Hi Peter,

____________________________________
Network GUI COnfiguration tools:-
____________________________________

1./usr/bin/redhat-config-network (/usr/bin/neat) (RH 7.2+)

2./usr/bin/redhat-config-network-tui
(text console RH 9.0)

3./usr/bin/gnome-network-preferences

(nome Desktop Network Configuration (RH 9.0) - proxy configuration)

Also in redhat Linux,

Static routes are set with the route command and with the configuration file /etc/sysconfig/static-routes.


You can see the following too

see the following file

Configuration settings for your first ethernet port (0).
/etc/sysconfig/network-scripts/ifcfg-eth0


Hope this helps you,
Syam


Ross Minkov
Esteemed Contributor

Re: Add routing entry at system startup

Some folks said that you can add routes in files like /etc/rc.d/rc.local, etc. Generally that is true and will work just file on a reboot.

But please consider the case when someone restarts network services while the system is up. For example "service network restart". Then you loose your route(s) that you added to /etc/rc.d/rc.local

That's why there are file (as Manuel said) that you should use to avoid the above described problem. For Red Hat - based distros:

RHL 7.x:
/etc/sysconfig/static-routes

RHEL & Fedora:
/etc/sysconfig/network-scripts/route-eth0

For examples use the ones Manuel provided in his post.

HTH,
Ross