--nochroot 選項,就是將根目錄切換到已安裝的新系統中。也就是此時所作的任何動作或命令,都是針對新安裝的系統。設定執行結果記錄在 /tmp/kspost。
[root@dywH add]# vim nat-ks.cfg %post --log=/kspost %end
[root@dywH add]# vim nat-ks.cfg %post --log=/kspost sed -i 's/\(^hiddenmenu\).*$/#\1/' /boot/grub/grub.conf sed -i 's/\(^title De-Yu Wang\).*$/\1 -- CSIE NAT/' /boot/grub/grub.conf %end
[root@dywH add]# vim nat-ks.cfg %post --log=/kspost sed -i 's/\(^net.ipv4.ip_forward =\).*$/\1 1/g' /etc/sysctl.conf %end
[root@dywH add]# vim nat-ks.cfg %post --log=/kspost chvt 1 curTTY=`tty` exec < $curTTY > $curTTY 2> $curTTY %end
[root@dywH add]# vim nat-ks.cfg %post --log=/kspost ethdhcp='eth0' ## Internal Network ethint='eth1' ## External Network echo -e "# Command line options here\nDHCPDARGS=\"$ethdhcp\"" > /etc/sysconfig/dhcpd %end
[root@dywH add]# vim nat-ks.cfg %post --log=/kspost answer="n" while [ x"$answer" != "xy" ] && [ x"$answer" != "xY" ] ; do echo -n "enter hostname (nat): "; read hostname [ "$hostname" == "" ] && hostname='nat' echo -n "enter ip: "; read ip echo -n "enter netmask (255.255.255.0): "; read netmask [ "$netmask" == "" ] && netmask='255.255.255.0' echo -n "enter default gw: "; read gw echo echo You entered: echo -e "\thostname: $hostname" echo -e "\tip: $ip" echo -e "\tnetmask: $netmask" echo -e "\tdefault gw: $gw" echo -n "Is this correct? [y/n] "; read answer done %end
[root@dywH add]# vim nat-ks.cfg
%post --log=/kspost
sed -i -e 's/^\(HOSTNAME=\).*$/\1'"$hostname"'/' /etc/sysconfig/network
cat > /etc/sysconfig/network-scripts/ifcfg-${ethint} << END
DEVICE='eth1'
BOOTPROTO='static'
NM_CONTROLLED=no
ONBOOT=yes
IPADDR=$ip
NETMASK=$netmask
GATEWAY=$gw
DNS1=163.17.3.1
DNS2=163.17.1.1
END
%end
[root@dywH add]# vim nat-ks.cfg
%post --log=/kspost
cat > /etc/named.conf << END
// named.conf for NAT
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
forward only;
forwarders {
163.17.3.1;
168.95.1.1;
139.175.10.20;
};
};
END
%end
[root@dywH add]# vim nat-ks.cfg
%post --log=/kspost
cat > /etc/dhcp/dhcpd.conf << END
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
# see 'man 5 dhcpd.conf'
#
authoritative;
ddns-update-style none;
subnet 192.168.1.0 netmask 255.255.255.0 {
# The following lines are standard all of the time.
option routers 192.168.1.254;
option subnet-mask 255.255.255.0;
option domain-name "deyu.wang";
option domain-name-servers 192.168.1.254,163.17.3.1,168.95.1.1;
default-lease-time 600;
max-lease-time 720;
range 192.168.1.100 192.168.1.199;
next-server 192.168.1.254;
}
END
%end
[root@dywH add]# vim nat-ks.cfg %post --log=/kspost sed -i 's/^\(server 0\)/server 163.17.1.46\nserver tock.stdtime.gov.tw\n\1/' /etc/ntp.conf %end
[root@dywH add]# vim nat-ks.cfg %post --log=/kspost useradd csielabnat passwd csielabnat %end
[root@dywH add]# vim nat-ks.cfg %post --log=/kspost mv /etc/sysconfig/iptables /etc/sysconfig/iptables.orig echo "setdhcpiptables.sh $ethdhcp $ethint" >> /etc/rc.d/rc.local echo "csielabnat ALL=NOPASSWD:/usr/sbin/setdhcpiptables.sh" >> /etc/sudoers %end
[root@dywH add]# vim nat-ks.cfg %post --log=/kspost echo 'AllowUsers csielabnat@192.168.1.*' >> /etc/ssh/sshd_config %end
[root@dywH add]# vim nat-ks.cfg %post --log=/kspost echo "0 8,13,18 * * * /usr/sbin/setdhcpiptables.sh $ethdhcp $ethint" >> /var/spool/cron/root %end
[root@dywH add]# vim nat-ks.cfg %post --log=/kspost chvt 6 %end