IP 주소의 맨 뒷자리 숫자를 얻어오는 코드는 다음과 같다.
ifconfig | grep Bcast | awk '{print $2}' | cut -f 4 -d '.'
만약 숫자에 추가로 덧샘이나 뺄샘이 필요하다면 다음과 같이 수정 가능하다.
ifconfig | grep Bcast | awk '{print $2}' | cut -f 4 -d '.' | awk '{print $1 - 10}'
숫자 앞에 별도의 알파벳이나 기호 등을 붙이기 위해서는 다음과 같이 작성 할 수 있다.
's'$(ifconfig | grep Bcast | awk '{print $2}' | cut -f 4 -d '.')
이를 이용하여 hostname을 변경하는 방법은 아래와 같다.
hostnamectl set-hostname 's'$(ifconfig | grep Bcast | awk '{print $2}' | cut -f 4 -d '.')
매번 수동으로 바꿀 수 없음으로, crontab에 작업을 예약한다.
# m h dom mon dow user command
@reboot root hostnamectl set-hostname 's'$(ifconfig | grep Bcast | awk '{print $2}' | cut -f 4 -d '.')

![[Ubuntu] apt-get update error (403 Forbidden on nijel/phpmyadmin)](https://tech.sangron.com/wp-content/uploads/sites/2/2017/12/ubuntu_wallpaper_2-768x480.jpg)
![[C++] Google Test (GTest) Ubuntu에 적용하기](https://tech.sangron.com/wp-content/uploads/sites/2/2018/10/cpp_wallpaper-768x480.jpg)
![[Crypto Currency] Ubuntu에서 CCMiner로 Mining 시작하기](https://tech.sangron.com/wp-content/uploads/sites/2/2019/02/blank_500x500-768x480.jpg)
![[Python] Python 으로 Shell command 수행하기](https://tech.sangron.com/wp-content/uploads/sites/2/2018/02/python_wallpaper_3-768x480.jpg)