Sunday, July 19, 2015

Unix - Welcome Message

Though not a big technical feature, having the right welcome message in a Unix server would be very much helpful in case of multiple server usages.

To change the welcome message modify /etc/motd file with the custom message and add update_motd="NO" line in /etc/rc.conf.

To have a custom SSH terminal welcome message create /etc/banner file with the custom message and add Banner /etc/banner line in /etc/ssh/sshd_config.

Saturday, September 20, 2014

Unix - Details of the processor



# sysctl -a | egrep -i 'hw.machine|hw.model|hw.ncpu'

E.g.1:
hw.machine: i386
hw.model: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz
hw.ncpu: 8
hw.machine_arch: i386

E.g.2:
hw.machine: amd64
hw.model: Intel(R) Pentium(R) D CPU 3.00GHz
hw.ncpu: 2
hw.machine_arch: amd64

Note: 'amd64' does not mean AMD processor, but 64 bit operating system.

# dmesg | grep -i cpu

E.g.1:
CPU: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz (3392.32-MHz 686-class CPU)
FreeBSD/SMP: Multiprocessor System Detected: 8 CPUs
 cpu0 (BSP): APIC ID:  0
 cpu1 (AP): APIC ID:  1
 cpu2 (AP): APIC ID:  2
 cpu3 (AP): APIC ID:  3
 cpu4 (AP): APIC ID:  4
 cpu5 (AP): APIC ID:  5
 cpu6 (AP): APIC ID:  6
 cpu7 (AP): APIC ID:  7
cpu0: on acpi0
cpu1: on acpi0
cpu2: on acpi0
cpu3: on acpi0
cpu4: on acpi0
cpu5: on acpi0
cpu6: on acpi0
cpu7: on acpi0
est0: on cpu0
p4tcc0: on cpu0
est1: on cpu1
p4tcc1: on cpu1
est2: on cpu2
p4tcc2: on cpu2
est3: on cpu3
p4tcc3: on cpu3
est4: on cpu4
p4tcc4: on cpu4
est5: on cpu5
p4tcc5: on cpu5
est6: on cpu6
p4tcc6: on cpu6
est7: on cpu7
p4tcc7: on cpu7
SMP: AP CPU #1 Launched!
SMP: AP CPU #6 Launched!
SMP: AP CPU #3 Launched!
SMP: AP CPU #2 Launched!
SMP: AP CPU #7 Launched!
SMP: AP CPU #4 Launched!
SMP: AP CPU #5 Launched!
 
E.g.2:
CPU: Intel(R) Pentium(R) D CPU 3.00GHz (3000.17-MHz K8-class CPU)
FreeBSD/SMP: Multiprocessor System Detected: 2 CPUs
 cpu0 (BSP): APIC ID:  0
 cpu1 (AP): APIC ID:  1
cpu0: on acpi0
cpu1: on acpi0
est0: on cpu0
est: CPU supports Enhanced Speedstep, but is not recognized.
est: cpu_vendor GenuineIntel, msr f2500000f25
p4tcc0: on cpu0
est1: on cpu1
est: CPU supports Enhanced Speedstep, but is not recognized.
est: cpu_vendor GenuineIntel, msr f2500000f25
p4tcc1: on cpu1
SMP: AP CPU #1 Launched!
 

# grep -i cpu /var/run/dmesg.boot

(Mostly the same output as above)


# sysctl -a | grep -i cpu | less

kern.ccpu: 0
  0, 1, 2, 3, 4, 5, 6, 7
    0, 1, 2, 3, 4, 5, 6, 7
      0, 1
      2, 3
      4, 5
      6, 7
kern.smp.cpus: 8
kern.smp.maxcpus: 32
debug.cpufreq.verbose: 0
debug.cpufreq.lowest: 0
debug.kdb.stop_cpus: 1
debug.PMAP1changedcpu: 1866
hw.model: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz
hw.ncpu: 8
hw.acpi.cpu.cx_lowest: C1
machdep.hlt_cpus: 0
security.jail.param.cpuset.id: 0
dev.cpu.0.%desc: ACPI CPU
dev.cpu.0.%driver: cpu
dev.cpu.0.%location: handle=\_PR_.CPU0
dev.cpu.0.%pnpinfo: _HID=none _UID=0
dev.cpu.0.%parent: acpi0
dev.cpu.0.freq: 3401
dev.cpu.0.freq_levels: 3401/95000 3000/79831 2800/72677 2600/65779 2400/59147 2200/52789 2000/46677 1800/40818 1600/35981 1400/31483 1200/26985 1000/22488 800/17990 600/13492 400/8995 200/4497
dev.cpu.0.cx_supported: C1/1 C2/80 C3/104
dev.cpu.0.cx_lowest: C1
dev.cpu.0.cx_usage: 100.00% 0.00% 0.00% last 500us
dev.acpi_perf.0.%parent: cpu0
dev.est.0.%parent: cpu0
dev.cpufreq.0.%driver: cpufreq
dev.cpufreq.0.%parent: cpu0
dev.p4tcc.0.%desc: CPU Frequency Thermal Control
dev.p4tcc.0.%parent: cpu0
... (similar outputs for each processor in the system)


Note:

  • Some outputs like hw architecture are not correct, do not give actual platform details, and are operating system dependent. For example, 'FreeBSD amd64' is generally installed on Intel i386 based platforms if 64 bit operation is expected.
  • Similar is the ‘uname –p’ command. It returns the OS choice, not the actual hardware platform.

Sunday, August 24, 2014

Unix - Symbolic links

A symbolic link or soft link is very much like a shortcut in Windows. Unlike a hard link, a symbolic link does not contain the data in the target file, and instead points to another file in the system.

  • Let's create a hard link of new directory as the source file
    # mkdir /usr/test

  • Let's create a symbolic link  
    # ln -s /usr/test/ /test        ( # ln –s sourceFile symbolicLinkFile )

  • # ls –al /

    lrwxr-xr-x   1 root  wheel       10 Sep 25 11:18     test -> /usr/test/


  • # touch /usr/test/sample.txt

  • # ls /test
    sample.txt

    Note: sample.txt IS listed.

  • # ls -al /test
    lrwxr-xr-x  1 root  wheel  10 Sep 25 11:18 /test -> /usr/test/

    Note: sample.txt IS NOT listed during detailed listing.

  • # ls -al /usr/test/
    total 6
    drwxr-xr-x   2 root  wheel  512 Sep 25 11:21 .
    drwxr-xr-x  18 root  wheel  512 Sep 25 11:18 ..
    -rwxr-xr-x   1 root  wheel   61 Sep 25 11:22 sample.txt


  • # touch /test/sample2.txt

  • # ls -al /test
    lrwxr-xr-x  1 root  wheel  10 Sep 25 11:18 /test -> /usr/test/


    Note: sample2.txt is NOT listed either.

  • # ls /test
    sample.txt       sample2.txt


  • # rm /test

    Note: Symbolic link is deleted without any complain about files within directory

  • # ls /usr/test/
    sample.txt       sample2.txt


  • # rm /usr/test
    rm: /usr/test: is a directory

Monday, June 23, 2014

Unix - Z File System (ZFS)

The Z file system (ZFS) developed by Sun Microsystems is a feature rich file system for server solutions. It is designed for high storage volumes, mirror and RAID options for redundancy, data snapshots, integrity checking, and automatic repairs.

Here are some ZFS troubleshooting commands and typical outputs:
  • # zpool status
      pool: zroot
     state: ONLINE
      scan: resilvered 30.6M in 0h0m with 0 errors on Sep 16 10:18:02 2013
    config:
    
     NAME        STATE     READ WRITE CKSUM
     zroot       ONLINE       0     0     0
       mirror-0  ONLINE       0     0     0
       gpt/disk0 ONLINE       0     0     0
       gpt/disk1 ONLINE       0     0     3
    
    errors: No known data errors 

  • # zpool list
    NAME    SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
    zroot   228G   124G   104G    54%  1.00x  ONLINE  - 

  • # zfs list
    NAME                        USED  AVAIL  REFER  MOUNTPOINT
    zroot                      31.8G   417G    31K  /zroot
    zroot/ROOT                 3.38G   417G  3.38G  /
    zroot/scratch              4.94G   417G  4.94G  /scratch
    zroot/tmp                  58.9M   417G  58.9M  /tmp
    zroot/usr                  21.0G   417G    31K  /usr
    zroot/usr/home             17.9G   417G  17.9G  /usr/home
    zroot/usr/local             813M   417G   813M  /usr/local
    zroot/usr/obj               997M   417G   997M  /usr/obj
    zroot/usr/ports             965M   417G   896M  /usr/ports
    zroot/usr/ports/distfiles  67.6M   417G  67.6M  /usr/ports/distfiles
    zroot/usr/ports/packages   1.30M   417G  1.30M  /usr/ports/packages
    zroot/usr/src               359M   417G   359M  /usr/src
    zroot/var                  2.46G   417G   109M  /var
    zroot/var/crash            2.15G   417G  2.15G  /var/crash
    zroot/var/db                206M   417G   204M  /var/db
    zroot/var/db/pkg           1.90M   417G  1.90M  /var/db/pkg
    zroot/var/empty              31K   417G    31K  /var/empty
    zroot/var/log               706K   417G   706K  /var/log
    zroot/var/mail             59.5K   417G  59.5K  /var/mail
    zroot/var/run              56.5K   417G  56.5K  /var/run
    zroot/var/tmp              1.79M   417G  1.79M  /var/tmp
    

  • # ls -l /etc/zfs
    total 1
    -rw-------  1 root  wheel  181 Jun 10 12:59 exports

  • # ls -l /boot/zfs /boot/zfsboot /boot/zfsloader
    -r--r--r--  1 root  wheel   66048 Dec  4  2012 /boot/zfsboot
    -r-xr-xr-x  1 root  wheel  303104 Oct 16  2013 /boot/zfsloader
    
    /boot/zfs:
    total 3
    -rw-r--r--  1 root  wheel  1588 Sep 13  2013 zpool.cache

  • # ls -l /boot/gptboot /boot/gptzfsboot
    -r--r--r--  1 root  wheel  16723 Dec  4  2012 /boot/gptboot
    -r--r--r--  1 root  wheel  43443 Dec  4  2012 /boot/gptzfsboot

Thursday, June 12, 2014

Unix - Hardware Timer Selection

  • To find the timer counter being used by the computer:

    myhost# sysctl kern.timecounter.hardware
    kern.timecounter.hardware: HPET


  • List of available timers:

    myhost# sysctl kern.timecounter.choice
    kern.timecounter.choice: TSC(-100) HPET(900)

  • The integer value within brackets defines the quality of the time counter compared to others. A negative value means this time counter is broken and should not be used.


  • Selecting the timer of your choice:
    myhost# sysctl kern.timecounter.hardware=TSC

    Note: This selection does not persist after a reboot. To make this change persistent add the following line to the file /etc/sysctl.conf:
    sysctl kern.timecounter.hardware=HPET

Saturday, May 31, 2014

Network Troubleshooting Commands

The following are the basic commands that helps to locate network issues. To open the command line interface or consoles:
* Ubuntu : 'Ctrl + Alt + T'
* Windows Systems : 'Window key + R' --> type 'cmd' and click 'OK/Run'


ifconfig / ipconfig

It is generally the very first to check whether the computer's network interface has got a valid IP address to establish communication with other devices in the network. MAC (physical) address of the network can also be found using these commands.

On Unix based systems,

e.g.1: ifconfig ==> Displays all the network interfaces, such as Ethernet and Loopback, MAC addresses, IP addresses, and subnet masks. Depending on the flavour of Unix and type of interface, some additional details such as number of packets transmitted and received, errors, active/disabled status, and size of the maximum transmittable unit (MTU) can also be found.

e.g.2: ifconfig eth0 down ==> Disables the Ethernet interface 'eth0'. Super user (root) only.

e.g.3: ifconfig eth0 up ==> Enables the Ethernet interface 'eth0'. Super user (root) only.

e.g.4: ifconfig eth0 192.168.1.1 netmask 255.255.255.0 ==> Assigns IP address and netmask manually. Super user (root) only.

On Windows systems,

e.g.1: ipconfig ==> Displays the IP address, netmask, and default gateway of all the network interfaces.

e.g.2: ipconfig /all ==> Displays more information about the network interfaces, including MAC address, DHCP status, and DNS servers used.

e.g.3: ipconfig /renew ==> Re-establishes TCP/IP connections on all network adapters and refreshes IP address with the DHCP server.

e.g.4: ipconfig /flushdns ==> Flushes the DNS cache stored locally (URL to IP address conversion)


ping

It is the basic command to check network reachability based on echos received from a network interface. It works in both Unix and Windows systems. However, command switches for a given additional option, such continuous ping, may vary.

On both Unix and Windows based systems,

e.g.1: ping 127.0.0.1 ==> reveals whether the IP protocol is up on you own computer (localhost). On Unix, continuously sends echo requests until terminated with 'Ctrl + C'.

e.g.2: ping www.yahoo.com ==> shows whether you can reach yahoo.com's server over the internet

On Windows,

e.g.1: ping -t www.google.com ==> On windows, continuously sends echo requests until terminated with 'Ctrl + C'.

Note:
  • If no response for a well known server, then ping to the gateway IP addess found from the ifconfig / ipconfig command above. This reveals the connectivity to your network gateway.
  • When URL is used with the ping command instead of an IP address, and it does not get resolved into an IP address, then the Domain Name System (DNS) resolution could be tested. 

traceroute / tracert

A command to identify the hops in the network, and in case of failures the output indicates the intermediate hops which packets travel successfully.

On Unix based systems,

e.g.1: traceroute www.yahoo.com ==> Names of hops along the network path and time taken to receive an echo response from them

On Windows, 

e.g.1: tracert www.yahoo.com ==> Names of hops along the network path and time taken to receive an echo response from them


nslookup

Returns the corresponding IP address for a given URL (also vice-versa).

On both Unix and Windows based systems,

e.g.1: nslookup www.yahoo.com 


netstat

A command to visualize the details of the ongoing network communication.

On both Unix and Windows based systems,

e.g.1: netstat ==> Details of all the established TCP connections

e.g.2: netstat -r ==> The routing table of your computer, including the default route and gateway details.


arp

Displays the IP address to MAC address conversion, and vice versa.

e.g.1: arp -a ==> Displays all the IP addresses and corresponding MAC addresses of the known network interfaces in the local broadcast domain


hostname

Gives the name assigned to your computer.

e.g.1: hostname ==> Hostname of your system


whoami / set U

Reveals the username currently used by you.

On Unix systems:

e.g.1: whoami ==> Shows your username (or 'root' in the case of superuser)

On Windows systems,

e.g.2: set U ==> Shows your username, domain, and user profile location.


Sunday, April 13, 2014

IPv4 Martian Addresses

Martian addresses are the blocks of IPv4 addresses that are reserved for special use by the Internet Assigned Numbers Authority (IANA), and are NOT meant to be reached over the Internet. The following are the IANA reserved category addresses which are generally considered as Martian addresses:

Address block Use
0.0.0.0/8 "This" network
100.64.0.0/10 Carrier-grade NAT
127.0.0.0/8 Loopback
169.254.0.0/16 Link local
192.0.0.0/24 IETF protocol assignments
192.0.2.0/24 TEST-NET-1
198.18.0.0/15 Network interconnect device benchmark testing
198.51.100.0/24 TEST-NET-2
203.0.113.0/24 TEST-NET-3
224.0.0.0/4 Multicast
240.0.0.0/4 Reserved for future use

Depending on the manufacturer of routers used at the customer premises or at the network service providers end these Martian addresses may also be blocked within Layer 3 Virtual Private Networks (IP VPNs) or Local Area Networks (LANs). E.g., Juniper Network routers block Martian addresses within IP VPNs.

Private Network IP Address Blocks

IP address blocks that are dedicated for private LANs are also included within the Martian Address blocks according to some definitions.

Subnet Address block Use
10.0.0.0/8 Class A private networks (used as /8 subnets)
172.16.0.0/12 Class B private networks (used as /16 subnets)
192.168.0.0/16 Class C private networks (used as /24 subnets)

Bogon IP Address Blocks

IP address blocks that are yet to be allocated to any user or delegated to any regulator agency by the IANA are called Bogon IP addresses. These blocks change with time.