天天看點

linux shell nis

 #!/bin/bash

#this script is install nis server

#this nis server

yum -y install xinetd

yum -y install yp-tools ypbind ypserv portmap

read -p "please input a domain name for host(like:abc.com):" domain

read -p "please input a hostname for host:" hname

read -p "add a user for nis client:" user

echo  "==========set password for $user:=========="

passwd $user

CONF=/etc/ypserv.conf

IP=`ifconfig | grep "inet addr" | grep -v "127.0.0.1" | cut -d: -f2 | cut -d' ' -f1`

MASK=`ifconfig | grep Mask | grep -v "127.0.0.1" | cut -d: -f4`

NIP=`echo $IP | awk -F . -v OFS="." '{print $1,$2,$3}'`                       #print ip the three before(取ip的前三位,也就是取網段)

sed -i "s/`hostname`/$hname.$domain/g"  /etc/sysconfig/network

echo "NISDOMAIN=$domain" >>/etc/sysconfig/network

echo "/bin/nisdomainname $domain" >> /etc/rc.d/rc.local

sed -i "/127.0.0.1/s/localhost/$hname/" /etc/hosts

sed -i "/127.0.0.1/s/localhost.localdomain/$hname.$domain/" /etc/hosts

echo  "$IP  $hname  $hname.$domain "  >> /etc/hosts

nisdomainname $domian

sed -i '/port/s/^/# /g' $CONF   #把比對有port的行,前面加上#号

cat >> $CONF << EOF

xfr_check_port: yes

127.0.0.0/255.255.255.0       :*     :*    :none

$NIP.0/$MASK                  :*     :*    :port

:*                            :*     :*    :deny

EOF

touch /etc/netgroup

cat >> /var/yp/securenets << EOF

host 127.0.0.1

$MASK   $NTP.0

/usr/lib/yp/ypinit -m

#start Related services

service xinetd restart

service rpcbind restart   #IN centos 6.x  Portmap has been replaced by rpcbind

service ypserv start

service yppasswd start 

chkconfig ypserv on

chkconfig yppasswdd on

chkconfig rpcbind on

#!/bin/bash

#this nis client,this script can not run

yum -y install ypbind yp-tools

#添加伺服器的ip與主機名對應的關系

echo " 192.168.1.1  ypserver"  >> /etc/hosts

echo "NISDOMAIN=abc.com" >>/etc/sysconfig/network

echo "/bin/nisdomainname abc.com" >> /etc/rc.d/rc.local

sed -i '$a domain abc.com server ypserver.abc.com' /etc/yp.conf

cat >> /etc/nsswitch.conf << EOF

passwd:     files nis

shadow:     files nis

group:      files nis

hosts:      files nis dns

service ypbind start

###測試用的指令

ypwhich -x

ypcat passwd

yptest

本文轉自 jie783213507 51CTO部落格,原文連結:http://blog.51cto.com/litaotao/1186923,如需轉載請自行聯系原作者

繼續閱讀