How to sync ntp with IST?

Hi,

I'm trying to synchronize the ntp with IST but unable to do it. Your input will be valuable for this issue?

root@Alphion:/# date
Tue May 21 07:29:43 UTC 2024

root@Alphion:/# cat /etc/config/system

config system
        option timezone 'GMT+6'
        option ttylogin '0'
        option log_size '64'
        option urandom_seed '0'
        option hostname 'Alphion'

config timeserver 'ntp'
        option enabled '1'
        option enable_server '0'
        list server '0.openwrt.pool.ntp.org'
        list server '1.openwrt.pool.ntp.org'
        list server '2.openwrt.pool.ntp.org'
        list server '3.openwrt.pool.ntp.org'

root@Alphion:/# ps | grep -i ntp
 3512 root      3532 S<   /usr/sbin/ntpd -n -N -S /usr/sbin/ntpd-hotplug -p 0.
24958 root      3324 S    grep -i ntp

Thanks
Khaleel Ahamed

You find out the addresses of your desired NTP servers, check their terms of usage if they allow using them like this - and configure them accordingly. It's in your own paste and should be relatively self-explaining.

I have tried to change the ntp server list but still its not working

works just fine

root@OpenWrt:~# ntpdate 0.in.pool.ntp.org
21 May 07:47:36 ntpdate[16523]: adjust time server 143.244.134.227 offset +0.009112 sec

have you restarted ntpd ?

If I'm understanding the OP correctly, NTP isn't actually the issue - it's the fact that the system is configured to use a timezone of GMT+6 but is displaying times in UTC.

Is that right, @akahamed1998 ?

Getting command not found
root@Alphion:/# ntpdate
/bin/ash: ntpdate: not found

Do i need to install anything?

ntpd is running via sysntpd
root@Alphion:/# ps | grep -i ntpd
3582 root 3408 S< /usr/sbin/ntpd -n -N -S /usr/sbin/ntpd-hotplug -p 0.
13161 root 3324 S grep -i ntpd

Yes, right i'm just trying to check whether the timezone configuration working properly or not and for that i have changed to GMT+6 but actually i need the timezone in IST.

Hi @akahamed1998

why you need "complete" NTP ?

there is a built in NTP client/server in OWRT "out-of-box"
no need to install anything

Hi @NPeca75

Actually, I'm trying to make the time based firewall rule for that ntp sync is must and when i'm testing with the firewall rule its not working due to incorrect time

aha, sorry
i saw

so i misunderstood your problem

ok, i am using this for TZ

        option zonename 'Europe/Belgrade'
        option timezone 'CET-1CEST,M3.5.0,M10.5.0/3'

and the time is correct on router

might require a zoneinfo-* package ?

I have installed the below listed packages but still the timezone configuration is not working

root@Alphion:/# opkg list | grep -i zoneinfo
zoneinfo-africa - 2021a-1
zoneinfo-asia - 2021a-1
zoneinfo-atlantic - 2021a-1
zoneinfo-australia-nz - 2021a-1
zoneinfo-core - 2021a-1
zoneinfo-europe - 2021a-1
zoneinfo-india - 2021a-1
zoneinfo-northamerica - 2021a-1
zoneinfo-pacific - 2021a-1
zoneinfo-poles - 2021a-1
zoneinfo-simple - 2021a-1
zoneinfo-southamerica - 2021a-1

What version of OpenWrt are you using because this timezone error was a known bug a couple of years ago.

1 Like

Hi @frollic

no, it is bare minimum build for 4/32
Owrt 23.05
and TZ file is correctly created in /tmp

root@r198.netdev.ele:/tmp$ cat /tmp/TZ 
CET-1CEST,M3.5.0,M10.5.0/3
root@r198.netdev.ele:/tmp$ 

edit:
nope

# CONFIG_BUSYBOX_DEFAULT_FEATURE_TIMEZONE is not set`

# Time Zone info
#
# CONFIG_PACKAGE_zoneinfo-africa is not set
# CONFIG_PACKAGE_zoneinfo-all is not set
# CONFIG_PACKAGE_zoneinfo-america is not set
# CONFIG_PACKAGE_zoneinfo-asia is not set
# CONFIG_PACKAGE_zoneinfo-atlantic is not set
# CONFIG_PACKAGE_zoneinfo-australia-nz is not set
# CONFIG_PACKAGE_zoneinfo-core is not set
# CONFIG_PACKAGE_zoneinfo-europe is not set
# CONFIG_PACKAGE_zoneinfo-indian is not set
# CONFIG_PACKAGE_zoneinfo-pacific is not set
# CONFIG_PACKAGE_zoneinfo-poles is not set
# CONFIG_PACKAGE_zoneinfo-simple is not set
# end of Time Zone info

AIUI you need to use the zone "Asia/Kolkata". It should be in the (very long!) dropdown menu in /cgi-bin/luci/admin/system/system, Time Synchronization tab.

Add the script of auto start of NTP on /etc/init.d/ntp_autostart.sh

OpenWRT modem doesn't consists RTC.

By configuring Zonename and timezone like below resolved the issue

   option zonename 'Asia/Kolkata'
    option timezone 'IST-5:30'

Thank you all...

I don’t think you have solved the actual problem, you have only defined a static time relative the utc time.
But if you have any kind if daylight saving time this won’t work automatically.

That timezone is indeed at a fixed offset from UTC, and India observes no DST periods at all.

Yes, you are right! another issues I faced with different distributions. So, I had created one auto turn on script for openwrt using bash. Everytime a manual input doesn't help to resolve.

So, Kindly refer the below:

To create a script that automatically updates the system time to the Asia/Kolkata timezone for OpenWrt and sets this to run at startup, follow these steps:

  1. Create the script to set the timezone and update time:

    • Open a terminal and create a new script file, for example, 'set_time.sh'.

      nano /etc/init.d/set_time.sh

  2. Add the following script content:

   #!/bin/sh /etc/rc.common

   START=99

   start() {
       echo "Setting timezone to Asia/Kolkata"
       uci set system.@system[0].timezone='IST-5:30'
       uci set system.@system[0].zonename='Asia/Kolkata'
       uci commit system
       /etc/init.d/system reload

       echo "Updating system time"
       ntpd -q -p pool.ntp.org
   }

   stop() {
       # No specific actions required on stop
       :
   }

  1. Make the script executable:

    chmod +x /etc/init.d/set_time.sh
    '''

  2. Enable the script to run at startup:

    /etc/init.d/set_time.sh enable

  3. Start the script manually (optional, for immediate effect):

    /etc/init.d/set_time.sh start

This script performs the following actions:

  • Sets the timezone to 'Asia/Kolkata' using the 'uci' commands.
  • Commits the changes and reloads the system settings.
  • Updates the system time using the NTP (Network Time Protocol) with a query to the 'pool.ntp.org' server.

Explanation of the script:

  • The script uses OpenWrt's 'rc.common' to create a service script that can be enabled to run at startup.
  • 'START=99' ensures the script runs towards the end of the startup sequence, after networking is up.
  • 'start' function sets the timezone and updates the system time.
  • 'stop' function is defined but does nothing (indicated by ':') because there are no specific actions required to stop the service.

By following these steps, you ensure that your OpenWrt device will automatically set the correct timezone and update its time at every startup.