레이블이 Linux인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Linux인 게시물을 표시합니다. 모든 게시물 표시

2018년 2월 5일 월요일

Change Linux hostid through shell script

check your current hostid
$ hostid
007f0101

make shell
$ vi hostid.sh

copy and paste below 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 [fazlearefin at yahoo dot com]
#

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

run script
# sh hostid.sh AABBCCDD
AABBCCDD
Success

If shell script doesn't work, maybe you should change mode (chmod)
# chmod 755 hostid.sh

check your changed hostid
$ hostid
AABBCCDD
참고 : https://github.com/fazlearefin/sysadm-scripts/blob/master/hostid.sh

2018년 2월 3일 토요일

Set static IP on Ubuntu 16.04

open file
# vi /etc/network/interfaces


Below is my default contents
# The primary network interface
auto enp0s3
iface enp0s3 inet dhcp


change to static address
# The primary network interface
auto enp0s3
iface enp0s3 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx
dns-nameservers xxx.xxx.xxx.xxx

network restart
# systemctl restart networking.service