LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 01-04-2011, 04:19 AM   #1
zaeem
Member
 
Registered: Jan 2010
Posts: 110

Rep: Reputation: 15
Issue with shell script


Dear All,

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.

Thanking you in advance.
 
Old 01-04-2011, 05:10 AM   #2
andrewthomas
Senior Member
 
Registered: May 2010
Location: Chicago Metro
Distribution: Arch, Gentoo, Slackware
Posts: 1,690

Rep: Reputation: 307Reputation: 307Reputation: 307Reputation: 307
Have you made the file executable?

What distribution are you using?

Is the rc.local script if the correct location?
 
Old 01-04-2011, 06:43 AM   #3
zaeem
Member
 
Registered: Jan 2010
Posts: 110

Original Poster
Rep: Reputation: 15
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"

Thanks for your help.
 
Old 01-04-2011, 07:13 AM   #4
ComputerErik
Member
 
Registered: Apr 2005
Location: NYC
Distribution: Debian, RHEL
Posts: 268

Rep: Reputation: 42
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?
 
Old 01-04-2011, 08:01 AM   #5
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
Hello,

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.

Regards,

Oliv'
 
Old 01-04-2011, 12:11 PM   #6
zaeem
Member
 
Registered: Jan 2010
Posts: 110

Original Poster
Rep: Reputation: 15
Dear Oliv,

Let me explain my requirement in detail

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.
 
Old 01-04-2011, 02:38 PM   #7
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
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.

Cheers,

Oliv'
 
Old 01-05-2011, 04:32 AM   #8
kamalkgarg
LQ Newbie
 
Registered: Jan 2011
Posts: 14

Rep: Reputation: Disabled
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...

"
GATEWAY0=<Gateway IP>
NETMASK0=<Netmask>
ADDRESS0=<Network Address>
"

Restart the network using "service network restart"
Execute "route -n" command to view the routes appearing.

- Kamal
 
Old 01-06-2011, 04:39 AM   #9
zaeem
Member
 
Registered: Jan 2010
Posts: 110

Original Poster
Rep: Reputation: 15
Dear Kamal,

This is not working for me. Any other suggestions?
 
Old 01-06-2011, 04:40 AM   #10
zaeem
Member
 
Registered: Jan 2010
Posts: 110

Original Poster
Rep: Reputation: 15
Dear Oliv,

The suggested link is for Debian and Ubuntu. It is not working for CentOS. Can you please give any other suggestion?
 
Old 01-06-2011, 09:56 AM   #11
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
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.

Oliv'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
issue related to shell script manglesh.vyas Linux - Newbie 2 12-07-2010 05:39 PM
Shell script issue suvra82002 Linux - Enterprise 23 07-26-2008 02:02 PM
ftp'ing via shell script issue closet geek Programming 6 09-20-2006 09:11 AM
issue with shell script chupacabra Linux - General 3 10-18-2002 08:12 PM
Out of guesses! (shell Script issue) chris Linux - General 2 12-10-2001 04:20 PM


All times are GMT -5. The time now is 08:39 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration