详细说明参照:
(四)跟我一起玩Linux网络服务:DHCP服务配置之中继代理
vm1的脚本是:
1 #! /bin/bash 2 3 HIPSEG="10.10.10" 4 SIPSEG="192.168.128" 5 HRoute="10.10.10.10" 6 SRoute="192.168.128.8" 7 DN="ns.gr.org" 8 9 cat > /etc/dhcpd.conf << +END+ 10 ddns-update-style interim; 11 ignore client-updates; 12 13 subnet $HIPSEG.0 netmask 255.255.255.0 { 14 option routers $HRoute; 15 option subnet-mask 255.255.255.0; 16 option domain-name "$DN"; 17 option domain-name-servers $HRoute; 18 option time-offset 28800; 19 range dynamic-bootp $HIPSEG.100 $HIPSEG.200; 20 default-lease-time 21600; 21 max-lease-time 43200; 22 } 23 subnet $SIPSEG.0 netmask 255.255.255.0 { 24 option routers $SRoute; 25 option subnet-mask 255.255.255.0; 26 option domain-name "$DN"; 27 option domain-name-servers $HRoute; 28 option time-offset 28800; 29 range dynamic-bootp $SIPSEG.100 $SIPSEG.200; 30 default-lease-time 21600; 31 max-lease-time 43200; 32 } 33 +END+ 34 service dhcpd restart 35 ps -ax | grep dhcpd 36 37 route add -net $SIPSEG.0/24 gw $HRoute
vm2的脚本是:
1 #! /bin/bash 2 IP="10.10.10" 3 RIP="10.10.10" 4 DN="gr.org" 5 Name="10.10.10.10" 6 cat >> /etc/named.conf << +END+ 7 zone "$DN." IN { 8 type master; 9 file "gr.org.db"; 10 }; 11 zone "$RIP.in-addr.arpa" IN{ 12 type master; 13 file "$IP.db"; 14 }; 15 +END+ 16 cat > /var/named/$DN.db <<+END+ 17 $TTL 86400 18 @ IN SOA ns.$DN. root.$DN. ( 19 20150317 6H 30M 1W 15M) 20 IN NS ns.$DN. 21 IN MX 10 mail.$DN. 22 bbs IN CNAME www.$DN. 23 ns IN A $IP.10 24 www IN A $IP.10 25 mail IN A $IP.11 26 +END+ 27 cat > /var/named/$IP.db <<+END+ 28 $TTL 86400 29 @ IN SOA ns.$DN. root.$DN.( 30 20150317 6H 30M 1W 15M) 31 IN NS ns.$DN. 32 10 IN PTR ns.$DN. 33 10 IN PTR www.$DN. 34 11 IN PTR mail.$DN. 35 +END+ 36 cat > /etc/resolv.conf <<+END+ 37 nameserver $Name 38 +END+ 39 40 service named start