---
# System prepended metadata

title: Customized NTP Server

---

# Customized NTP Server
* 下載ntp service
```bash=
apt-get install ntp
```
* 下載完ntp service後需將/etc/ntp.conf裡預設的上層NTP Server註解掉，否則預設NTP會每64秒去sync上層NTP server，如果系統時間與上層NTP server相差太多，ntp service會報錯。
```bash=
vi /etc/ntp.conf
```
```vi=
# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
pool 0.ubuntu.pool.ntp.org iburst
pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst

# Use Ubuntu's ntp server as a fallback.
pool ntp.ubuntu.com
```
將以上6~9行、12行註解
```vi=
# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
#pool 0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst

# Use Ubuntu's ntp server as a fallback.
#pool ntp.ubuntu.com
```
> 錯誤訊息example:
> ntp.service: Main process exited, code=exited, status=255/EXCEPTION
ntp.service: Failed with result 'exit-code'.
* 註解後重啟ntp service
```bash=
systemctl restart ntp
system ntp status # 查看ntp sevice狀態
date +"%Y-%m-%d %H:%M:%S" # 更改系統時間
```
* 重啟完後再更改時間就不會受到上層NTP server影響
可在另外一台PC上用ntpdate測試sync到customized NTP server
```bash=
apt-get install ntpdate
ntpdate {customized_ntp_ip}
ntpdate -d {customized_ntp_ip} # 依debug模式測試ntpdate
```
---
參考資料:
1. [Setup NTP](https://linuxconfig.org/stay-time-synchronized-with-internet-time-server)
2. [NTP service error message解釋](https://github.com/coreos/bugs/issues/61)
3. [ntpdate command](https://linux.die.net/man/8/ntpdate)