Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a shell script which adds route which is not working if called through /etc/rc.local file. The contents of scripts are;
#!/bin/bash route add default gw 192.168.0.1 netmask 0.0.0.0 dev eth3
If I just execute above command on console then it puts route entry in routing table. I want to make this entry permanent. Please let me know what I am making wrong and how can I get this done.
Yes I have given permission as chmod a+x script.sh
I am using CentOS 5.5 64 bit
yes I have mentioned correct location of script in rc.local as "sh /root/script.sh"
If all you are trying to do is set the default gateway why not do so in the standard interface configuration scripts found under /etc/sysconfig/network-scripts/ifcfg-eth0?
I agree with ComputerErik, the correct way would be to use standard scripts.
Anyway, if you do a script which is supposed to be run during boot sequence, always use full path, I mean you should specify "/sbin/route", because nothing guarantee you that PATH is correctly set during boot.
Actually my servers has two NICs and both NICs have been assigned IP addresses and default gateways. Linux by default picks only one default gateway and puts it in routing table which can be viewed in 'route -n' command. Now purpose of dual NICs and IPs is that if one NIC or even router gets down then traffic will be received using send NIC or router and after processing send traffic back to router.
I have defined default gateways of both NICs using scripts placed at /etc/sysconfig/network-scripts/ but only one default gateway is used by linux and if that gateways gets down then traffic can't be sent from the server. Now if I execute command route add default gw 192.168.0.1 netmask 0.0.0.0 dev eth3 then it puts second default gateway in routing table and this way I can achieve redundancy. I hope now my requirement is clear so please suggest me how can I automate above command on startup/boot time.
Ok, I think that this link may help you: http://www.cyberciti.biz/faq/setting...terfaces-file/
I think that if I were you, I would try to "play" with "post-down command" stuff to change the default gateway when an interface comes down. As I have never tried I cannot assert it will work, but it is from my point of view the cleanest way to proceed.
You can also configure static route and make it persistent.
Suppose you have two interfaces eth0 and eth1 and default gateway is configured for eth0. Then you can create a file route-eth1 in /etc/sysconfig/network-scripts and enter the following text...
Sorry but unfortunately, I have never used Centos and barely never used Fedora (I think that they are quite similar)... So I cannot help you more.
Maybe have a look at /etc/sysconfig/network-scripts/ directory and ifup-routes file... the best would be to create a similar file named ifdown-routes to change your gateway when an interface bvrings down.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.