环境加固之NTP

时间:2023-02-16 11:05:00

一、直接关闭ntp服务

1、如果没有必要,可以关闭ntp服务
systemctl stop ntpd
systemctl disable ntpd

二、开启服务,加固

1、端口加固
ntp默认开启四个监听ip:端口
ss -tulnp|grep ntp
"udp 192.168.10.131:123
udp 127.0.0.1:123
udp 0.0.0.0:123
[::]:123"

vi /etc/ntp.conf
#指定监听IP,主要是为了去掉全网监听
interface ignore wildcard
interface listen 127.0.0.1 #即使不写这一行,它默认也会监听IP127.0.0.1
interface listen 192.168.10.131

2、关闭现在NTP服务的monlist功能
在ntp.conf配置文件中增加(或修改)"disable monitor"选项

3、作为服务端权限设置
将配置文件所有restrict开头的注释掉
#restrict -4 default kod notrap nomodify nopeer noquery limited
#restrict -6 default kod notrap nomodify nopeer noquery limited
#restrict 127.0.0.1
#restrict ::1
最后增加
restrict -4 default noquery ignore

使用restrict管理权限控制
restrict [address] mask [mask] [parameter]
其中IP地址也可以是default ,default 就是指所有的IP
其中parameter的参数主要有下面这些:
ignore: 拒绝所有类型的NTP联机;
nomodify: 客户端不能使用ntpc与ntpq这两个程序来修改服务器的时间参数,但客户端仍可透过这个主机来进行网络校时;
noquery: 客户端不能使用ntpq,ntpc等指令来查询时间服务器,等于不提供NTP的网络校时;
notrap: 不提供trap这个远程事件登录(remote event logging)的功能;notrust: 拒绝没有认证的客户端;
nopeer:用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟
kod:访问违规时发送 KoD 包。
restrict -6 表示IPV6地址的权限设置。
如果你没有在 parameter 的地方加上任何参数的话,这表示该IP或网段不受任何限制。
注意:没有限制需求不要配置restrict,默认是不限制的。