Linux
hostid 변경방법
Naan
2018. 4. 3. 19:53
반응형
source code
#!/bin/bash
#
# Purpose: Write the passed in parameter as hostid to /etc/hostid
# If no parameter is passed, write current hostid to /etc/hostid
# Author: Fazle Arefin
if [[ -n "$1" ]]; then
host_id=$1
# chars must be 0-9, a-f, A-F and exactly 8 chars
egrep -o '^[a-fA-F0-9]{8}$' <<< $host_id || exit 1
else
host_id=$(hostid)
fi
a=${host_id:6:2}
b=${host_id:4:2}
c=${host_id:2:2}
d=${host_id:0:2}
echo -ne \\x$a\\x$b\\x$c\\x$d > /etc/hostid &&
echo "Success" 1>&2
exit 0
위 소스코드를 복사해서 파일에 복사 하자
# vi hostid.sh
# chmod 755 hostid.sh
# hostid
02343f0c
# ./hostid.sh 0011aabb
0011aabb
Success
# hostid
0011aabb
# rm -Rf /etc/hostid
# hostid
02343f0c
/etc/hostid 파일을 삭제 하면 원상태로 돌아 온다.
728x90
반응형