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-11-2013, 01:51 PM   #1
kaempfer0080
LQ Newbie
 
Registered: Jan 2013
Posts: 7

Rep: Reputation: Disabled
First init.d script?


Hello everyone. At work we have a linux server that is on both the local network and a VPN network. In order for it to function correctly I need to route local traffic through the local network and the rest of the traffic through the VPN router. I did this by putting the following in terminal
Code:
route add default gw 10.226.67.1 eth1
route del default gw 192.168.16.1 eth0
to route the traffic through a specific interface.

And that fixed the problem. However, whenever the server restarts or the network goes down or whatever, the route config switches back to the default which doesn't work. I want to write a script and place it in init.d that just executes the 2 lines written above. I've done a lot of googling but the examples I find are complex with starts, stops, conditionals, etc. I just want to run the two lines. How can I do this?
 
Old 06-11-2013, 02:06 PM   #2
thedaver
Member
 
Registered: Jan 2010
Posts: 65

Rep: Reputation: 21
do some research into an init script 'rc.local' which is present for Debian/Ubuntu systems... Redhat/Fedora probably use something similar.

rc.local allows you to insert some commands that should be part of the boot sequence.


You've clearly appreciated that the 'route' command you've been issuing are only valid until a restart of networking or a reboot.
 
Old 06-11-2013, 02:35 PM   #3
kaempfer0080
LQ Newbie
 
Registered: Jan 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
Oh, thanks for reminding me. The server runs Fedora 14 so fedora/red hat structure. I'll try a few more things in the meantime.
 
Old 06-12-2013, 09:37 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
rc.local should be present in the /etc tree on most Linux distros.
 
Old 06-12-2013, 10:59 AM   #5
kaempfer0080
LQ Newbie
 
Registered: Jan 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
Ah I found rc.local. Can I just put the commands in there as is without any of the binning and bashing?
 
Old 06-12-2013, 11:34 AM   #6
thedaver
Member
 
Registered: Jan 2010
Posts: 65

Rep: Reputation: 21
It should work that way. If you have the flexibility to reboot that server, you can insert this into the rc.local and check the outcome after reboot

Code:
echo "hello world" > /var/log/my_rc.local_script_output.log
IF that works, then you should be able to insert real commands into rc.local.

Note, this approach will NOT implement the commands on restart of networking, which likely exists under another set of init.d scripts.

You could write your commands into a script and store that script in /sbin or /usr/bin or whatever. Then in rc.local AND in the networking scripts you could reference that script. That way you solve for both cases.
 
Old 06-12-2013, 12:07 PM   #7
kaempfer0080
LQ Newbie
 
Registered: Jan 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
Alright I'll try the echo thing to see if it works. I discovered another issue where on reboot/network restart it sets both connections to eth1 for some reason. Having trouble figuring out why because the ifcfg-device files have device=eth0 and device=eth1 respectively.

e: I got the log output so I assume it's working, but I can't know til I get this other problem sorted out.

Last edited by kaempfer0080; 06-12-2013 at 12:17 PM.
 
Old 06-12-2013, 03:16 PM   #8
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
Originally Posted by kaempfer0080 View Post
..
And that fixed the problem. However, whenever the server restarts or the network goes down or whatever, the route config switches back to the default which doesn't work. I want to write a script and place it in init.d that just executes the 2 lines written above. I've done a lot of googling but the examples I find are complex with starts, stops, conditionals, etc. I just want to run the two lines. How can I do this?
just wondering if it would be better to set it up in /etc/network/interfaces

Code:
man interfaces
an init.d script might* work for server restarts, but the network coming back up.. it won't

* might work !! but probably won't as the network will likely 'come up' after your script ran, clobbering it's work.
 
Old 06-12-2013, 03:49 PM   #9
thedaver
Member
 
Registered: Jan 2010
Posts: 65

Rep: Reputation: 21
Hey, I said that! :-)
 
Old 06-12-2013, 04:25 PM   #10
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
Originally Posted by thedaver View Post
Hey, I said that! :-)
well yes and no
  • Not enough weight given to correctly configuring the network
  • The rc.local would be redundant if also handled by the networking scripts, so no need for AND.
  • Pointing to a script that 'fudges' something which can be handled within the standard configuration is poor practice.
None of which really matter all that much on a personal system, but the workplace is a different matter.
Someone may inherit responsibility for that server/system and not necessarily with the benefit of a personalized handover.
It is, in my opinion, only polite to do things in a standard way.

Please for give me for being so pedantic

Last edited by Firerat; 06-12-2013 at 04:30 PM.
 
Old 06-12-2013, 08:05 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Re eth1 vs eth0; have you set the MAC addresses in the ifcfg-ethX files? Check if they're the same.
See also /etc/udev/rules.d/70-persistent-net.rules
 
  


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
[SOLVED] Script no in init.d davidedwardgill Linux - Software 1 08-21-2011 10:07 AM
Init script in /etc/init.d does not start at boot tdnnash25 Linux - Server 4 12-18-2009 05:40 PM
Init.d Script pliqui Debian 11 06-16-2009 09:58 AM
script init.d anna611 Linux - Newbie 9 11-28-2007 01:22 PM
need help with init script batymahn Linux - Server 1 08-23-2007 12:12 PM


All times are GMT -5. The time now is 05:15 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