Wednesday, January 21, 2015

modifications to /etc/rc.d/rc.inet1.conf

Hey everyone, just thought I'd share my modifications to /etc/rc.d/rc.inet1.conf. These are pretty simple, but very effective in my opionion.

Basically, I really had to learn the hard way the importance of /etc/resolv.conf, and how to set a hostname. I really don't like how you have to hunt in order to get these settings in place. In my opinion, editing a textfile by hand is fine, but doing it all in one place is simpler than going to different files.

Then again, people may view this as an abomination, and respond by saying things should be kept the old way. Take a look and let me know what you think :)

# /etc/rc.d/rc.inet1.conf
.

.

.


# Set hostname

# This will set your hostname as defined in /etc/hosts.
# This only works if you have a properly defined /etc/hosts file.
# In order for these settings to take effect, after properly modifying
# /etc/hosts, you must restart network (/etc/rc.d/rc.inet1 restart),
# exit your current shell, and log back in--or log in to a new shell.
# Please refer to man /etc/hosts for more information.

hsts=$(cat /etc/hosts | grep 127.0.0.1 | egrep -v 'localhost|Arnt' | cut -f 2)
if [ -n $hsts ]; then
        HOSTNAME=$hsts
    hst=$(echo $hsts | sed 's/\..*//')
    echo $hsts > /etc/HOSTNAME
    echo $hst > /etc/HOSTNAME_S
    hostname -F /etc/HOSTNAME_S
fi

# Config information for eth0:
.

.
# Default gateway IP address:
GATEWAY=""

# DNS Settings

# Either run dhcpd once to create a temp /etc/resolv.conf and copy values
# below, or get the values from your ISP / Router / Modem.
# Uncomment nameservers as necessary for your network.
domain=ph.cox.net
nameserver1=192.168.0.1
#nameserver2=68.105.28.11
#nameserver3=68.105.29.11

# Create resolv.conf

# Uncomment nameservers as necessary for your network.
if [ -x /etc/resolv.conf ]; then
 echo "" > /etc/resolv.conf
else
 touch /etc/resolv.conf
 echo "domain $domain" > /etc/resolv.conf
 echo "nameserver $nameserver1" >> /etc/resolv.conf
#echo "nameserver $nameserver2" >> /etc/resolv.conf
#echo "nameserver $nameserver3" >> /etc/resolv.conf
fi



So basically, to summarize, skip the comments and the ethernet section (those are still there but you know what it looks like). The parts I added was the hostname section, the DNS settings, and creating resolv.conf. These easily make resolv.conf for you when rc.inet1 is being run--in other words when network is being brought up. The hostname according to the hostname manpage is supposedly also setup when rc.inet1 is ran, but it doesn't accept changes to /etc/hosts on the fly. I didn't like this, which is why I modified rc.inet1.conf as such.

This script requires you to have a properly modified /etc/hosts, like such:

# For loopbacking.
127.0.0.1    localhost
# This next entry is technically wrong, but good enough to get TCP/IP apps
# to quit complaining that they can't verify the hostname on a loopback-only
# Linux box.
127.0.0.1          bpm37093.centauri.net          bpm37093  
192.168.0.200   beta.centauri.net                    beta
192.168.0.210   v766.centauri.net                    v766
192.168.0.220   bpm37093.centauri.net          bpm37093    


The nice thing about adding this section is that, you can have your hostname update on the fly, all you have to do is restart the network (/etc/rc.d/rc.inet1 restart), and then make sure to exit and log back in to your shell/ log in to a new shell. And viola! Your hostname will now show up :)

The DNS settings, well ... the easiest way to get those is to either run dhcpd once--which will auto generate a resolv.conf for you. Once you have those settings  you can populate the DNS settings sections with what is suitable for your network.

Alternatively you don't have to run dhcpd. You can just get the settings from your router, or modem, and go from there.

Also, you may not need as many nameservers. Simply uncomment the appropriate nameserver variables/ echo statements as neccessary for your network. Also, you can add additional nameservers, you just have to add another nameserver line in the dns section and an extra echo statement in the resolv.conf section. However 3 is more than enough (2 is generally what most ISP's use, the 3rd is for your router if it supports it).

Below are links to the modified /etc/rc.d/rc.inet1.conf file and an accompanying md5 file (so you can sure what youre downloading isn't some bullshit garbage:b).
 - rc.inet1.conf - modified: http://www.datafilehost.com/d/57b5c9f0
 - rc.inet1.conf - md5sum: http://www.datafilehost.com/d/86fc1021

No comments:

Post a Comment