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 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? |
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. |
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.
|
rc.local should be present in the /etc tree on most Linux distros.
|
Ah I found rc.local. Can I just put the commands in there as is without any of the binning and bashing?
|
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 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. |
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. |
Quote:
Code:
man interfaces * might work !! but probably won't as the network will likely 'come up' after your script ran, clobbering it's work. |
Hey, I said that! :-)
|
Quote:
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 ;) |
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 |
All times are GMT -5. The time now is 11:24 PM. |