Adding/overwriting hosts to /etc/hosts on DEBIAN (And OpenMediaVault)

Leave a comment

September 28, 2012 by aubreykloppers

This took me a while to understand.  Basically you need to add a script to your /etc/init.d/ directory, Change the ACL and add the script to your RC-LEVELS.

Steps:

a. create a file /etc/init.d/addhosts.sh and add the following content:

#!/bin/sh
### BEGIN INIT INFO
# Provides: /etc/hosts
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start hosts file
### END INIT INFO

case “$1” in
start)

echo “Starting script blah ”
echo “Could do more here”

echo “#Added by Aubrey” >/etc/hosts
echo “127.0.0.1 localhost” >>/etc/hosts
echo “10.0.0.200 MYHOST.host.com MYHOST” >>/etc/hosts
echo “” >>/etc/hosts
echo “# SERVERS” >>/etc/hosts
echo “10.0.0.16 myhost1” >>/etc/hosts
echo “10.0.0.17 myhost2” >>/etc/hosts

;;

*)

echo “Usage: /etc/init.d/addhosts.sh {start}”
exit 1
;;
esac

exit 0

b. Change the acl:

chmod 755 addhosts.sh

c. write the file to your rcX.d directories:

update-rc.d addhosts.sh defaults

NOTES:

1. Remember the HEADER of the file must be EXACT, else it will fail.

2. Setting the ACL.

That’s it.  Works like a charm!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: