LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 06-28-2015, 08:56 AM   #1
tramni1980
Member
 
Registered: Jul 2006
Location: Köln, Germany
Distribution: Slackware64-14.2 & -current, DragonFly BSD, OpenBSD
Posts: 819

Rep: Reputation: 55
adjust time: sntp works, but ntpd does not?


Dear all,
I want to synchronise the system time at boot from the local time servers.
sntp works OK:
Code:
sntp -Ss -c bg.pool.ntp.org
The above command adjust the time successfulle within a few seconds.
However, the command:
Code:
ntpd -gqc /dev/null bg.pool.ntp.org
,
which should actually do the same, hangs and never releases the console.
Any clues?

Best regards,
Martin
 
Old 06-28-2015, 09:32 AM   #2
perbh
Member
 
Registered: May 2008
Location: Republic of Texas
Posts: 393

Rep: Reputation: 81
Just off the cuff (and x-ing my fingers hoping its right), one is a daemon (ntpd) and the other is not. You might have to background the daemon with a '&' at the end of your command ...
ntpdate (if it still exists) will do the same as sntp

Last edited by perbh; 06-28-2015 at 09:33 AM.
 
Old 06-28-2015, 10:08 AM   #3
mancha
Member
 
Registered: Aug 2012
Posts: 484

Rep: Reputation: Disabled
Quote:
Originally Posted by tramni1980 View Post
However, the command:
Code:
ntpd -gqc /dev/null bg.pool.ntp.org
,
which should actually do the same, hangs and never releases the console.
Any clues?
Hi. Can't repro - works here. Can you provide a bit more info:
  1. ntp version
  2. pastebin of ntpd.trace generated by:
    Code:
    strace -o ntpd.trace /usr/sbin/ntpd -gqc /dev/null bg.pool.ntp.org
--mancha
 
Old 06-28-2015, 10:51 AM   #4
tramni1980
Member
 
Registered: Jul 2006
Location: Köln, Germany
Distribution: Slackware64-14.2 & -current, DragonFly BSD, OpenBSD
Posts: 819

Original Poster
Rep: Reputation: 55
Dear mancha,
thank You very much for Your reply.
This is the output strace:
Code:
strace -o ntpd.trace /usr/sbin/ntpd -gqc /dev/null bg.pool.ntp.org
28 Jun 18:21:52 ntpd[29583]: ntpd 4.2.8p2@1.3265-o Fri Apr 10 18:50:36 UTC 2015 (1): Starting
28 Jun 18:21:52 ntpd[29583]: Command line: /usr/sbin/ntpd -gqc /dev/null bg.pool.ntp.org
28 Jun 18:21:52 ntpd[29583]: proto: precision = 0.043 usec (-24)
28 Jun 18:21:52 ntpd[29583]: line 0 column 0 syntax error, unexpected $end
28 Jun 18:21:52 ntpd[29583]: Listen and drop on 0 v6wildcard [::]:123
28 Jun 18:21:52 ntpd[29583]: Listen and drop on 1 v4wildcard 0.0.0.0:123
28 Jun 18:21:52 ntpd[29583]: Listen normally on 2 lo 127.0.0.1:123
28 Jun 18:21:52 ntpd[29583]: Listen normally on 3 ppp0 193.68.19.128:123
28 Jun 18:21:52 ntpd[29583]: Listen normally on 4 lo [::1]:123
28 Jun 18:21:52 ntpd[29583]: Listen normally on 5 eth0 [fe80::3a2c:4aff:feb5:5b1d%2]:123
28 Jun 18:21:52 ntpd[29583]: Listening on routing socket on fd #22 for interface updates
And here is the ntpd version:
Code:
ntpd --version
ntpd 4.2.8p2@1.3265-o Fri Apr 10 18:50:36 UTC 2015 (1)
Best regards,
Martin
 
Old 06-28-2015, 11:00 AM   #5
mancha
Member
 
Registered: Aug 2012
Posts: 484

Rep: Reputation: Disabled
Quote:
Originally Posted by tramni1980 View Post
This is the output strace:
Hi Martin.

The strace output I want to see should be in a newly-created file called ntpd.trace in the directory where you ran the command.

Because it hangs, let the strace command run for 10 seconds or so before exiting to let the trace file fill up with relevant info.

It might be a long file, so rather than paste the contents here directly, use an online bin (e.g. dpaste).

--mancha

Last edited by mancha; 06-28-2015 at 11:12 AM. Reason: pyto
 
Old 06-28-2015, 11:53 AM   #6
tramni1980
Member
 
Registered: Jul 2006
Location: Köln, Germany
Distribution: Slackware64-14.2 & -current, DragonFly BSD, OpenBSD
Posts: 819

Original Poster
Rep: Reputation: 55
Hello, Mancha,

Thank You for Your reply. The contents of the ntpd.trace file is viewable from:

https://dpaste.de/2xeT

Best regards,

Martin
 
Old 06-28-2015, 12:39 PM   #7
mancha
Member
 
Registered: Aug 2012
Posts: 484

Rep: Reputation: Disabled
Hi Martin.

That trace helped a lot. We're indeed not getting a response on the socket (no recvmsg after the sendto on line 422).

Can we look at network traffic while you make the ntp request? For that, open up two terminals.

In terminal #1 run:

Code:
# tcpdump -v -i any udp port 123
Once that's running, in terminal #2 run:

Code:
# /usr/sbin/ntpd -gqc /dev/null bg.pool.ntp.org
In addition to the tcpdump output from above, can you please provide output from:

Code:
# ip a
Code:
# ip r
Code:
# iptables-save
--mancha
 
Old 06-28-2015, 11:23 PM   #8
tramni1980
Member
 
Registered: Jul 2006
Location: Köln, Germany
Distribution: Slackware64-14.2 & -current, DragonFly BSD, OpenBSD
Posts: 819

Original Poster
Rep: Reputation: 55
Dear Mancha,

Thank You very much for Your helpfulness. Here is the output of the commands in the order You suggested them:

Code:
bash-4.2# tcpdump -v -i any udp port 123
tcpdump: listening on any, link-type LINUX_SLL (Linux cooked), capture size 65535 bytes
07:16:59.792303 IP (tos 0xb8, ttl 64, id 14462, offset 0, flags [DF], proto UDP (17), length 76)
    193.68.19.128.ntp > dns2.mnet.bg.ntp: NTPv4, length 48
        Client, Leap indicator: clock unsynchronized (192), Stratum 0 (unspecified), poll 6 (64s), precision -24
        Root Delay: 0.000000, Root dispersion: 0.000045, Reference-ID: (unspec)
          Reference Timestamp:  0.000000000
          Originator Timestamp: 0.000000000
          Receive Timestamp:    0.000000000
          Transmit Timestamp:   3644540219.792285501 (2015/06/29 07:16:59)
            Originator - Receive Timestamp:  0.000000000
            Originator - Transmit Timestamp: 3644540219.792285501 (2015/06/29 07:16:59)
07:16:59.821577 IP (tos 0xc0, ttl 52, id 0, offset 0, flags [DF], proto UDP (17), length 76)
    dns2.mnet.bg.ntp > 193.68.19.128.ntp: NTPv4, length 48
        Server, Leap indicator:  (0), Stratum 3 (secondary reference), poll 6 (64s), precision -21
        Root Delay: 0.081512, Root dispersion: 0.116455, Reference-ID: zg2.ntp.CARNet.hr
          Reference Timestamp:  3644539377.212144181 (2015/06/29 07:02:57)
          Originator Timestamp: 3644540219.792285501 (2015/06/29 07:16:59)
          Receive Timestamp:    3644540219.740907728 (2015/06/29 07:16:59)
          Transmit Timestamp:   3644540219.740929722 (2015/06/29 07:16:59)
            Originator - Receive Timestamp:  -0.051377803
            Originator - Transmit Timestamp: -0.051355808
07:18:05.792267 IP (tos 0xb8, ttl 64, id 14463, offset 0, flags [DF], proto UDP (17), length 76)
    193.68.19.128.ntp > dns2.mnet.bg.ntp: NTPv4, length 48
        Client, Leap indicator: clock unsynchronized (192), Stratum 0 (unspecified), poll 6 (64s), precision -24
        Root Delay: 0.000000, Root dispersion: 0.001037, Reference-ID: (unspec)
          Reference Timestamp:  0.000000000
          Originator Timestamp: 0.000000000
          Receive Timestamp:    0.000000000
          Transmit Timestamp:   3644540285.792254745 (2015/06/29 07:18:05)
            Originator - Receive Timestamp:  0.000000000
            Originator - Transmit Timestamp: 3644540285.792254745 (2015/06/29 07:18:05)
07:18:05.818582 IP (tos 0xc0, ttl 52, id 0, offset 0, flags [DF], proto UDP (17), length 76)
    dns2.mnet.bg.ntp > 193.68.19.128.ntp: NTPv4, length 48
        Server, Leap indicator:  (0), Stratum 3 (secondary reference), poll 6 (64s), precision -21
        Root Delay: 0.081512, Root dispersion: 0.117446, Reference-ID: zg2.ntp.CARNet.hr                                                                                                                                                     
          Reference Timestamp:  3644539377.212144181 (2015/06/29 07:02:57)                                                                                                                                                                   
          Originator Timestamp: 3644540285.792254745 (2015/06/29 07:18:05)                                                                                                                                                                   
          Receive Timestamp:    3644540285.740996479 (2015/06/29 07:18:05)                                                                                                                                                                   
          Transmit Timestamp:   3644540285.741017401 (2015/06/29 07:18:05)                                                                                                                                                                   
            Originator - Receive Timestamp:  -0.051258269                                                                                                                                                                                    
            Originator - Transmit Timestamp: -0.051237378                                                                                                                                                                                    
07:19:10.792266 IP (tos 0xb8, ttl 64, id 14464, offset 0, flags [DF], proto UDP (17), length 76)                                                                                                                                             
    193.68.19.128.ntp > dns2.mnet.bg.ntp: NTPv4, length 48                                                                                                                                                                                   
        Client, Leap indicator: clock unsynchronized (192), Stratum 0 (unspecified), poll 6 (64s), precision -24                                                                                                                             
        Root Delay: 0.000000, Root dispersion: 0.002014, Reference-ID: (unspec)                                                                                                                                                              
          Reference Timestamp:  0.000000000                                                                                                                                                                                                  
          Originator Timestamp: 0.000000000                                                                                                                                                                                                  
          Receive Timestamp:    0.000000000                                                                                                                                                                                                  
          Transmit Timestamp:   3644540350.792254626 (2015/06/29 07:19:10)                                                                                                                                                                   
            Originator - Receive Timestamp:  0.000000000                                                                                                                                                                                     
            Originator - Transmit Timestamp: 3644540350.792254626 (2015/06/29 07:19:10)                                                                                                                                                      
07:19:10.814428 IP (tos 0xc0, ttl 52, id 0, offset 0, flags [DF], proto UDP (17), length 76)                                                                                                                                                 
    dns2.mnet.bg.ntp > 193.68.19.128.ntp: NTPv4, length 48                                                                                                                                                                                   
        Server, Leap indicator:  (0), Stratum 3 (secondary reference), poll 6 (64s), precision -21                                                                                                                                           
        Root Delay: 0.081512, Root dispersion: 0.118423, Reference-ID: zg2.ntp.CARNet.hr                                                                                                                                                     
          Reference Timestamp:  3644539377.212144181 (2015/06/29 07:02:57)                                                                                                                                                                   
          Originator Timestamp: 3644540350.792254626 (2015/06/29 07:19:10)                                                                                                                                                                   
          Receive Timestamp:    3644540350.736711800 (2015/06/29 07:19:10)                                                                                                                                                                   
          Transmit Timestamp:   3644540350.736729979 (2015/06/29 07:19:10)
            Originator - Receive Timestamp:  -0.055542808
            Originator - Transmit Timestamp: -0.055524602
07:20:17.792298 IP (tos 0xb8, ttl 64, id 14465, offset 0, flags [DF], proto UDP (17), length 76)
    193.68.19.128.ntp > dns2.mnet.bg.ntp: NTPv4, length 48
        Client, Leap indicator: clock unsynchronized (192), Stratum 0 (unspecified), poll 6 (64s), precision -24
        Root Delay: 0.000000, Root dispersion: 0.003021, Reference-ID: (unspec)
          Reference Timestamp:  0.000000000
          Originator Timestamp: 0.000000000
          Receive Timestamp:    0.000000000
          Transmit Timestamp:   3644540417.792287468 (2015/06/29 07:20:17)
            Originator - Receive Timestamp:  0.000000000
            Originator - Transmit Timestamp: 3644540417.792287468 (2015/06/29 07:20:17)
07:20:17.824595 IP (tos 0xc0, ttl 52, id 0, offset 0, flags [DF], proto UDP (17), length 76)
    dns2.mnet.bg.ntp > 193.68.19.128.ntp: NTPv4, length 48
        Server, Leap indicator:  (0), Stratum 3 (secondary reference), poll 6 (64s), precision -21
        Root Delay: 0.081512, Root dispersion: 0.119430, Reference-ID: zg2.ntp.CARNet.hr
          Reference Timestamp:  3644539377.212144181 (2015/06/29 07:02:57)
          Originator Timestamp: 3644540417.792287468 (2015/06/29 07:20:17)
          Receive Timestamp:    3644540417.736084342 (2015/06/29 07:20:17)
          Transmit Timestamp:   3644540417.736101150 (2015/06/29 07:20:17)
            Originator - Receive Timestamp:  -0.056203156
            Originator - Transmit Timestamp: -0.056186296
^C
8 packets captured
8 packets received by filter
0 packets dropped by kernel

Code:
root@marto:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 38:2c:4a:b5:5b:1d brd ff:ff:ff:ff:ff:ff
    inet6 fe80::3a2c:4aff:feb5:5b1d/64 scope link 
       valid_lft forever preferred_lft forever
3: ppp0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1480 qdisc pfifo_fast state UNKNOWN qlen 3
    link/ppp 
    inet 193.68.19.128 peer 193.68.18.180/32 scope global ppp0
       valid_lft forever preferred_lft forever
Code:
root@marto:~# ip r
default dev ppp0  scope link 
127.0.0.0/8 dev lo  scope link 
193.68.18.180 dev ppp0  proto kernel  scope link  src 193.68.19.128
Code:
root@marto:~# iptables-save
# Generated by iptables-save v1.4.20 on Mon Jun 29 07:19:35 2015
*filter
:INPUT ACCEPT [26909:20598538]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [24830:2937215]
-A INPUT -i ppp+ -p udp -m udp --dport 0:1023 -j LOG
-A INPUT -i ppp+ -p tcp -m tcp --dport 0:1023 -j LOG
-A INPUT -i ppp+ -p udp -m udp --dport 0:1023 -j DROP
-A INPUT -i ppp+ -p tcp -m tcp --dport 0:1023 -j DROP
-A INPUT -i ppp+ -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j LOG
-A INPUT -i ppp+ -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j DROP
-A INPUT -i ppp+ -p icmp -m icmp --icmp-type 8 -j DROP
COMMIT
# Completed on Mon Jun 29 07:19:35 2015
Best regards,
Martin
 
Old 06-29-2015, 12:16 AM   #9
mancha
Member
 
Registered: Aug 2012
Posts: 484

Rep: Reputation: Disabled
Hi - thanks for the output.

My hunch was correct, your firewall is blocking the reply.

The reason sntp is working for you is because it uses random high ports. On the other hand, ntpd uses a low port (port 123 locally)
and your firewall blocks incoming packets to low ports (1023 and lower).

Now, though UDP is technically stateless, Linux's netfilter connection tracking system is clever and has ways of determining if an
incoming UDP datagram is part of an existing connection you previously established.

So, a possible solution for your issue is to permit incoming packets on the ppp0 interface that are part of an existing connection
(i.e. replies) while still blocking new incoming connections to ports 1-1023. This can be achieved by inserting the rule in red:

Code:
-A INPUT -i ppp+ -p udp -m udp --dport 0:1023 -j LOG
-A INPUT -i ppp+ -p tcp -m tcp --dport 0:1023 -j LOG
-A INPUT -i ppp+ -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i ppp+ -p udp -m udp --dport 0:1023 -j DROP
-A INPUT -i ppp+ -p tcp -m tcp --dport 0:1023 -j DROP
-A INPUT -i ppp+ -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j LOG
-A INPUT -i ppp+ -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j DROP
-A INPUT -i ppp+ -p icmp -m icmp --icmp-type 8 -j DROP
Note: order is important so make sure you insert the rule where I placed it (i.e. as rule #3).

--mancha

PS If you want to only allow established/related packets in to UDP/123 (which is all you will need for ntpd to work as you want it),
you can use this more restrictive rule instead:
Code:
-A INPUT -i ppp+ -p udp -m udp --dport 123 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

Last edited by mancha; 06-29-2015 at 01:17 AM. Reason: tidy
 
Old 06-29-2015, 11:42 PM   #10
tramni1980
Member
 
Registered: Jul 2006
Location: Köln, Germany
Distribution: Slackware64-14.2 & -current, DragonFly BSD, OpenBSD
Posts: 819

Original Poster
Rep: Reputation: 55
Dear Mancha,

Thank You very much for Your helpfulness and collaboration. I just corrected the firewall-standalone file
in the ppp directory and now ntpd -gq works. Thank You very much!

Best regards,
Martin
 
Old 06-30-2015, 09:12 PM   #11
mancha
Member
 
Registered: Aug 2012
Posts: 484

Rep: Reputation: Disabled
Quote:
Originally Posted by tramni1980 View Post
Thank You very much for Your helpfulness and collaboration. I just corrected the firewall-standalone file
in the ppp directory and now ntpd -gq works. Thank You very much!
You're welcome Martin - glad you've got it working.

An ancillary benefit is others who've been reading this thread might have learned a thing or two from our exchange.

--mancha

Last edited by mancha; 06-30-2015 at 09:14 PM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ntpd - time server, not time source bramankp Linux - Server 4 07-15-2011 08:58 AM
ntpdate/ntpd time is in UTC instead of local time? m4rtin Linux - Software 7 05-06-2011 07:57 AM
ntpd does not adjust system clock kannerke Linux - Software 1 01-15-2009 10:31 AM
Despite ntpd and hourly `hwclock --adjust`, I had to `ntpdate` to fix 5 minute drift? GrapefruiTgirl Linux - Software 3 06-14-2008 11:44 AM
how to check if ntpd works jetfreggel Linux - Networking 6 11-30-2002 02:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 11:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration