LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-05-2012, 04:41 AM   #1
Paulius_J
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Rep: Reputation: Disabled
Add simple script to "service network restart"


Hello, how could i add a script which runs everytime when i restart network? sript would look like this:

Code:
#!/bin/bash
route add default gw 10.3.1.1 eth0
route add default gw 10.3.1.5 eth1
I have to do this because in CentOS network configuration is a little screwed, if i add default gateway to /etc/sysconfig/network then eth1 takes it, not eth0, to make it work well i would have to change route-eth0 and route-eth1 which is complicated. So i added this script to /etc/rc.local but if i restart network gateway is removed, so in order not to have to run rc.local again i would like to add bash script to network restart, how could i do this?
 
Old 06-05-2012, 04:56 AM   #2
vp0619520
Member
 
Registered: Jan 2012
Posts: 55

Rep: Reputation: Disabled
Hi, I think you can add these two statements to that network script file with the path
Code:
/etc/init.d/network
.
You should add your command to the end of the “start”and “restart” in the “case” statements/blocks.Wish this can be useful for you.
 
Old 06-05-2012, 06:08 AM   #3
Paulius_J
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Tried

No it doesn't work, it says something "file is found" but doesn't work. I tried adding line " . /etc/myscriptname" too, but still nothing. I am waiting for more suggestions now.
 
Old 06-05-2012, 07:15 AM   #4
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 190Reputation: 190
This sounds like a dodgy work around to me, you would be better off fixing the multiple default routes.

I don't believe it is possible with the old 'route' command, but it is doable with 'ip' by creating multiple route tables..

http://kindlund.wordpress.com/2007/1...utes-in-linux/
http://www.generationip.com/document...teway-on-linux

To answer your question about running a script when restarting networking as a service, I would suggest adding your commands to add the necessary routes to the ifup-ethx scripts in /etc/sysconfig/network-scripts/
 
Old 06-05-2012, 08:50 AM   #5
Paulius_J
LQ Newbie
 
Registered: Jun 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
To answer your question about running a script when restarting networking as a service, I would suggest adding your commands to add the necessary routes to the ifup-ethx scripts in /etc/sysconfig/network-scripts/
That didn't work either, i tried many variables (with . /etc/myscript) but no, didn't work either.

And those are magnificent links, i will study them and will ask if something is not understandable, thank you.
 
  


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
What does "service network restart" do on RHEL? resetreset Linux - Networking 5 04-06-2012 08:10 AM
Where do I add a "service dhcp3-server restart" micropanther Linux - Server 2 03-16-2012 07:40 AM
Getting "SIOCADDRT: No such process" when running "service network restart" cmlorentz Linux - Networking 1 11-26-2010 02:06 PM
"ip route add" doesn't keep changes on network restart Hosferatu Linux - Networking 4 06-11-2008 01:52 AM
counter part of "service network restart" b0nd Slackware 5 10-10-2005 07:47 AM


All times are GMT -5. The time now is 03:24 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration