设定为Server+IP地址的最后一段
Ubuntu:
#!/bin/bash
ADDR=`ifconfig eth0|grep -i "inet\>"|awk '{print $2}'`
NUM=${ADDR##*.}
hostname Server$NUM
echo "Server$NUM" > /etc/hostname
echo "127.0.0.1 Server$NUM" >> /etc/hosts
CentOS:
#!/bin/bash
ADDR=`ifconfig eth0|grep -i "inet\>"|awk '{print $2}'`
NUM=${ADDR##*.}
hostname Server$NUM
sed -i "s/HOSTNAME.*/HOSTNAME=Server$NUM/g" /etc/sysconfig/network
echo "127.0.0.1 Server$NUM" >> /etc/hosts
阅读(1075) | 评论(0) | 转发(0) |