全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1287
推到 Plurk!
推到 Facebook!

Linux 架站文件_ 4

 
jackkcg
站務副站長


發表:891
回覆:1050
積分:848
註冊:2002-03-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-12-21 23:54:52 IP:61.64.xxx.xxx 未訂閱
http://www.adj.idv.tw/server/linux_dhcp.htm 架設 DHCP DHCP 的好處﹐我已經在“網路基礎”之“DHCP 協定”裡面花了不少筆墨﹐您應該知道的了﹐這裡也就不再多說。 設定DHCP 別以為我在“網路基礎”那裡說得那麼複雜﹐但在 Linux 下面設定 DHCP 一點也不困難﹐您所有要做的只有一個檔案﹕/etc/dhcpd.conf (如果該檔案不存在﹐自行建立則可)。 下面﹐我用我自己的設定來說說怎麼修改這個檔案﹕ default-lease-time 259200; max-lease-time 777600; option domain-name "siyongc.domain"; 這幾行我放在檔案的開頭部份。第一和第二行我定義出租約的預設期限和最高期限﹐數值以秒來計算﹐也就是‘三天’和‘九天’。 然後在第三行我指定了網路使用的網域名稱。 接下來是 subnet 的設定﹕ subnet 192.168.0.0 netmask 255.255.255.0 { range 192.168.0.21 192.168.0.30; range 192.168.0.121 192.168.0.230; option broadcast-address 192.168.0.255; option routers 192.168.0.17; option domain-name-servers 192.168.0.17, 203.56.8.1; } subnet 203.30.35.128 netmask 255.255.255.224 { range 203.30.35.140 203.30.35.157; option broadcast-address 203.30.35.159; option routers 203.30.35.134; option domain-name-servers 203.30.35.134 203.56.8.1; } 這裡﹐我一共有兩裝網路卡分別向兩個網路提供 DHCP 服務。在第一個網路(192.168.0.0)下面我指定出兩個 scope ﹐也就是用來分配 DHCP 的 IP 範圍﹕192.168.0.21 到 192.168.0.30 和 192.168.0.121 到 192.168.0.230 。另外﹐我還指定了‘廣播地址’﹑‘路由器地址’和‘DNS的地址’。 第二個網路因為使用了27 bit 的 netmask﹐所以 Net ID 是﹕ 203.30.35.128 ﹐而廣播位址則是﹕203.30.35.159 。 最後﹐我還設定了這樣的句子﹕ host pii266 { hardware ethernet 48:54:E8:27:75:77; fixed-address 192.168.0.15; option domain-name "nt.domain"; option broadcast-address 192.168.0.255; option routers 192.168.0.254; option domain-name-servers 192.168.0.1, 192.168.0.17; } 正如我們所知﹐通過 DHCP 獲取 IP 的客戶端機器﹐如果其租約已經過期了﹐那麼好可能失去了原來的 IP 。不過﹐我又想我的 pii266 這台主機永遠都使用一個固定的 IP 地址。上面的句子就是為了這個目的而設的了。首先﹐我得找到在 pii266 這台機器上連接到我這個網路的界面種類和硬體地址﹐也就是﹕ethernet 48:54:E8:27:75:77 ﹐然後我用‘fixed-address’將 192.168.0.15 這個不在 DHCP scopes 之內的 IP 分配給 pii266。 如果您參考我上面這個檔案進行設定的話﹐務必留意每一個標點符號﹐有些數字是用‘﹐’來分隔﹐而有些則用空白鍵來分隔﹔而每一個句子﹐都要用‘﹔’做結尾(和 perl script 一樣)﹐否則﹐下面一行將會視為該行的延續部份﹐而不會當是新的一行看待。 當這個 /etc/dhcpd.conf 檔案設定好之後﹐您還要用下面的命令創建一個 /etc/dhcp.leases 的空白檔﹕ touch /etc/dhcp.leases 注意﹕您不要嘗試自行修改這個檔案﹐假如該檔有問題的話﹐將之刪除或改名﹐然後再用 touch 命令創建就是了。有些版本則會使用 /var/state/dhcp/dhcpd.leases﹐請根據您的情況自行決定。 我們在“網路基礎”中已經知道﹕在 DHCP 運作的初期﹐client 是使用廣播方式來查詢 DHCP 信息的。問題是我這裡有兩張網路卡﹐DHCP 要回應 client 的查詢時很難判斷出要傳到哪個網路中去﹐因為一開始的時候 client 端還沒分配到 IP 地址﹐所以我在我的 /etc/hosts 中增加了這樣一行﹕ 255.255.255.255 all-ones all-ones 然後﹐我還在 /etc/rc.d/rc.local 中增加了這樣的敘述﹕ # Lines added by netman, # for enabling DHCP routing on multi-nics environement: echo "Adding IP routing for DHCP server..." route add -host 255.255.255.255 dev eth0 route add -host 255.255.255.255 dev eth1 這樣﹐當機器啟動的時候﹐DHCP 的路由就設定好了。然而看來現在新版的 Linux 似乎無需再擔心這個問題了﹐假如您發現 DHCP 未能成功提供服務的話﹐再考慮使用這個辦法吧。 最後您要做的是﹐重新啟動 DHCP 服務﹕ /etc/rc.d/init.d/dhcpd start (如果 dhcpd 之前已經跑起來了﹐用 restart 代替 start)。檢查一下 /var/log/messages 有沒有錯誤信息﹐有則做出適當修改﹐再來嘗試啟動 dhcpd 。當沒有錯誤出現之後﹐您就可以執行 setup --> System services --> 確定﹕[ * ] dhcpd 。 為 IP Alias 設定 DHCP 在某些場合中﹐我們或許會運用到 IP Alias 來連接網路。這時候﹐我們還可以為 alias 所在的網路提供 DHCP 服務呢﹗不過﹐要留意一點是﹕您只能為一張界面提供一個 sub-net 的服務﹐就算界面上面捆綁了好幾個 alias 也一樣。 設定也是蠻簡單的啦﹕ 將 alias 所在的網路設定好。 然後將 /etc/dhcpd.conf 原本關於原有 IP 所在的 subnet 取消。 只留下 alias 所在網路的 range 就可以了。 在我的測試中﹐/etc/dhcpd.conf 不是最重要的﹐關鍵還是要確定 ip alias 已經成功啟動﹐而且 routing 一定要設定好。 下面是我初步整理出來的流程﹕ 1﹐啟動 dhcpd: 如果您有任何 interface 已經 up 起來了 && 且 routing 已經設定好 { 如果原有界面 sub-net 已經 declare 好 { ## 那麼無論您是否 delcare 好 alias 所在 sub-net dhcpd 可以啟動成功。 } 否則 { #原有界面 sub-net 沒有 declare 如果 alias 所在 sub-net 已經 declare 的時候 { 如果 alias 所在 sub-net 已經設定好 routing { dhcpd 可以成功啟動 } 否則 { # alias 所在 sub-net 還沒設定好 routing 當您啟動 dhcpd 的時候﹐您應該會得到﹕ No subnet declaration for ethx(原有 IP 網路) 的信息而失敗。 } } 否則 { # alias 所在 sub-net 沒有 declare 的話 也會得到 No subnet declaration for ethx 錯誤 } } } ------- 2﹐運作 dhcpd 當您的 dhcpd 成功啟動之後 { 如果您有 declear 原有界面所在 sub-net { 有 range 設定 { ## 那麼無論您是否設定好 alias 所在的 sub-net 和 range dhcpd 都只會offer 原有界面的 sub-net } 否則 { #沒有 range 設定 ## 那麼無論您是否設定好 alias 所在的 sub-net 和 range dhcpd 收到 DHCPDISCOVER 之後都會回應說﹕ no free leases on subnet (原有界面之 sub-net) } 否則 { #您並沒有 declear 原有界面所在 sub-net 如果有 alias 所在 sub-net { #沒有的話 dhcpd 啟動的時候已失敗 有 range 設定 { dhcpd 會 offer alias 所在 sub-net } 否則 { #沒有 range 設定 dhcpd 收到 DHCPDISCOVER 之後都會回應說﹕ no free leases on subnet (alias 所在 sub-net) } } } 如果看我的範例﹐會是這樣﹕ default-lease-time 259200; max-lease-time 777600; option domain-name "siyongc.domain"; ## 下面我將原有界面 sub-net 註解起來 #subnet 192.168.0.0 netmask 255.255.255.0 { # range 192.168.0.21 192.168.0.30; # range 192.168.0.121 192.168.0.230; # option broadcast-address 192.168.0.255; # option routers 192.168.0.17; # option domain-name-servers 192.168.0.17, 203.56.8.1; #} ## 這才是 alias 所在 sub-net 的設定﹕ subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.21 192.168.1.30; option broadcast-address 192.168.1.255; option routers 192.168.1.17; option domain-name-servers 192.168.1.17, 203.56.8.1; } 測試DHCP 要測試 HDCP 是否工作還不簡單﹐找一台在同一個網路的 Linux 機器﹐將它的界面轉成使用 DHCP 就是了。例如﹐修改 /etc/sysconfig/network-scripts/ifcfg-eth0 這個檔案﹐將之改成這樣﹕ DEVICE="eth0" ONBOOT="yes" BOOTPROTO="dhcp" IPADDR="" NETMASK="" BROADCAST="" NETWORK="" 然後執行 ifdown eth0 和 ifup eth0 將界面重新啟動﹐再執行 ifconfig 您就知道DHCP 是否運作了。但有一點您要留意﹕client 端的 dhcp 版本不能舊於 server 端 ﹐您可以用 rpm -qa | grep dhcp 命令來得知版本號碼。 如果您使用的是 Windows 系統﹐那麼﹕ 開始 --> 設定 --> 控制台 --> 網路 --> ‘TCP/IP ->網路卡’--> IP 位址 --> 自動取得 IP 位址 --> 確定 --> 確定 -->重新啟動機器。當登錄之後﹐執行﹕ 開始 --> 執行 --> winipcfg --> 尚有資訊 。您就可以驗證 DHCP 的設定了。如果您要在 DHCP 伺服器那端改動設定﹐可以按“全部更新”看看新設定是否生效。 假如您的機器有多張網路卡﹐但您只想向其中某一個界面所連接的網路提供 DHCP 服務而已﹐似乎在 dhcpd.conf 裡面只設定一個 subnet 話﹐會遇到 “No subnet declaration for ethx”的錯誤。要解決這個問題其實很簡單﹐就是為那些不提供 DHCP 的界面建立空的 declaration 就可以了。例如﹐您不想對 eth1 所在的網路 203.30.35.128/27 提供 DHCP 服務﹐那麼可以這樣寫﹕ subnet 203.30.35.128 netmask 255.255.255.224 {} 也就是在 { 和 } 之間﹐不設定任何東西就是了。 還有﹐非常感謝 steven 兄的建議﹐另外還有一個更方便的方法來解決這個問題。假如﹐您只想向 eth1 所連接的網路提供服務﹐而不理會 eth0 的話﹐您可以修改 /etc/rc.d/init.d/dhcpd 這個檔案﹐修改如下﹕ start) # Start daemons. echo -n "Starting dhcpd: " daemon /usr/sbin/dhcpd eth1 也就是在 daemon 那行後面加上 eth1 就可以了。 另外﹐當您機器有兩張網路卡﹐其中一張您已經用來做 DHCP server 來給內部網路發放 IP ﹐而另外一張則作為 DHCP client 到另外一個網路抓 IP。這樣的情形﹐有時候 DHCP client 那張卡在開機的時候或許會抓到自己的 DHCP server 發出來的 IP﹐然而這並不是您所需的。這時候﹐您要先抓到那張卡的硬體位置﹐然後用下面的設定﹐防止這種情形的發生﹕ host myclient { hardware ethernet 00:E0:C5:E4:02:EE; deny booting; } 這裡﹐我要感謝『我本善良』兄提供這個方法。 設定 remote boot 怎樣﹖是否意尤未盡還想玩玩更勁爆的呢﹖ 想的話就繼續囉~~~ 記得曾經答應過網友要寫關於 remote boot 的文章。 Appendix B, Installation Procedures 1, Install a Redhat Linux system, here is version 6.2 with kernel 2.2.19, with DHCPD, NFS, PORTMAP and TFTP services enabled. (Running rpm and 'ntsysv' to make sure) 2, Edit /etc/dhcpd.conf: ####################################################### # dhcpd.conf # # Sample configuration file for ISC dhcpd # use-host-decl-names on; shared-network testnet { option domain-name "kh.intra.coventive.com"; subnet 10.0.0.0 netmask 255.255.255.0 { option routers 10.0.0.1; option domain-name-servers 10.0.0.1; group { default-lease-time -1; next-server 10.0.0.1; option dhcp-class-identifier "PXEClient"; option vendor-encapsulated-options 01:04:00:00:00:00; host bpc01 { hardware ethernet 00:02:B3:0B:5A:60; fixed-address 10.0.0.99; option broadcast-address 10.0.0.255; option option-135 "linux"; # it expects 'linux.bpb' filename "bpbatch"; } } } } ####################################################### 3, Restart dhcp service: touch /var/state/dhcp/dhcpd.leases servcie dhcpd restart 4, Modify /etc/inetd.conf: tftp dgram udp wait root /usr/sbin/tcpd in.tftpd bootps dgram udp wait root /usr/sbin/tcpd bootpd 5, Restart inet serveive: service inet restart 6, Download bpbatch program from following wite: http://www.bpbatch.org/downloads/bpb-exe.tar.gz 7, Untar the program and copy them into /tftpboot: mkdir /tftpboot cp bpb-exe.tar.gz /tftpboot cd /tftpboot tar zxvf bpb-exe.tar.gz cp bpbatch.P bpbatch # You must rename or copy the file if you are using the default TFTP server shipped with RedHat. 8, Create a file named 'linux.bpb' and contains following: set CacheNever="ON" linuxboot "bzImage" "root=/dev/nfsroot nfsroot=10.0.0.1 ip=10.0.0.99:10.0.0.1::255.255.255.0:bpc01.kh.intra.coventive.com:eth0:" # last two lines must be written in a single line! # the format of the 'ip' command is follow: ip=:::::: # Note: Server IP is 10.0.0.1 and Client IP is 10.0.0.99, and no 'autoconf' in this case. 9, Compile the kernel with following options: cd /usr/src/linux make menuconfig Networking options ---> [*] IP: kernel-level configuration support [*] DHCP support [*] BOOTP support [*] RARP support Network device support ---> Ethernet (10 or 100Mbit) ---> <*> EtherExpressPro/100 support <*> PCI NE2000 support (or what ever you run on the client machine) Filesystems ---> <*> Kernel automounter support Network File Systems ---> <*> NFS filesystem support [*] Root file system on NFS 10, Compile your kernel and copy the image to /tftpboot: make dep make clean make bzImage mknod /dev/nfsroot b 0 255 cd arch/i386/boot/ /usr/sbin/rdev bzImage /dev/nfsroot # it modify the boot image, may be no necessary cp bzImage /tftpboot * You may need to fix the modules stuff as well. Try your own please. 11, Update the /etc/hosts file: 10.0.0.1 bpsrv01.kh.intra.coventive.com bpsrv01 10.0.0.99 bpc01.kh.intra.coventive.com bpc01 12, Create the client directory and copy stuffs: mkdir /tftpboot/bpc01 cd /tftpboot/bpc01 cp -a /bin . cp -a /boot . cp -a /dev . cp -a /etc . cp -a /lib . cp -a /opt . cp -a /sbin . cp -a /root . cp -a /var . mkdir home mkdir mnt mkdir proc mkdir tmp mkdir usr chmod 1777 tmp * If the client machine is different with the server, create the template on client then copy them on to server. 13, Update /etc/exports: /tftpboot/bpc01 10.0.0.99(rw,no_root_squash) /home 10.0.0.99(rw,no_root_squash) /usr 10.0.0.99(rw,no_root_squash) 14, Reload export content or restart nfs service: /usr/sbin/exportfs -a # or: service nfs stop service nfs start # don't use 'restart' switch! 15, Change directory to /tftpboot/bpc01/etc make necessary change in those files: HOSTNAME: bpc01.kh.intra.coventive.com fstab: 10.0.0.1:/ftfpboot/bpc01 / nfs defaults 1 1 10.0.0.1:/home /home nfs defaults 1 1 10.0.0.1:/usr /usr nfs defaults 1 1 none /proc proc defaults 0 0 none /dev/pts devpts gid=5,mode=620 0 0 resolv.conf: nameserver 10.0.0.1 sysconfig/network: NETWORK=yes HOSTNAME=bpc01.kh.intra.coventive.com GATEWAY=10.0.0.1 GATEWAYDEV=eth0 sysconfig/network-scripts/ifcfg-eth0: DEVICE=eth0 BOOTPROTO=dhcp ONBOOT=yes 17, Delete the files that make effecting the system: cd /tftpboot/bpc01/etc rm dhcpd.conf echo "" > exports cd rc.d/rc6.d rm *netfs* rm *killall 18, At the first successful boot up, run 'ntsysv' and disable following services: dhcpd nfs * Or, according to your actual needs.
------
**********************************************************
哈哈&兵燹
最會的2大絕招 這個不會與那個也不會 哈哈哈 粉好

Delphi K.Top的K.Top分兩個字解釋Top代表尖端的意思,希望本討論區能提供Delphi的尖端新知
K.表Knowlege 知識,就是本站的標語:Open our mind
系統時間:2024-05-17 20:02:11
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!