開機互動式設定腳本

  1. 變更 root 及用戶 csielabnat 密碼。
    [root@dywH ~]# cd /usr/src/nat/bin
    [root@dywH bin]# vim natboot.sh 
    passwd
    passwd csielabnat
    
  2. 要求使用者輸入對外網路 ip, 遮罩。
    [root@dywH bin]# vim natboot.sh 
    ethdhcp='eth0'  ## Internal Network
    ethint='eth1'   ## External Network
    answer="n"
    echo -n "SETUP EXTERNAL NETWORK: "
    while [ x"$answer" != "xy" ] && [ x"$answer" != "xY" ] ; do
    	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 "\tip: $ip"
    	echo -e "\tnetmask: $netmask"
    	echo -e "\tdefault gw: $gw"
    	echo -n "Is this correct? [y/n] "; read answer
    done
    
  3. 將使用者輸入的資料,寫入對外網卡設定檔。
    [root@dywH bin]# vim natboot.sh 
     
    cat > /etc/sysconfig/network-scripts/ifcfg-eth1 << 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
    
  4. 重新啟動網路。
    /etc/init.d/network restart
    
  5. 讓使用者輸入需要的防火牆設定,選項 --set= 後接 open 為全開放、 close 為全關閉、csie 為只開放連上校內網路、dywang 為只能連上 De-Yu Wang 指定的網站。若此參數不輸入,預設為全開放。myip 可以單獨指定某 ip 完全放行,不受防火牆管制。
    [root@dywH bin]# vim natboot.sh 
    answer="n"
    echo -n "SETUP IPTABLES: "
    while [ x"$answer" != "xy" ] && [ x"$answer" != "xY" ] ; do
    	echo -n "enter myip: "; read ip
    	myip="192.168.1.$ip"
    	echo -n "enter --set=[open|close|csie|dywang]: "; read iptab
    	[ "$iptab" == "" ] && iptab=” || iptab="--set=${iptab}"
    	echo
     
    	echo You entered:
    	echo -e "\tmyip: $myip"
    	echo -e "\tiptables : $iptab"
    	echo -n "Is this correct? [y/n] "; read answer
    done
    
  6. 重新建立 repo 資料庫清單。
    [root@dywH bin]# vim natboot.sh 
    setdhcpiptables.sh $iptab --myip=$myip
    
    exit 0
    %post --nochroot --log=$INSTALL_ROOT/tmp/ksnochrootpost
    cp /usr/src/nat/bin/*.sh $INSTALL_ROOT/usr/local/bin/
    %end