Check NTP server working or not, Check NTP server Date and Time – Windows, Linux

Windows

1 Use Win + R to open run Window

Microsoft Windows - Run window
Microsoft Windows – Run window

2 Type cmd, then hit Enter key

Microsoft Windows - Run window - cmd.exe
Microsoft Windows – Run window – cmd.exe

The command we use is in following format:

w32tm /stripchart /computer:domainnameORipaddress /dataonly /samples:5

3 Enter following command to test “time.windows.com”

w32tm /stripchart /computer:time.windows.com /dataonly /samples:5
Microsoft Windows - CMD -   w32tm /stripchart /computer:time.windows.com /dataonly /samples:5 output
Microsoft Windows – CMD – w32tm /stripchart /computer:time.windows.com /dataonly /samples:5 output

Bonus: Other commands

1 Show the current time zone settings:

w32tm /tz

2 List external NTP servers (peers)

w32tm /query /peers
Microsoft Windows - CMD -  w32tm /query /peers output
Microsoft Windows – CMD – w32tm /query /peers output

Note! If you have encountered this error: “The following error occurred: The service has not been started. (0x80070426)”, you need to start the “Windows Time” service, you can start a elevated cmd or PowerShell by using Win + X key combination then select “Command Prompt (Admin)” or “Windows PowerShell (Admin)” then type “sc start W32Time” to start the Windows Time service or using Run window and type “services.msc” then find “Windows Time” service and start it.

3 Restore Windows Time service settings to default

C:\>net stop w32time
C:\>w32tm /unregister
C:\>w32tm /register
C:\>net start w32time

4 Re-sync Time

Resynchronize the clock as soon as possible, disregarding all accumulated error statistics. If no computer is specified, the local computer will resynchronize. The command will wait for resynchronization unless the /nowait switch is used.

w32tm /resync

5 Redirect the network configuration and Re-sync time

Force redetection of network resource before resynchronization.

w32tm /resync /rediscover
Microsoft Windows - PowerShell - w32tm /resync /rediscover output
Microsoft Windows – PowerShell – w32tm /resync /rediscover output

6 Check current NTP configuration

Show Information:

w32tm /query /status
Microsoft Windows - PowerShell -  w32tm /query /status  output
Microsoft Windows – PowerShell – w32tm /query /status output

Show Configuration:

w32tm /query /configuration
Microsoft Windows - PowerShell -  w32tm /query /configuration  output
Microsoft Windows – PowerShell – w32tm /query /configuration output

Linux

1 ntpdate -q domainnameORipaddress

ntpdate -q time.windows.com
Linux - Terminal - ntpdate -q time.windows.com output
Linux – Terminal – ntpdate -q time.windows.com output

2 ntpq -p domainnameORipaddress

ntpq -p 192.168.1.1

Ubuntu 18.04.3 LTS /usr/lib/apt/methods/http: relocation error

When updating package list with sudo apt update, following error comes up

/usr/lib/apt/methods/http: relocation error: /usr/lib/x86_64-linux-gnu/libgnutls.so.30: symbol _idn2_punycode_decode version IDN2_0.0.0 not defined in file libidn2.so.0 with link time reference    
Reading package lists… Done
E: Method http has died unexpectedly!
E: Sub-process http returned an error code (127)
E: Method /usr/lib/apt/methods/http did not start correctly

1 Download http://ftp.us.debian.org/debian/pool/main/libi/libidn2/libidn2-0_2.0.5-1_amd64.deb

2 Run sudo dpkg -i path/libidn2-0_2.0.5-1_amd64.deb

Linux Server Tips

Keywords: Linux Server Tips, Linux commands

1 Check last login details, who, when

“w” to check last start up time, currently logged in users

“last” to check logins

“who” Currently logged in users’ details

“lastlog” Users’ last login time

“whoami” Show current username

“finger” Find user information

“id” Current user uid, gid and group information

2 Find ports

netstat -anp | grep 443

lsof -i:443

3 Compile source code

“ar” extract archive, archived installation files

“./configure” configure to fit current systems

“make” compile the source code into binary files e.g. executables

“make install” install the compiled program

4 Linux Directories

“/boot”: Linux kernel, boot configuration etc.

“/bin”: Basic user commands, can be run by users

“/dev”: HDD, Keyboard, Mouse, DVD/CD-ROM device files

“/etc”: Configuration files

“/home”: Users’ working directories (home directory etc.)

“/sbin”: Basic management commands, normally only accessable by administrators

“/usr”: Application, source code files, documents etc.

“/var”: Logs, user mail, process data

“/tmp”: Temporary files

5 Common log files

“/var/log/messages”: Kernel and public messages

“/var/log/cron”: Scheduled Tasks/Crontab

“/var/log/dmesg”: System boot log

“/var/log/maillog”: System mail log

“/var/log/secure”: Access control log

6 Common Linux boot files

“/etc/fstab”: Auto mount on boot

“/etc/initab”: Define default boot level

“/etc/rc.local”: Define custom boot tasks

7 suid, sgid, sticky bit

suid: Run as the owner of the file/binary

sgid: Files created within the folder inherits the folder owner’s permission

sticky bit: Users can only modify, delete wheir own files

8 Check process: “ps”, “top”

9 Check process scheduling: “at”, “crontab”, “batch”, “kill”

10 Extract files

1.*.tarExtract using tar -xvf
2.*.gz Extract using gzip -d OR gunzip
3.*.tar.gz Extract using tar -xzf
4.*.bz2 Extract using bzip2 -d OR bunzip2
5.*.tar.bz2 Extract using tar -xjf
6.*.Z Extract using uncompress
7.*.tar.Z Extract using tar -xZf
8.*.rar Extract using unrar e
9.*.zip Extract using unzip

11 Mounting Windows share

mount -t cifs -o username=windowsusername, password="windowspassword" //ipaddress/folder mnt/linuxtargetfolder

OR

mount.cifs //ipaddress/folder /mnt.linuxtargetfolder -o username="windowsusername", password="windowspassword"

Change hostname in Linux operating systems

Usually hostname is configured during system installating.

Here is how to change the hostame on up to date Linux Linux distributions with systemd installed by default.

To understand what is hostname: https://en.wikipedia.org/wiki/Hostname

Show Current hostname

To show current hostname, we can use this command: hostnamectl

(It will show information including: Static hostname, Icon name, Chassis, Machine ID, Boot ID, Virtualization, Operating System, Kernel, Architecture)

[email protected]:~$ hostnamectl
    Static hostname: ubuntu
          Icon name: computer-vm
            Chassis: vm
         Machine ID: eee8d3edb062470c8afc7e097eb9b962
            Boot ID: 126a5a692e754b56b59dc75f8f045984
     Virtualization: vmware
   Operating System: Ubuntu 19.04
             Kernel: Linux 5.0.0-23-generic
       Architecture: x86-64
Output of hostnamectl
Output of hostnamectl

Change hostname

Command: hostnamectl set-hostname newhostname

[email protected]:~$ hostnamectl set-hostname newubuntu
 [email protected]:~$ hostnamectl
    Static hostname: newubuntu
          Icon name: computer-vm
            Chassis: vm
         Machine ID: eee8d3edb062470c8afc7e097eb9b962
            Boot ID: 126a5a692e754b56b59dc75f8f045984
     Virtualization: vmware
   Operating System: Ubuntu 19.04
             Kernel: Linux 5.0.0-23-generic
       Architecture: x86-64
Output of hostnamectl set-hostname newhostname
Output of hostnamectl set-hostname newhostname

hostnamectl set-hostname will return 0 if the command was successfully executed, if the command failed, it will return non 0 results.

To check if the hostname is changed or not, just execute hostnamectl command again to verify.

Depend on your platform or Linux distro, you may need to modify the command to achieve same results.

Turn off display automatically on Ubuntu 18.04 server with text boot

Open /etc/default/grub in any text editor (e.g. sudo nano, sudo vi etc.)

Add consoleblank=0 to GRUB_CMDLINE_LINUX_DEFAULT= as parameter.

e.g.

If it is GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" change to GRUB_CMDLINE_LINUX_DEFAULT="quiet splash consoleblank=0"

If it is GRUB_CMDLINE_LINUX_DEFAULT="text" change to GRUB_CMDLINE_LINUX_DEFAULT="text consoleblank=0"

Finally, do sudo update-grub then reboot.

Note: If you already boot from text mode, chance is you will have GRUB_CMDLINE_LINUX_DEFAULT=”text”

What does this change do?

Without consoleblank=0 after the server boot into text mode, after timeout, the screen will go blank with screen powered on (Dimmed screen), adding consoleblank=0 at the end of GRUB_CMDLINE_LINUX_DEFAULT=, will actually turn off the display after timeout instead of dim the display.

Alternatively, if you are running server on a laptop, the easiest way is to close the lid and still keep the server running, refer to this post: How to: Keep Ubuntu Server running on laptop with lid closed

How to: Ubuntu switch php-fpm version

Install newer php-fpm version e.g. 7.3

1. sudo apt install php7.3-fpm

2. sudo a2enconf php7.3-fpm

Notes:

a2enconf is a script that enables the specified configuration file within the apache2 configuration. It does this by creating symlinks within /etc/apache2/conf-enabled. Likewise, a2disconf disables a specific configuration part by removing those symlinks. It is not an error to enable a configuration which is already enabled, or to disable one which is already disabled.

Ubuntu Manual

a2enmod is a script that enables the specified module within the apache2 configuration. It does this by creating symlinks within /etc/apache2/mods-enabled. Likewise, a2dismod disables a module by removing those symlinks. It is not an error to enable a module which is already enabled, or to disable one which is already disabled.    – Ubuntu Manual