# Update system time using NTP and NetworkManager (Gentoo)

*2010-11-29*

> Automatically synchronize Gentoo’s system clock with NTP when a network connection comes up using a NetworkManager dispatcher script.

On my laptop, I use NetworkManager to manage the LAN and WLAN interfaces.

The dispatcher script below starts `ntp-client` to synchronize the system clock when `eth0` or `wlan0` comes up. It stops the service when either interface goes down and ignores other interfaces and events. Replace `eth0` and `wlan0` with your interface names if they differ.

As root, save the following script as `/etc/NetworkManager/dispatcher.d/10-ntp-client`:

```bash
#!/bin/bash
IF=$1
STATE=$2

if [ "$IF" = "eth0" ] || [ "$IF" = "wlan0" ]; then
    if [ "$STATE" = "up" ]; then
        /etc/init.d/ntp-client start
    elif [ "$STATE" = "down" ]; then
        /etc/init.d/ntp-client stop
    fi
fi
```

Then make it executable:

```sh
chmod +x /etc/NetworkManager/dispatcher.d/10-ntp-client
```

The script requires Gentoo’s `net-misc/ntp` package and its `/etc/init.d/ntp-client` service.

