天天看點

DHCP服務和NIS服務

<本章目标>

■ 掌握linux系統網絡配置

■ 掌握dhcp和nis的伺服器配置和用戶端使用

■ 使用dhcp中繼代理實作跨網段的網絡位址自動配置設定

■ 使用nis服務實作主機和使用者帳戶的同步

<章節内容> 1.1 linux系統網絡配置

在開始使用linux網絡之前,必須了解linux網絡相關配置檔案所在的目錄與檔案名以及相關的設定指令,并熟記這些網絡配置檔案和指令,這樣在進行網絡測試與修改時就會事半功倍。

<b>1.1.1 </b><b>更改主機名</b><b></b>

比如主機名為gouzhongxing,ip位址為192.168.20.2

1. 修改系統資訊,/etc/sysconfig/network的主要功能是修改主機名稱(hostname)與是否啟動network。

# <b>cat /etc/sysconfig/network</b>

networking=yes

hostname=gouzhongxing.xapc.com

2. 修改/etc/hosts裡面的名字,為自己的域名加上解析。/etc/hosts檔案是用于記錄計算機的ip對應的主機名稱或主機的别名。

# <b>tail -2 /etc/hosts</b>

127.0.0.1 localhost.localdomain localhost

192.168.20.2 gouzhongxing.xapc.com

3. 最後在終端下執行:

# hostname gouzhongxing.xapc.com

特别提示:三處修改的名字要保持一緻,否則會出現問題。

<b>1.1.2</b><b> </b><b>配置</b><b>ip</b><b>位址</b><b>/</b><b>子網路遮罩</b><b>/</b><b>網關</b><b>/dns</b>

方法1:使用 netconfig/system-config-network

方法2:直接修改網卡的配置檔案

在/etc/sysconfig/network-scripts目錄中,編輯ifcfg-eth0檔案。

device=eth0

bootproto=none

onboot=yes

type=ethernet

ipaddr=192.168.20.2 # 要設定的ip

netmask=255.255.254.0 # 要設定的子網路遮罩

gateway=192.168.20.1 # 要設定的網關

hwaddr=00:0c:29:4f:3d:c8 # 要設定的網卡位址

為主機設定dns伺服器位址

# <b>cat /etc/resolv.conf</b>

nameserver 192.168.20.2 # 要設定的dns伺服器位址

設定完成後,重新啟用一下網卡設定後配置檔案生效

# /etc/rc.d/init.d/network restart

# service network restart

<b>1.1.3</b><b> </b><b>檢視和快速設定</b><b>ip</b><b>位址的指令</b><b>——ifconfig</b>

ifconfig指令用于檢視和更改網絡接口的位址和參數

一個更改網絡接口的ip位址的例子:

# ifconfig eth0 down

# ifconfig eth0 211.101.149.233 netmask 255.255.255.0 up

1.2 dhcp服務和中繼代理 <b>1.2.1</b><b> </b><b>知識回顧</b><b></b>

dhcp稱為動态主機配置協定。dhcp服務允許工作站連接配接到網絡并且自動擷取一個ip參數。配置dhcp服務的伺服器可以為每一個網絡客戶提供ip位址、子網路遮罩、預設網關、wins伺服器的ip位址,以及dns伺服器的ip位址等。

dhcp協定中的資料包類型(7種封包)分别是:dhcpdiscover包、dhcpoffer包、dhcpoffer包、dhcpack包、dhcpdecline包、dhcpnak包、dhcprelease包。

一個完整的ip租約生成過程如下圖所示:

DHCP服務和NIS服務

<b>1. ip</b><b>租用請求。</b>dhcp客戶機啟動計算機後,通過udp端口67廣播一個dhcpdiscover資訊包,向網絡上的任意一台dhcp伺服器請求提供ip租約。

<b>2. ip</b><b>租用提供。</b>網絡上所有的dhcp伺服器都會收到此資訊包,每台dhcp伺服器通過udp端口68給dhcp客戶機回應一個dhcpoffer廣播包,提供一個ip位址。

<b>3. ip</b><b>租用選擇。</b>客戶機從不止一台dhcp伺服器收到提供後,會選擇第一個收到的dhcpoffer包,并向網絡中廣播一個dhcprequest消息包,表明自己已經接受了一個dhcp伺服器提供的ip位址。該廣播包中包含所接受的ip位址和伺服器的ip位址。

<b>4. ip</b><b>租約确認。</b>被客戶機選擇的dhcp伺服器在接收到dhcprequest廣播後,會廣播傳回給客戶機一個dhcpack消息包,表明已經接受客戶機的選擇,并将這一ip位址的合法租用以及其他的配置資訊都放入該廣播包中發給客戶機。客戶機在收到dhcpack包後,會使用該廣播包中的資訊來配置自己的tcp/ip,則租用過程完成,客戶機可以在網絡中通信。

<b>1.2.2</b><b> dhcp</b><b>服務的相關檔案</b><b></b>

■ 軟體包名稱為 dhcp

■ 配置檔案為 /etc/dhcpd.conf

■ 模闆檔案為 /usr/share/doc/dhcp-3.0pl1/dhcpd.conf.sample

■ dhcp租約檔案 /var/lib/dhcp/dhcpd.leases

■ 指定那塊網卡提供dhcp服務 /etc/sysconfig/dhcpd

■ 系統日志 /var/log/messages

<b>1.2.3</b><b> dhcp</b><b>中繼代理</b><b></b>

<b>一、在網絡中部署</b><b>dhcp</b>

■ 在單實體子網環境中部署dhcp

在單實體子網環境中,為了均衡負載和提供容錯能力,通常會配置兩台dhcp伺服器,在實際應用中較好的解決方案是使用80/20規則來平衡兩台dhcp伺服器的使用。一台性能較好的dhcp配置成主伺服器。

■ 在多實體子網環境中部署dhcp

由于dhcp在配置設定ip位址時是使用廣播方式通信,但路由器就是會隔離廣播。預設情況下,一個實體子網中的dhcp伺服器是無法為其它實體子網中的dhcp用戶端配置設定ip位址的。為了使網絡中所有的dhcp用戶端都能獲得ip位址租約,可以采取兩種方案:一種是每個實體子網中都配置一台或兩台dhcp伺服器;另一種是在一個實體子網中配置一台dhcp伺服器,在其它實體子網中使用dhcp中繼代理。兩種方案均使用80/20規則。在實際應用中後一種解決方案比較常用。

<b>二、使用</b><b>dhcp</b><b>中繼代理</b><b></b>

其工作過程是:

(1)收到本子網的dhcp用戶端廣播發出的dhcp消息後,如果在預定的時間内沒有dhcp伺服器廣播發出dhcp回應消息,則會将用戶端的dhcp消息以單點傳播方式轉發給指定的dhcp伺服器。

(2)dhcp伺服器收到 dhcp中繼代理轉發來的dhcp消息後,會提供一個與dhcp中繼代理的ip位址在同一子網的ip位址,然後以單點傳播方式将回應的dhcp消息發送給dhcp中繼代理。

(3)dhcp中繼代理收到dhcp伺服器回應的dhcp消息後,再通過廣播方式發送給dhcp用戶端。

這樣以單點傳播方式就不會受到路由器的限制。

<b>1.2.6</b><b> </b><b>實作</b><b>dhcp</b><b>中繼代理的三個重要步驟</b><b></b>

1、設定配置檔案

# <b>cat /etc/sysconfig/dhcrelay</b>

interfaces=“<b>eth0 eth1”</b>

dhcpservers=“<b>192.168.20.2”</b>

2、開啟路由轉發功能

# echo “1” &amp;gt; /proc/sys/net/ipv4/ip_forward

3、啟動中繼代理服務

# service dhcrelay start

1.3 dhcp中繼代理配置執行個體

網絡拓撲結構如圖,首先確定網絡暢通。

DHCP服務和NIS服務

步驟一:linux a上配置dhcp服務,可以為兩個子網提供服務

步驟二:linux b上配置dhcp中繼代理

步驟三:windows xp作為192.168.100.0網段的用戶端擷取ip位址

具體實作過程如下:

<b>步驟一、在</b><b>dhcp</b><b>伺服器</b><b>linux c</b><b>上做如下設定:</b><b></b>

檢視dhcp軟體包是否安裝

[root@xapc ~]# <b>rpm -q dhcp</b>

package dhcp is not installed

挂載第四張安裝CD光牒

[root@xapc ~]# <b>mount /dev/cdrom /media</b>

mount: block device /dev/cdrom is write-protected, mounting read-only

安裝dhcp軟體包

[root@xapc ~]# <b>rpm -ivh /media/server/dhcp-3.0.1-12_el5.i386.rpm</b>

warning: /media/server/dhcp-3.0.1-12_el.i386.rpm: v3 dsa signature: nokey, key id 37017186

preparing... ########################################### [100%]

1:dhcp ########################################### [100%]

複制配置檔案模闆

[root@xapc ~]# cp /usr/share/doc/dhcp-3.0.1/dhcpd.conf.sample /etc/dhcpd.conf

修改後的配置檔案内容如下:

[root@xapc ~]# <b>cat /etc/dhcpd.conf</b>

ddns-update-style interim;

ignore client-updates;

subnet 192.168.20.0 netmask 255.255.255.0 {

# --- default gateway

option routers 192.168.20.2;

option subnet-mask 255.255.255.0;

option domain-name-servers 192.168.20.2;

range 192.168.20.128 192.168.20.254;

default-lease-time 21600;

max-lease-time 43200;

# we want the nameserver to appear at a fixed address

host ns {

next-server marvin.redhat.com;

hardware ethernet 12:34:56:78:ab:cd;

fixed-address 192.168.13.222

}

在配置檔案中增加如下内容:

subnet 192.168.100.0 netmask 255.255.255.0 {

option routers 192.168.100.1;

range 192.168.100.128 192.168.100.254;

啟動dhcpd服務

[root@xapc ~]# <b>service dhcpd start</b>

starting dhcpd: [ ok ]

<b>步驟二、在</b><b>dhcp</b><b>中繼代理</b><b>linux b</b><b>上做如下配置:</b><b></b>

eth0及eth1設定如下:

[root@xapc ~]# <b>ifconfig</b>

eth0 link encap:ethernet hwaddr 00:0c:29:89:5e:16

inet addr:192.168.20.1 bcast:192.168.20.255 mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fe89:5e16/64 scope:link

up broadcast running multicast mtu:1500 metric:1

rx packets:1415 errors:0 dropped:0 overruns:0 frame:0

tx packets:35 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

rx bytes:161233 (157.4 kib) tx bytes:4361 (4.2 kib)

interrupt:185 base address:0x1400

eth1 link encap:ethernet hwaddr 00:0c:29:89:5e:20

inet addr:192.168.100.1 bcast:192.168.100.255 mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fe89:5e20/64 scope:link

rx packets:1434 errors:0 dropped:0 overruns:0 frame:0

tx packets:16 errors:0 dropped:0 overruns:0 carrier:0

rx bytes:164142 (160.2 kib) tx bytes:840 (840.0 b)

interrupt:169 base address:0x1480

同linux c一樣檢查并安裝dhcp軟體包

[root@xapc ~]#<b> rpm -ivh /media/server/dhcp-3.0.1-12_el.i386.rpm</b>

warning: /media/cdrom/server/dhcp-3.0.1-12_el.i386.rpm: v3 dsa signature: nokey, key id db42a60e

修改dhcp中繼的配置檔案如下:

[root@xapc ~]# <b>cat /etc/sysconfig/dhcrelay</b>

# command line options here

interfaces="<b>eth0 eth1</b>"

dhcpservers="<b>192.168.20.2</b>"

啟動dhcprelay服務

[root@xapc ~]# <b>service dhcrelay start</b>

starting dhcrelay: [ ok ]

啟用ip轉發

[root@xapc ~]# echo "1" &amp;gt; /proc/sys/net/ipv4/ip_forward

<b>步驟三、這時,可以在</b><b>linux a</b><b>上進行</b><b>ip</b><b>的自動擷取。</b><b></b>

在dhcp用戶端linux a自動擷取ip後,檢視dhcp伺服器linux c上的資料庫檔案:

[root@xapc ~]#<b> tail -7 /var/lib/dhcp/dhcpd.leases</b>

lease 192.168.20.2 {

starts 6 2011/10/28 09:23:32;

ends 6 2011/10/28 15:23:32;

binding state active;

next binding state free;

hardware ethernet 00:0c:29:55:3a:2e;

dhcp伺服器已經成功為192.168.20.0網段配置設定ip。

1.4 nis服務

nis(網絡資訊服務)也稱yp(yellow pages)協定,是一個提供目錄服務的rpc(遠端過程調用)應用服務。nis簡化了unix和linux桌面客戶的管理工作,用戶端利用它可以使用中心伺服器的管理檔案。桌面系統的使用者無需建立他們自己的/etc/passwd,他們隻簡單的使用維護在nis伺服器的檔案即可。

nis是一個客戶機/伺服器系統,ypbind是定義nis伺服器的用戶端程序。一旦确定了伺服器位置,客戶機綁定到了伺服器上,是以用戶端的查詢都發往伺服器。ypserv是回答用戶端查詢的伺服器程序。

nis伺服器集中維護使用者的帳号資訊(資料庫)供nis客戶機進行查詢,又稱為nis映射表。

yp-tools/ypbind,ypserv三個軟體包,用來安裝nis伺服器,安裝linux時可以選擇安裝。

<b>1.4.1</b><b> ypserv.conf</b><b>檔案</b><b> </b>

伺服器端有兩個配置檔案,ypserv.conf和securenets檔案,用于定義安全性。securenets檔案用于對nis用戶端主機進行通路控制,需要手工建立。

ypserv.conf的文法格式

host:map:security:[mangle[]]

各字段含義如下:

■ host 授權或禁止通路的計算機,它由位址/掩碼對确定。例如 192.168.1.0/255.255.255.0。* 表示所有主機。

■ map 該字段表示通路的nis映射表項名稱。例如:passwd.byuid。* 表示映射表 中所有的字段都可用。

■ security 授權通路類型

l none 允許通路,不加強安全性。

l port 允許特權端口通路。隻接收源端口小于1024的連接配接。

l deny 禁止通路。

l des 通路時需要數字加密标準(des)認證。

舉例如下:

# host : map : security : mangle

192.168.1.0/255.255.255.0 : * : none : no

* : * : deny : no

<b>1.4.2</b><b> yp.conf</b><b>檔案</b><b></b>

/etc/yp.conf是用戶端ypbind程序的配置檔案。如果找不到yp.conf檔案,ypinit程序使用nisdomainname 指令傳回的nis域名,廣播定位nis伺服器。ypbind将綁定到第一個相應請求的伺服器上。

ypserver hostname

domain nisdomain broadcast | server hostname

其中,hostname,nisdomain字元為變量。

使用ypserver配置選項為客戶機指定伺服器。yp.conf檔案包括ypserver選項時,客戶機使用指令nisdomainname傳回的nis域名,向ypserver指令的hostname字段指定的伺服器送出請求。/etc/hosts檔案中必須包含該主機的ip位址,dns是取代的hosts的,在dns中設定也是可以的。ypserver選項強制客戶機連接配接到特定的伺服器上。

在yp.conf檔案中使用domain選項定義了nis域名,指出客戶機是廣播定位還是直接向伺服器發送請求。

例子:

#<b> tail -1 /etc/yp.conf</b>

domain xapc server xapcserver

其中xapc作為域名,jh是這個域的伺服器。xapcserver在hosts中必須有相對應的ip位址,或者dns能夠對域名xapcserver進行解析。

<b>1.4.3</b><b> nsswitch.conf</b><b>檔案</b><b></b>

windows 2003的域跟nis非常類似,在區域網路内有一台win2003域控制器,下面有一些機器加入到這個域中,當域中的機器登入時,有一個選項是選擇登入到本機還時登入到域内,登入本地的密碼由本機控制,但是如果登入域内,密碼則有域控制器負責管理。

linux也是網絡作業系統,跟win2003沒有本質的差別,linux使用重要的檔案/etc/nsswitch.conf來控制登入。

nsswitch.conf檔案不僅能處理主機表和dns之間的優先次序,還能處理其它的問題。它為幾個不同的系統管理資料庫定義來源

由nsswitch.conf控制的資料庫:

■ alias email别名

■ ethers 用于rarp的以太網位址。

■ hosts 主機名和ip位址

■ password 使用者帳号資訊。

還有許多,沒有列出來。

例一:使用不帶nis的nsswitch.conf

password: files

shadow: files

...........

hosts: dns files

最後一句很重要,dns在先,files在後,這裡的files指的是/etc/hosts檔案,如果有用戶端查詢的時候,先找dns,再找files。這一句決定了順序。

例二:使用帶nis的nsswitch.conf example:

hosts: files nis dns

protocols: nis files

.........

........

nsswich.conf檔案已經取代了hosts.conf,因為它可以提供更多的資源控制方式。linux系統中通常這兩個檔案都有,但實際上起作用的是nsswitch.conf檔案。

<b>1.4.4</b><b> nis</b><b>測試及故障排除</b><b></b>

nis用戶端應該綁定到伺服器。ypwhich指令可以檢測用戶端是否正确的連接配接到伺服器。

如果客戶機正确的綁定到伺服器,用ypcat可以檢測伺服器提供的資訊。

如果nis軟體不正常工作,則可以檢查如下幾項内容:

■ 确認程序正在進行。使用ps auxw指令列出所有正在運作的程序,确認該程序正在運作。

■ 檢查系統日志(/var/log)檔案,檢視是否有消息指明影響配置的外設問題。

■ 如果程序看上去在運作但是沒有響應,殺死它們并重新啟動。在某些情況,守護程式工作不正常,需要重新啟動。

■ 确認/etc/nsswitch.conf配置檔案正确。通常問題都出現在這裡。

1.5 nis服務配置執行個體

DHCP服務和NIS服務

<b>步驟一</b><b> </b><b>在</b><b>linux b</b><b>上配置</b><b>nis server</b><b>,基本設定步驟如下:</b><b></b>

1、安裝nis伺服器軟體包

2、設定time和time-udp服務的啟動狀态

3、建立伺服器中的nis域名

4、設定ypserv服務的配置檔案

5、啟動nis伺服器

6、建構nis資料庫

<b>步驟二</b><b> linux a</b><b>作為</b><b>nis client</b><b>驗證</b><b>nis</b><b>服務</b><b></b>

1、安裝nis客戶機軟體包

2、設定hosts檔案中的nis伺服器主機記錄

3、建立nis的域名

4、設定yp.conf配置檔案

5、設定nsswitch.conf檔案

6、啟動ypbind服務程式

7、使用nis客戶機測試與nis伺服器的連接配接

8、nis用戶端使用者登入

<b>步驟一</b><b> </b><b>在</b><b>linux b</b><b>上配置</b><b>nis server</b>

1、 檢查nis伺服器端軟體包是否已經安裝

[root@xapc ~]# <b>rpm -qa | grep yp</b>

libgcrypt-1.2.0-3

freetype-2.1.9-1

<b>ypbind-1.17.2-3</b>

crypto-utils-2.1-4

perl-crypt-ssleay-0.51-5

beecrypt-3.1.0-6

cryptsetup-0.1-4

<b>yp-tools-2.8-7</b>

pyparted-1.6.8-2

[root@xapc ~]#

挂載CD光牒安裝未安裝的軟體包

[root@xapc ~]# <b>mount /dev/cdrom /media/cdrom/</b>

[root@xapc ~]# <b>rpm -ivh /media/cdrom/redhat/rpms/ypserv-2.13-5.i386.rpm</b>

warning: /media/cdrom/redhat/rpms/ypserv-2.13-5.i386.rpm: v3 dsa signature: nokey, key id db42a60e

1:ypserv ########################################### [100%]

2、啟動time和time-udp服務

修改time和time-udp服務的配置

[root@xapc ~]# <b>chkconfig time on</b>

[root@xapc ~]# <b>chkconfig time-udp on</b>

[root@xapc ~]# <b>service xinetd restart</b>

stopping xinetd: [ ok ]

starting xinetd: [ ok ]

3、加入域xapc,并修改相應的配置檔案和腳本

[root@xapc ~]# <b>nisdomainname</b>

(none)

[root@xapc ~]# <b>nisdomainname xapc</b>

修改後的系統配置檔案

[root@xapc ~]# <b>cat /etc/sysconfig/network</b>

hostname=xapc.com

<b>nisdomain=xapc</b>

修改後的系統啟動腳本

[root@xapc ~]# <b>cat /etc/rc.d/rc.local</b>

#!/bin/sh

#

# this script will be executed *after* all the other init scripts.

# you can put your own initialization stuff in here if you don't

# want to do the full sys v style init stuff.

touch /var/lock/subsys/local

<b>/bin/nisdomainname xapc</b>

4、将主配置檔案最後一行的注釋标記去掉

[root@xapc ~]# <b>tail /etc/ypserv.conf</b>

# if you comment out the next rule, ypserv and rpc.ypxfrd will

# look for yp_secure and yp_authdes in the maps. this will make

# the security check a little bit slower, but you only have to

# change the keys on the master server, not the configuration files

# on each nis server.

# if you have maps with yp_secure or yp_authdes, you should create

# a rule for them above, that's much faster.

<b>* : * : * : none</b>

定義用戶端通路控制

[root@xapc ~]# <b>cat /var/yp/securenets</b>

<b>255.255.255.0 192.168.11.0</b>

5、檢查portmap服務是否已經啟動

[root@xapc ~]# <b>service portmap status</b>

portmap (pid 1816) is running...

啟動ypserv服務

[root@xapc ~]# <b>service ypserv start</b>

starting yp server services: [ ok ]

6、添加域使用者zhang3

[root@xapc ~]# <b>useradd zhang3</b>

[root@xapc ~]# <b>passwd zhang3</b>

changing password for user zhang3.

new unix password:

bad password: it is too simplistic/systematic

retype new unix password:

passwd: all authentication tokens updated successfully.

生成map映像資料庫檔案,鍵入ctrl+d即可。此時,系統會在/var/yp/目錄下生成一個xapc子目錄。裡面包含許多映像檔案。

[root@xapc ~]# <b>/usr/lib/yp/ypinit -m</b>

at this point, we have to construct a list of the hosts which will run nis

servers. xapc.com is in the list of nis server hosts. please continue to add

the names for the other hosts, one per line. when you are done with the

list, type a &lt;control d&gt;.

next host to add: xapc.com

next host to add:

the current list of nis servers looks like this:

xapc.com

is this correct? [y/n: y] <b>y</b>

we need a few minutes to build the databases...

building /var/yp/xapc/ypservers...

running /var/yp/makefile...

gmake[1]: entering directory `/var/yp/xapc'

updating passwd.byname...

updating passwd.byuid...

updating group.byname...

updating group.bygid...

updating hosts.byname...

updating hosts.byaddr...

updating rpc.byname...

updating rpc.bynumber...

updating services.byname...

updating services.byservicename...

updating netid.byname...

updating protocols.bynumber...

updating protocols.byname...

updating mail.aliases...

gmake[1]: leaving directory `/var/yp/xapc'

xapc.com has been set up as a nis master server.

now you can run ypinit -s xapc.com on all slave server.

檢視生成後的map映像資料庫檔案

[root@xapc ~]# <b>ls -l /var/yp/xapc/</b>

total 432

-rw------- 1 root root 12430 may 10 09:44 group.bygid

-rw------- 1 root root 12438 may 10 09:44 group.byname

-rw------- 1 root root 12463 may 10 09:44 hosts.byaddr

-rw------- 1 root root 12664 may 10 09:44 hosts.byname

-rw------- 1 root root 13204 may 10 09:44 mail.aliases

-rw------- 1 root root 13081 may 10 09:44 netid.byname

-rw------- 1 root root 12479 may 10 09:44 passwd.byname

-rw------- 1 root root 12475 may 10 09:44 passwd.byuid

-rw------- 1 root root 29187 may 10 09:44 protocols.byname

-rw------- 1 root root 14498 may 10 09:44 protocols.bynumber

-rw------- 1 root root 16377 may 10 09:44 rpc.byname

-rw------- 1 root root 14229 may 10 09:44 rpc.bynumber

-rw------- 1 root root 49714 may 10 09:44 services.byname

-rw------- 1 root root 102400 may 10 09:44 services.byservicename

-rw------- 1 root root 12352 may 10 09:44 ypservers

至此,nis伺服器端配置完畢。

1、 檢查nis用戶端軟體包是否已經安裝。nis客戶機需要安裝ypbind和yp-tools兩個軟體包,ypbind和yp-tools軟體包是rhel4中預設安裝的

2、 設定hosts檔案中的nis伺服器主機記錄,nis客戶機需要通過主機名通路nis伺服器

[root@xapc ~]# <b>cat /etc/hosts</b>

# do not remove the following line, or various programs

# that require network functionality will fail.

127.0.0.1 xapc.com xapc localhost.localdomain localhost

<b>192.168.11.11 xapcserver</b>

3、 加入域xapc,nis客戶機中建立nis域名的操作與nis伺服器中相同。

[root@xapc ~]#<b> nisdomainname xapc</b>

4、設定用戶端yp.conf配置檔案,增加最後一行。nis客戶機的配置檔案是yp.conf

yp.conf檔案中需要設定nis域名和伺服器主機名稱。

[root@xapc ~]#<b> tail /etc/yp.conf</b>

# ypserver hostname

# use server hostname for the local domain. the

# ip-address of server must be listed in /etc/hosts.

# broadcast

# if no server for the default domain is specified or

# none of them is rechable, try a broadcast call to

# find a server.

<b>domain xapc server xapcserver</b>

4、 設定nsswitch.conf檔案,檔案中需要添加使用nis作為主機資訊的查詢方式

[root@xapc ~]# <b>cat /etc/nsswitch.conf | grep nis</b>

# nis or yp use nis (nis version 2), also called yp

# nisplus or nis+ use nis+ (nis version 3), unsupported

#passwd: db files ldap nis

#shadow: db files ldap nis

#group: db files ldap nis

<b>passwd: files nis</b>

<b>shadow: files nis</b>

<b>group: files nis</b>

#hosts: db files ldap nis dns

5、 ypbind服務程式需要portmap服務的支援,檢查portmap服務是否已經啟動

portmap (pid 1798) is running...

啟動ypbind服務

[root@xapc ~]# <b>service ypbind start</b>

binding to the nis domain: [ ok ]

listening for an nis domain server.

7、測試用戶端能否找到伺服器,檢視能通路的map映像資料庫檔案。yp-tools軟體包中提供了三個測試指令:

■ yptest指令可對nis伺服器進行自動測試

■ ypwhich指令可顯示nis客戶機所使用的nis伺服器的主機名稱和資料庫檔案清單

■ ypcat指令顯示資料庫檔案清單和指定資料庫的内容

[root@xapc ~]# <b>ypwhich</b>

xapcserver

[root@xapc ~]# <b>ypcat -x</b>

use "ethers" for map "ethers.byname"

use "aliases" for map "mail.aliases"

use "services" for map "services.byname"

use "protocols" for map "protocols.bynumber"

use "hosts" for map "hosts.byname"

use "networks" for map "networks.byaddr"

use "group" for map "group.byname"

use "passwd" for map "passwd.byname"

8、使用域使用者zhang3登陸,成功!

[root@xapc ~]# <b>su zhang3</b>

bash-3.00$

&lt;本章實驗&gt;

DHCP服務和NIS服務

<b>任務</b><b>1</b><b>:安裝配置</b><b>dhcp</b><b>伺服器及中繼代理,在用戶端擷取</b><b>ip</b><b>位址</b><b> </b>

注意事項

提示1:dhcpd.conf配置檔案預設不存在,需要手工建立

提示2:dhcpd.conf配置檔案中的任何錯誤配置都可能導緻dhcpd服務程式不能正常啟動

<b></b>

<b>任務</b><b>2</b><b>:安裝配置</b><b>nis</b><b>伺服器和</b><b>nis</b><b>客戶機,驗證使用者登入</b><b></b>

提示1:nis伺服器和客戶機中都需要較多的配置步驟,要按照順序進行配置

提示2:nis伺服器和客戶機中都需要運作相應的服務程式,portmap服務程式需要提前啟動

提示3:網絡防火牆有可能造成nis伺服器和客戶機連接配接失敗,必要時可以關閉兩端主機中的防火牆

&lt;本章總結&gt;

■ dhcp伺服器可向dhcp客戶機提供ip位址、預設網關位址等配置資訊

■ rhel4系統中包括dhcpd伺服器的安裝包,需要手工進行安裝

■ dhcp伺服器的主配置檔案是dhcpd.conf,dhcpd.conf檔案中包括聲明、參數和選項三類設定内容

■ linux系統作為dhcp客戶機需要設定網絡接口配置檔案,并重新啟動網絡接口

■ nis服務可以對系統中的使用者帳号等資訊進行集中管理;一台nis伺服器可以為多台nis客戶機提供資訊查詢服務;nis伺服器需要運作ypserv和yppasswdd兩個網絡服務程式;ypserv服務的配置檔案是ypserv.conf

■ nis客戶機需要運作ypbind服務程式,ypbind服務的配置檔案是yp.conf

繼續閱讀