server1 自动设置SHELL

#!/bin/bash
#提取本机MAC地址
MAC=`/sbin/ifconfig eth0 | grep HW | awk '{print $5}'`

#修改HOSTS文件
echo -e "127.0.0.1\tlocalhost\n172.24.254.254\tserver1.exampl.com\tserver1">/etc/hosts
hostname server1.example.com
#修改resolv.conf文件
echo -e "search example.com\nnameserver 127.0.0.1"> /etc/resolv.conf
#修改主机名
echo -e "NETWORKING=yes\nNETWORKING_IPV6=yes\nHOSTNAME=server1.example.com"> /etc/sysconfig/network
#修改eth0IP地址

echo -e "DEVICE=eth0\nONBOOT=yes\nPEERDNS=no\nHWADDR=$MAC\nTYPE=Ethernet\nNETMASK=255.255.0.0\nIPADDR=172.24.254.254\nGATEWAY=172.24.0.1"> /etc/sysconfig/network-scripts/ifcfg-eth0
重置网卡
ifdown eth0
ifup eth0

你可能感兴趣的:(linux,server,shell,职场,休闲)