FreeBSD 10 & BIND 9.9

Setup chroot for bind 9 in FreeBSD 10
DNS again: a clarification
FreeBSD 10: Unbound and LDNS replacing BIND

interface "xn0" {
    supersede domain-name-servers 127.0.0.1;
}
Message from bind99-9.9.8_1:
**********************************************************************
*            _  _____ _____ _____ _   _ _____ ___ ___  _   _         *
*           / \|_   _|_   _| ____| \ | |_   _|_ _/ _ \| \ | |        *
*          / _ \ | |   | | |  _| |  \| | | |  | | | | |  \| |        *
*         / ___ \| |   | | | |___| |\  | | |  | | |_| | |\  |        *
*        /_/   \_\_|   |_| |_____|_| \_| |_| |___\___/|_| \_|        *
*                                                                    *
*   BIND requires configuration of rndc, including a "secret" key.   *
*    The easiest, and most secure way to configure rndc is to run    *
*   'rndc-confgen -a' to generate the proper conf file, with a new   *
*            random key, and appropriate file permissions.           *
*                                                                    *
*     The /usr/local/etc/rc.d/named script will do that for you.     *
*                                                                    *
**********************************************************************
$ /usr/local/sbin/named -fg -t /var/named -u bind -c /usr/local/etc/namedb/named.conf

MOOC – Massive Open Online Course / Online University

Udacity
Udemy
Pluralsight | Unlimited Online Developer, IT and Cyber Security Training
edX (Education X ?!)

Coursera
Wikipedia: Coursera

Kiron University
Wikipedia: Kiron Open Higher Education

Kurse

Kiron University

Multivariable calculus – Derivatives of multivariable functions

Udemy

Solve 100 Python Exercises to Boost your Python Skills
Python Bootcamp: Vom Anfänger zum Profi, inkl. Data Science
Python für Data Science, Maschinelles Lernen & Visualization

Christian Heigele

Kommt halt drauf an was du suchst.

Udacity hat richtige Kurse mit richtigem Lerninhalt und druck, mit ein bisschen Glück werden dir die Zertifikate auch hier in Europa angerechnet, kosten aber auch echtes Geld. Also hundert Dollar pro Kurs oder entsprechend mehr für so Mini Studiengänge.

Pluralsight kann ich für aufbessern von Programmiertechniken, Pattern, Sprachdetails… Recht empfehlen. Ein Teil davon ist auch in einem MSDN Account dabei, kann sich lohnen.

Udemy ist eher so ein bisschen Hobby für Leute die neue Themen lernen wollen, aber nicht allzu in die Tiefe gehen wollen. Ist wirklich nett, und kostet in den Sales auch echt nicht viel. Ich hab mir da ein paar Kurse rausgelassen um mich während der Täglichen Pendelei durchlesen/hören.

ntpd / ntpq Internals

Documentation

Wikipedia: ntpd (de)
Wikipedia: ntpd (en)
The NTP FAQ and HOWTO, Understanding and using the Network Time Protocol (2006-11-21)
Network Time Synchronization Research Project (with PowerPoint/PDF presentations)
The Network Time Protocol (NTP) Distribution (31-Mar-2014 05:41)
The Network Time Protocol (NTP) Distribution (07-Nov-2009 20:43 UTC)
Performance Metrics for root distance statistic (root delay, root dispersion), 26.07.2015

support.ntp.org Wiki

The NTP Public Services Project
NTP Support Web
Configuring NTP
ntpd access restrictions

Timescale

Major definitions of time

  • Atomic Time – or TAI
  • Universal Time – or UT0 and UT1
  • oordinated Universal Time – or UTC
  • Unix epoch = 1 January 1970
  • NTP epoch = 1 January 1900
  • constant 2,208,988,800 between 1900 and 1970
  • TAI seconds: seconds since 01.01.1970 00:00 without leap seconds
  • UTC seconds: seconds since 01.01.1970 00:00 with leap seconds (today 36 leap seconds) without daylight-saving time and time-zone information
  • NTP seconds: seconds since 01.01.1900 00:00 with leap seconds without daylight-saving time and time-zone information

Create ntp time stamp from gettimeofday
NTP Timestamp calculation

ntp_fraction
a

Time, Clock, and Calendar Programming In C
NTP, UTC, and Working with Time on Linux
The Unix leap second mess
The NTP Era and Era Numbering
NTP Timestamp Calculations

gettimeofday() should never be used to measure time
C/C++ tip: How to measure elapsed real time for benchmarking

stackoverflow

Create ntp time stamp from gettimeofday
Measure time in Linux – getrusage vs clock_gettime vs clock vs gettimeofday?
faster equivalent of gettimeofday
How do I get the unix timestamp in C as an int?

Manual Pages

Ubuntu Wily: man ntp.conf
FreeBSD 10.2: man ntp.conf

Reference Clock

Generic Reference Driver

IPv6

RFC: Reference ID for NTPv6
REFID Format
Updating the REFID format

HowTos

Ubuntuuser.de: Systemzeit
NTP Server – Stratum Levels Explained
The Raspberry Pi as a Stratum-1 NTP Server
How to build a stratum 1 NTP server with GPS time reference
Setting up a local stratum 2 NTP server
NTP-Deamon Konfiguration
Network Time Protocol

Root distance / dispersion

Root delay and Root dispersion values in NTP protocol?
NTPD not updating time date on CENTOS

FAQ

Question

powerpc-e300c3-linux-gnu-gcc -o ntpd ntp_config.o ntp_io.o \
ntp_parser.o ntp_scanner.o ntpd.o ntpd-opts.o \
-L. -lopts -lntp -lntpd -lrt -lcap -lm -lssl -lcrypto

ntpd.o: In function `ntpdmain':
./libntpd.a(ntp_control.o): In function `ctl_putadr':
src/ntpd/ntp_control.c:1678: undefined reference to `numtoa'
./libntpd.a(ntp_control.o): In function `ctl_putsys':
src/ntpd/ntp_control.c:2214: undefined reference to `k_st_flags'
./libntpd.a(ntp_control.o): In function `send_restrict_entry':
src/ntpd/ntp_control.c:4239: undefined reference to `res_match_flags'
src/ntpd/ntp_control.c:4240: undefined reference to `res_access_flags'
./libntpd.a(ntp_control.o): In function `write_variables':
src/ntpd/ntp_control.c:3283: undefined reference to `atoint'
./libntpd.a(ntp_control.o): In function `report_event':
src/ntpd/ntp_control.c:4773: undefined reference to `eventstr'
src/ntpd/ntp_control.c:4741: undefined reference to `eventstr'

Answer

Libraries order were not right

before:
-lopts -lntp -lntpd

after:
-lntpd -lntp -lopts

Is it possible to have circular dependencies?
Resolving circular dependencies by linking the same library twice?
Avoiding Linking Problems, Darryl Gove and Stephen Clamage, May 2011

-lfoo -lbar -lfoo
or
-Wl,--start-group -lfoo -lbar -Wl,--end-group

Question

How does asynchronouse / non-blocking sockets work?
non-blocking sockets + signal SIGALRM

Answer

SIGALRM, setitimer(), sleep(), select()
select() returns that socket is ready when SIGALRM
Unix signal handling example in C, SIGINT, SIGALRM, SIGHUP…

If any of these (as well as other) system calls is interrupted by a signal, such as SIGALRM or SIGIO, the call will return -1 and the variable errno will be
set to EINTR 2. The system call will be automatically restarted. It may be advisable to reset errno to zero.

Berkeley UNIX System Calls and Interprocess Communication
Unix connect() and interrupted system calls
c / interrupted system call / fork vs. thread
System call interrupted by a signal still has to be completed
EINTR and non-blocking calls
Apple: Avoiding Common Networking Mistakes
glibc: Waiting for Input or Output
select() usage examples
System call error handling

Question

How to listen only on specific interfaces?

Answer

How to prevent ntpd to listen on 0.0.0.0:123?
Does NTPd have to listen on an interface or address for updating the server time?

Question

No header files for simulation / standalone

[CC] src/ntpd/cmd_args.c
gcc -o obj/osa541x_sim/libntpd.a/ntpd/cmd_args.o -c src/ntpd/cmd_args.c -Iinclude/config/x86 -DHAVE_CONFIG_H -Iinclude -Wall -Wcast-align -Wcast-qual -Wmissing-prototypes -Wpointer-arith -Wshadow -Winit-self -Wstrict-overflow -Wno-strict-prototypes -g -O2 
In file included from include/ntp.h:14:0,
                 from include/ntpd.h:11,
                 from src/ntpd/cmd_args.c:8:
include/ntp_crypto.h:27:25: fatal error: openssl/evp.h: No such file or directory

Answer

Install header files

$ sudo apt-get install libssl-dev

Question

YACC not found

[CC] src/ntpd/ntp_io.c
gcc -o obj/osa541x_sim/advaNtpd/ntpd/ntp_io.o -c src/ntpd/ntp_io.c -Iinclude/config/x86 -DHAVE_CONFIG_H -Iinclude -Wall -Wcast-align -Wcast-qual -Wmissing-prototypes -Wpointer-arith -Wshadow -Winit-self -Wstrict-overflow -Wno-strict-prototypes -g -O2
src/ntpd/ntp_io.c: In function ‘io_setbclient’:
src/ntpd/ntp_io.c:2672:5: warning: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow]
  if (nif > 0) {
     ^
src/ntpd/ntp_io.c:2672:5: warning: assuming signed overflow does not occur when simplifying conditional to constant [-Wstrict-overflow]
yacc  src/ntpd/ntp_parser.y 
make: yacc: Command not found
<builtin>: recipe for target 'src/ntpd/ntp_parser.c' failed
make: *** [src/ntpd/ntp_parser.c] Error 127

rsync

rsync – synchronizing two file trees
Use Rsync for Daily, Weekly and Full Monthly Backups
Rsync as a Backup Tool

$ rsync -a /boot/kernel{,-8.2}/
-a         = -rlptgoD

-r         = recurse into directories
-l         = copy symlinks as symlinks
-p         = Preserve permission
-t         = Preserve time
-g         = Preserve group
-o         = Preserve owner (user)
-D         = --devices --specials
--devices  = preserve device files (super-user only)
--specials = preserve special files

freebsd-update

FreeBSD Update
FreeBSD-Update (de)
FreeBSD Update (en)

Tech Stuff – FreeBSD Update Survival Guide

freebsd-update and custom kernels

Upgrades from one minor version of FreeBSD to another, like from FreeBSD 9.0 to FreeBSD 9.1, are called minor version upgrades. Major version upgrades occur when FreeBSD is upgraded from one major version to another, like from FreeBSD 9.X to FreeBSD 10.X. Both types of upgrades can be performed by providing freebsd-update with a release version target.

Upgrade to a new Patch-Level

FreeBSD 12.0-RELEASE-p9 GENERIC
$ freebsd-update fetch
$ freebsd-update install
$ reboot

FreeBSD 12.0-RELEASE-p10 GENERIC
$  freebsd-version -kru
-k   version and patch level of the installed kernel
-r   version and patch level of the running kernel
-u   version and patch level of the installed userland

12.0 to 12.2

# freebsd-update upgrade -r 12.2-RELEASE
src component not installed, skipped
Looking up update.FreeBSD.org mirrors... 2 mirrors found.
Fetching metadata signature for 12.0-RELEASE from update2.freebsd.org... done.
Fetching metadata index... done.
Fetching 2 metadata patches.. done.
Applying metadata patches... done.
Inspecting system... done.

The following components of FreeBSD seem to be installed:
kernel/generic kernel/generic-dbg world/base world/doc world/lib32

The following components of FreeBSD do not seem to be installed:
world/base-dbg world/lib32-dbg

Does this look reasonable (y/n)? y

Fetching metadata signature for 12.2-RELEASE from update2.freebsd.org... done.
Fetching metadata index... done.
Fetching 1 metadata patches. done.
Applying metadata patches... done.
Fetching 1 metadata files... done.
Inspecting system... done.
Fetching files from 12.0-RELEASE for merging... done.
Preparing to download files... done.
Fetching 10713 patches... [...]
Applying patches... done.
Fetching 11146 files... done.
Attempting to automatically merge changes in files... done.

The following changes, which occurred between FreeBSD 12.0-RELEASE and
FreeBSD 12.2-RELEASE have been merged into /etc/group:
[...]
Does this look reasonable (y/n)? y

The following changes, which occurred between FreeBSD 12.0-RELEASE and
FreeBSD 12.2-RELEASE have been merged into /etc/master.passwd:
[...]
Does this look reasonable (y/n)? y

The following changes, which occurred between FreeBSD 12.0-RELEASE and
FreeBSD 12.2-RELEASE have been merged into /etc/passwd:
[...]
Does this look reasonable (y/n)? y

The following changes, which occurred between FreeBSD 12.0-RELEASE and
FreeBSD 12.2-RELEASE have been merged into /etc/profile
[...]
Does this look reasonable (y/n)? y

The following files are affected by updates, but no changes have
been downloaded because the files have been modified locally:
[...]
The following files will be removed as part of updating to 12.2-RELEASE-p9:
[...]
The following files will be added as part of updating to 12.2-RELEASE-p9:
[...]
The following files will be updated as part of updating to 12.2-RELEASE-p9:
[...]
To install the downloaded upgrades, run "/usr/sbin/freebsd-update install".

Upgrade to a new Release Version

$ uname -a
FreeBSD gateway 10.0-RELEASE [...] GENERIC  amd64

$ freebsd-update upgrade -r 10.2-RELEASE
$ /usr/sbin/freebsd-update install
$ reboot
$ /usr/sbin/freebsd-update install
$ pkg upgrade -f
$ /usr/sbin/freebsd-update install
$ uname -a
FreeBSD ns2.te-clan.ch 10.1-RELEASE [...] NS2-BACHI-NET  amd64

$ df
Filesystem  1K-blocks    Used    Avail Capacity  Mounted on
/dev/ada0p2   2031132  969868   898776    52%    /      <== includes /boot
                                                            kernel uses ca. 450 MB
devfs               1       1        0   100%    /dev
/dev/ada0p3   8106716  452652  7005528     6%    /var
/dev/ada0p4   4053308   35020  3694024     1%    /tmp
/dev/ada0p6  64995324 7673760 52121940    13%    /usr
/dev/ada0p7  42651260   32836 39206324     0%    /web
/dev/ada0p8  26396824   32836 24252244     0%    /db
devfs               1       1        0   100%    /var/named/dev

$ cd /usr/src
$ make kernel __MAKE_CONF=/dev/null SRCCONF=/dev/null
/boot/kernel/kernel        <- GENERIC kernel
/boot/kernel.old/kernel    <- your kernel

$ rsync -a /boot/kernel /boot/GENERIC
$ rm /boot/kernel
$ mv /boot/kernel.old /boot/kernel

$ sysctl -n kern.bootfile
/boot/kernel.old/kernel

$ sysctl kern.bootfile=/boot/kernel/kernel
kern.bootfile: /boot/kernel.old/kernel -> /boot/kernel/kernel

$ sysctl -n kern.bootfile
/boot/kernel/kernel

$ freebsd-update upgrade -r 10.2-RELEASE
Looking up update.FreeBSD.org mirrors... none found.
Fetching public key from update.FreeBSD.org... done.
Fetching metadata signature for 10.1-RELEASE from update.FreeBSD.org... done.
Fetching metadata index... done.
Fetching 2 metadata files... done.
Inspecting system... done.

WARNING: This system is running a "ns2-bachi-net" kernel, which is not a
kernel configuration distributed as part of FreeBSD 10.1-RELEASE.
This kernel will not be updated: you MUST update the kernel manually
before running "/usr/sbin/freebsd-update install".

The following components of FreeBSD seem to be installed:
kernel/generic src/src world/base world/doc world/lib32

The following components of FreeBSD do not seem to be installed:
world/games

Does this look reasonable (y/n)? y

Fetching metadata signature for 10.2-RELEASE from update4.freebsd.org... done.
Fetching metadata index... done.
Fetching 1 metadata patches. done.
Applying metadata patches... done.
Fetching 1 metadata files... done.
Inspecting system... done.
Fetching files from 10.1-RELEASE for merging... done.
Preparing to download files... done.
Fetching 39913 patches.....10....20....30....40....50....60
[...]
Applying patches... done.
Fetching 6731 files... done.
Attempting to automatically merge changes in files... done.

The following file could not be merged automatically: /etc/dhclient.conf
Press Enter to edit this file in vi and resolve the conflicts
manually...

The following files are affected by updates, but no changes have
been downloaded because the files have been modified locally:
/.profile
/root/.profile

The following files will be removed as part of updating to 10.2-RELEASE-p8:
[...]
To install the downloaded upgrades, run "/usr/sbin/freebsd-update install".

$ /usr/sbin/freebsd-update install
Installing updates...
Kernel updates have been installed.  Please reboot and run
"/usr/sbin/freebsd-update install" again to finish installing updates.
$ sudo freebsd-update upgrade -r 9.1-RELEASE

[ warnings about custom kernel ]

$ sudo freebsd-update install

[ this is when the new generic kernel is installed if we weren't running a custom kernel ]

$ cd /usr 
$ mv src{,-8.2}
$ sudo svn co https://svn.freebsd.org/base/releng/9.1/
$ sudo cp src{-8.2,}/sys/i386/conf/PULP
$ cd src

$ sudo rsync -a /boot/kernel{,-8.2}/
$ sudo make kernel-toolchain
$ sudo make buildkernel KERNCONF=PULP
$ sudo make installkernel KERNCONF=PULP

$ sudo reboot

$ sudo freebsd-update install
$ sudo reboot

Custom kernel in loader.conf

How to keep freebsd-update from trashing custom kernel?
FreeBSD Boot Process

Just an idea, not tested: Leave the GENERIC kernel updated
by freebsd-update, and put your own kernel unter a different
name into /boot, for example:

	/boot/kernel/kernel		<- GENERIC kernel
	/boot/mykernel/kernel		<- your kernel

Then change /boot/loader.conf to contain:

	kernel="mykernel"
	bootfile="/boot/mykernel/kernel"

Create Ubuntu USB Stick

ISO-9660 / MBR / GPT

“CD-Rs normally use the ISO-9660 filesystem directly, without partitions.”
Do ISO’s contain partition tables as well as a backup of the data?
How to understand partition table on hybrid ISO image?
In Ubuntu ISO MBR, why does a GPT partition overlap the boot partition, and make MBR uneditable?

mkusb


dus – a revamped interface of mkusb and mkusb-nox
mkusb versions with GUI
mkusb – tool to create boot drives

$ sudo add-apt-repository ppa:mkusb/unstable
$ sudo apt-get update
$ sudo apt-get install mkusb

$ guidus

Zenity, erlaubt, GTK-Dialoge von der Kommandozeile oder von Shell-Skripten aus zu starten

Von Hand

How to create a bootable Ubuntu USB flash drive from terminal?

sudo umount /dev/sdb
sudo dd if=/path/to/ubuntu.iso of=/dev/sdb bs=1M

How do you monitor the progress of dd?

$ sudo dd if=/dev/urandom of=/dev/null status=progress
or
$ sudo apt-get install pv
$ dd if=/path/to/ubuntu.iso | pv | dd of=/dev/sdb
sudo mkdir /media/iso/
sudo mount -o loop /path/to/ubuntu.iso /media/iso

# add fat32 partition (with gparted)

cp -a /media/iso/. /media/xxx/

sudo apt-get install syslinux mtools
sudo syslinux -s /dev/sdd1

=== NOT FINISHED !!! ===

$ pkg install syslinux
New packages to be INSTALLED:
        syslinux: 6.03
        mtools: 4.0.10_4
[...]
[1/2] Installing mtools-4.0.10_4...
[1/2] Extracting mtools-4.0.10_4: 100%
[2/2] Installing syslinux-6.03...
[2/2] Extracting syslinux-6.03: 100%
Message from mtools-4.0.10_4:
************************************************************
Please verify /usr/local/etc/mtools.conf for your machine.
************************************************************

Delete MBR
$ dd if=/dev/zero of=/dev/da1 bs=2m count=1

Create MBR with one FAT32 partition
$ fdisk -i /dev/da0

Format the partition
$ newfs_msdos -F32 /dev/da1s1

Mount partition
$ mount_msdosfs /dev/da1s1 /mnt

Create a memory disk:
-a        = attach
-t vnode  = backing store "file"
-f <file> = filename to use
-u 0      = create /dev/md0
$ mdconfig -a -t vnode -f ubuntu-15.10-server-amd64.iso -u 0

Mount the memory disk
$  mount -t cd9660 /dev/md0 /media/iso

Copy files from ISO to USB Stick
$ cp -a /media/iso/. /mnt

$ find /mnt -name syslinux.cfg
/mnt/install/netboot/ubuntu-installer/amd64/boot-screens/syslinux.cfg

=== NOT FINISHED !!! ===

Format USB Stick with FAT32 on FreeBSD

Expect

expect
Using Expect Scripts to Automate Tasks
6 Expect Script Examples to Expect the Unexpected
Expect Script Tutorial: Expressions, If Conditions, For Loop, and While Loop Examples
Tcl – How to Locate Include File to Source

User input

How can I make an expect script prompt for a password?

# grab the password
stty -echo
send_user -- "Password for $user@$host: "
expect_user -re "(.*)\n"
send_user "\n"
stty echo
set pass $expect_out(1,string)

#... later
send -- "$pass\r"

Tcl

Expect Examples
Regular Expressions
Regular Expression Examples

$ ./5410debug.exp 
bash: ./5410debug.exp: /usr/bin/expect: bad interpreter: No such file or directory

$ sudo yum install expect
Loaded plugins: langpacks, refresh-packagekit
Resolving Dependencies
--> Running transaction check
---> Package expect.x86_64 0:5.45-10.fc20 will be installed
--> Finished Dependency Resolution
[...]
Installed:
  expect.x86_64 0:5.45-10.fc20
Complete!

Embedded SSH

Planning Your Embedded Secure Shell (SSH) Implementation

Algorithm

Wikipedia: Comparison of Cryptography Libraries
cryptlib (C source, can be used with RTOS)
Java-based SSH-Client and -Server

Web

Web-based SSH
Is there a free-embedded Web-SSH solution?
github: QWeb and Ajaxterm

Proprietary

Embedded Tools GmbH’s smxSSL und smxSSH
Micro Digital Inc.’s uSSH Secure Server
Micro Digital Inc.’s uSSL Secure Server and Client
RomSShell AE – An Embedded SSH Client/Server
InterNiche’s SSH Server
Mocana NanoSSH