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
EOF
 
/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
EOF
 
service rpcbind restart   #IN centos 6.x  Portmap has been replaced by rpcbind
service ypbind start
 
 
###测试用的命令
ypwhich -x
ypcat passwd
yptest









本文转自 jie783213507 51CTO博客,原文链接:http://blog.51cto.com/litaotao/1186923,如需转载请自行联系原作者
目录
相关文章
|
17天前
|
Web App开发 Java Linux
Linux之Shell基本命令篇
Linux之Shell基本命令篇
Linux之Shell基本命令篇
|
1月前
|
监控 Shell Linux
【Shell 命令集合 系统管理 】Linux 显示当前登录到系统的用户信息 who命令 使用指南
【Shell 命令集合 系统管理 】Linux 显示当前登录到系统的用户信息 who命令 使用指南
43 1
|
1月前
|
监控 Shell Linux
【Shell 命令集合 系统管理 】Linux 显示目前登入系统的用户信息 w命令 使用指南
【Shell 命令集合 系统管理 】Linux 显示目前登入系统的用户信息 w命令 使用指南
45 2
|
16天前
|
存储 Shell Linux
【攻防世界】unseping (反序列化与Linux bash shell)
【攻防世界】unseping (反序列化与Linux bash shell)
|
18天前
|
Shell Linux
【Linux】12. 模拟实现shell
【Linux】12. 模拟实现shell
27 2
|
24天前
|
Shell Linux
Linux的shell入门教程shell脚本入门教程
Linux的shell入门教程shell脚本入门教程
15 0
|
1月前
|
存储 算法 Shell
【Linux 环境变量相关】深入理解Linux下 CMake、Shell 与环境变量的交互(二)
【Linux 环境变量相关】深入理解Linux下 CMake、Shell 与环境变量的交互
50 0
|
1月前
|
Shell Linux 开发工具
shell的介绍以及Linux权限的讲解
shell的介绍以及Linux权限的讲解
31 2
|
1月前
|
网络协议 Shell Linux
【Shell 命令集合 系统管理 】Linux 查询域名的注册信息 whois命令 使用指南
【Shell 命令集合 系统管理 】Linux 查询域名的注册信息 whois命令 使用指南
48 1
|
1月前
|
存储 Shell Linux
【Shell 命令集合 系统管理 】Linux 显示当前登录用户的用户 whoami命令 使用指南
【Shell 命令集合 系统管理 】Linux 显示当前登录用户的用户 whoami命令 使用指南
49 1