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.
Sunday, July 19, 2015
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
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
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 cpuE.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
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.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)
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:
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) - 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
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.
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:
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.
* 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:
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.
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.
| 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.
Thursday, April 10, 2014
Unix - SSH/SCP
- Check SSH server running:
# cat /etc/rc.conf | grep ssh sshd_enable="YES"
- SSH access to a remote machine:
#/$ ssh username@remoteMachine
'remoteMachine' is the DNS resolvable hostname of the remote host. IP address can also be used instead of the remote machine's hostname. - Securely transfer file over SSH:
#/$ scp -q -C -l 80000 username@remoteMachine:/home/username/test.txt \
/home/username/.
- Enable root access over SSH (only if it is essential):
# vi /etc/ssh/sshd_config PermitRootLogin yes # service sshd restart (or, # /etc/rc.d/sshd restart)
- Generate and copy SSH keys:
#/$ cd ~ #/$ ssh-keygen -t rsa #/$ scp ~/.ssh/id_rsa.pub remoteMachine:.ssh/authorized_keys
'RSA' is used here as authentication mechanism. Similarly 'DSA' can also be used. - Verify whether SSH key is working:
#/$ ssh remoteMachine hostname
Displays remote machine's hostname without a password prompt. - Monitoring/tracing SSH/SCP activities:
# cat /var/log/auth.log
Displays detailed log.
Note: Unix commands and file locations used here have been tested on FreeBSD systems.
Tuesday, April 8, 2014
Crimping an Ethernet LAN cable
Steps:
- Insert the cat 5e/6 cable into the boot/cap.
- Remove approximately 1 inch of the sleeve of the wire.
- Straighten the wires (ie, untwist the twisted pairs).
- Arrange the wires in the right order as shown below. Choose either (EIA/TIA 568) A or B type, and if it is a straight cable follow the colour sequence of the first image on both the ends of the cable.
- Cutoff excess length of the wire (to make it levelled inside the RJ-45 clip).
- Insert the wire into the RJ-45 clip while maintaining the order of the wires all the way in until you can see all the wires touching on the right side wall of the clip as shown by the red line (ie, you have to insert the beyond the end of arrows shown here.)
- Crimp the RJ-45 clip firmly with the crimping tool.
- Fix the boot.
Saturday, March 22, 2014
Unix - Memory and Disk Usages
- Statistics of process, virtual memory, disk, trap and cpu activity:
# vmstat -m
Type InUse MemUse HighUse Requests Size(s) USBdev 32 3K - 50 32,64,128,256,2048 USB 56 18K - 95 16,32,64,128,512,2048,4096 isadev 10 1K - 10 64 ppbusdev 3 1K - 3 128 cdev 7 1K - 7 128 entropy 1024 64K - 1024 64 sigio 1 1K - 1 32 filedesc 46 12K - 291905 16,32,256,512,2048 kdtrace 248 54K - 273670 64,256 kenv 83 7K - 92 16,32,64,128,4096 ... - Swap memory usage
# swapinfo
Device 1K-blocks Used Avail Capacity /dev/ada0p3 4194304 424 4193880 0%
- Top processes on the system
# top -d1
last pid: 73598; load averages: 0.00, 0.00, 0.00 26 processes: 1 running, 25 sleeping CPU: % user, % nice, % system, % interrupt, % idle Mem: 114M Active, 1683M Inact, 234M Wired, 121M Cache, 91M Buf, 843M Free Swap: 4096M Total, 424K Used, 4095M Free PID USER THR PRI NICE SIZE RES STATE C TIME WCPU COMMAND 1130 root 1 20 0 11296K 2944K select 0 0:39 0.00% sendmail 1137 root 1 20 0 9584K 1380K nanslp 0 0:10 0.00% cron 1003 root 1 20 0 9544K 1300K select 1 0:05 0.00% syslogd 70226 vijay 1 20 0 15852K 4200K select 1 0:03 0.00% sshd 70186 root 1 20 0 15852K 3992K select 0 0:03 0.00% sshd 928 root 1 29 0 9544K 1364K select 0 0:02 0.00% dhclient 966 _dhcp 1 20 0 9544K 1408K select 1 0:01 0.00% dhclient 813 root 1 20 0 12132K 2868K select 1 0:01 0.00% devd 1133 smmsp 1 20 0 11296K 2816K pause 1 0:01 0.00% sendmail 71182 root 1 20 0 11256K 2940K select 1 0:01 0.00% ntpd 70223 root 1 20 0 15852K 4056K select 1 0:00 0.00% sshd 1127 root 1 20 0 13096K 3148K select 1 0:00 0.00% sshd 70189 root 1 20 0 10864K 3188K pause 0 0:00 0.00% csh 1183 root 1 20 -4 10092K 1868K ttyin 1 0:00 0.00% login 73598 root 1 20 0 9872K 2008K CPU1 1 0:00 0.00% top 1185 root 1 52 0 9544K 1240K ttyin 1 0:00 0.00% getty 1187 root 1 52 0 9544K 1240K ttyin 1 0:00 0.00% getty 1189 root 1 52 0 9544K 1240K ttyin 0 0:00 0.00% getty 1188 root 1 52 0 9544K 1240K ttyin 0 0:00 0.00% getty ...
- Finding size of folders (total size of files and subfolders underneath)
- # du –sh myfolder
- # du –sh * => Size of all the folders in the current directory
- # du –sk | sort –n => Size of folders, sorted by size (k kilo byte. h gives false sorting results)
Saturday, February 15, 2014
IPv4 Address Classes
Though Classless Inter-Domain Routing (CIDR) and Variable-Length Subnet Mask (VLSM) are the order of today's IPv4 networking, classification of IPv4 address spaces into classes A, B, C, or D remains common. The following table shows the classes that were designated during the days of classful routing:
| Class | First bits | Address range | Subnet mask |
| Class A | 0 | 1.x.x.x ~ 127.x.x.x | 255.0.0.0 (/8) |
| Class B | 10 | 128.0.x.x ~ 191.255.x.x | 255.255.0.0 (/16) |
| Class C | 110 | 192.0.0.x ~ 223.255.255.x | 255.255.255.0 (/24) |
| Class D | 1110 | 224.0.0.0 ~ 239.255.255.255 | - |
| Class E | 1111 | 240.0.0.0 ~ 255.255.255.254 | - |
Saturday, January 4, 2014
Unix - Disk Management
Identifying the harddisks installed
- Listing all the disks and drives attached to the system
# camcontrol devlist (or, atacontrol list) at scbus2 target 0 lun 0 (ada0,pass0) at scbus3 target 0 lun 0 (cd0,pass1)
- Listing harddisks detected during the system bootup
# dmesg | grep ad ada0 at ata4 bus 0 scbus2 target 0 lun 0 ada0:
ATA-8 SATA 2.x device ada0: 300.000MB/s transfers (SATA 2.x, UDMA5, PIO 8192bytes) ada0: 238418MB (488281250 512 byte sectors: 16H 63S/T 16383C) ada0: Previously was known as ad4 Trying to mount root from ufs:/dev/ada0p2 [rw]... - Listing harddisks and their partitions
# ls /dev | grep ad ad4 ad4p1 ad4p2 ad4p3 ada0 ada0p1 ada0p2 ada0p3
- Listing hardware level information of a harddisks
# diskinfo -c ada0 ada0 512 # sectorsize 250000000000 # mediasize in bytes (232G) 488281250 # mediasize in sectors 0 # stripesize 0 # stripeoffset 484406 # Cylinders according to firmware. 16 # Heads according to firmware. 63 # Sectors according to firmware. WD-WMAV12345678 # Disk ident. I/O command overhead: time to read 10MB block 0.124816 sec = 0.006 msec/sector time to read 20480 sectors 2.126440 sec = 0.104 msec/sector calculated command overhead = 0.098 msec/sector
- #fdisk ada0
******* Working on device /dev/ada0 ******* parameters extracted from in-core disklabel are: cylinders=484521 heads=16 sectors/track=63 (1008 blks/cyl) Figures below won't work with BIOS for partitions not in cyl 1 parameters to be used for BIOS calculations are: cylinders=484521 heads=16 sectors/track=63 (1008 blks/cyl) Media sector size is 512 Warning: BIOS sector numbering starts with sector 1 Information from DOS bootblock is: The data for partition 1 is: sysid 238 (0xee),(EFI GPT) start 1, size 488397167 (238475 Meg), flag 80 (active) beg: cyl 0/ head 1/ sector 1; end: cyl 1023/ head 255/ sector 63
Identifying the harddisk partitions
- Identifying basic information about harddisk partitions
# gpart show => 34 488281183 ada0 GPT (232G) 34 128 1 freebsd-boot (64k) 162 478150528 2 freebsd-ufs (228G) 478150690 8388608 3 freebsd-swap (4.0G) 486539298 1741919 - free - (850M) - Displaying detailed information of harddisk partitions
# gpart list Geom name: ada0 modified: false state: OK fwheads: 16 fwsectors: 63 last: 488281216 first: 34 entries: 128 scheme: GPT Providers: 1. Name: ada0p1 Mediasize: 65536 (64k) Sectorsize: 512 Stripesize: 0 Stripeoffset: 17408 Mode: r0w0e0 rawuuid: 740aff84-9a1e-11e3-b778-002219173177 rawtype: 83bd6b9d-7f41-11dc-be0b-001560b84f0f label: (null) length: 65536 offset: 17408 type: freebsd-boot index: 1 end: 161 start: 34 2. Name: ada0p2 Mediasize: 244813070336 (228G) Sectorsize: 512 Stripesize: 0 Stripeoffset: 82944 Mode: r1w1e1 rawuuid: 740b80b0-9a1e-11e3-b778-002219173177 rawtype: 516e7cb6-6ecf-11d6-8ff8-00022d09712b label: (null) length: 244813070336 offset: 82944 type: freebsd-ufs index: 2 end: 478150689 start: 162 3. Name: ada0p3 Mediasize: 4294967296 (4.0G) Sectorsize: 512 Stripesize: 0 Stripeoffset: 17408 Mode: r1w1e0 rawuuid: 740eaebd-9a1e-11e3-b778-002219173177 rawtype: 516e7cb5-6ecf-11d6-8ff8-00022d09712b label: (null) length: 4294967296 offset: 244813153280 type: freebsd-swap index: 3 end: 486539297 start: 478150690 Consumers: 1. Name: ada0 Mediasize: 250000000000 (232G) Sectorsize: 512 Mode: r2w2e3
df -h Filesystem Size Used Avail Capacity Mounted on /dev/ada0p2 220G 7.6G 195G 4% / devfs 1.0k 1.0k 0B 100% /dev nfsServer:/home 435G 15G 420G 3% /usr/home
Mounting and unmounting external drives
For a USB memory stick,- # mount -t msdosfs /dev/da0s1 /tmp/usb
- # umount /tmp/usb
Note: Unix commands and file locations used here have been tested on FreeBSD systems.
Labels:
commands,
disk management,
mounting,
partitions,
Unix
Saturday, December 28, 2013
Unix - File Access Rights and Ownerships
File Attributes
#/$ ls -l /tmp drwxr-xr-x 4 vijay wheel 10 Apr 16 2010 testFolder -rw-r--r-- 2 vijay wheel 368884 Feb 13 2012 news.txt -rwx------ 2 vijay wheel 2687 Feb 13 2012 secret.txt -rwxr-xr-x 2 vijay wheel 11762 Nov 10 2011 code.c
Symbolic permissions
| Option | Letter | Represents |
| (who) | u | User |
| (who) | g | Group owner |
| (who) | o | Other |
| (who) | a | All (“world”) |
| (action) | + | Adding permissions |
| (action) | - | Removing permissions |
| (action) | = | Explicitly set permissions |
| (permissions) | r | Read |
| (permissions) | w | Write |
| (permissions) | x | Execute |
| (permissions) | t | Sticky bit |
| (permissions) | s | Set UID or GID |
To modify the access rights, modify the file attributes.
| # chmod 777 testfile | Allows access by File Owner, Group Members, and All-other-users. |
| # chmod –R 755 /tmp/test/ | -R affects access rights all the files and sub-folders in /tmp/test/ |
| # chmod go= testfile | Symbolic permission (who) (action) (permissions) |
| # chmod go-w,a+x testfile |
Extended file attributes
# getfacl testfile # setfacl -k testfile # setfacl -m u:trhodes:rwx,group:web:r--,o::--- testfile
setuid (4), setgid (2), and sticky (1) permissions
# chmod 4755 testfile=> File will always use permissions and the same user ID of who assigned it)
-rwsr-xr-x (x of owner is replaced with s)
# chmod 2755 testfile
=> File will always use permissions of the group (of the group to assigner belongs)
-rwxr-sr-x (x of group is replaced with s)
# chmod 1777 testdir
=> Allows file deletion only by the owner (make sense for directories)
drwxrwxrwt (x of all-users is replaced with t)
File flags (FreeBSD specific)
File flags are used to prevent accidental editing/removal of files (non-directory) by the root and/or the file owners in FreeBSD.To view them:
# ls -lo /etc | grep rc.conf -rw-r--r-- 1 root wheel schg 1897 Mar 1 2012 rc.conf
In the above case, the secret tool 'schg' makes the file rc.conf unmodifiable even by the superuser (root) without removing the flag. This feature provides one additional level of protection for important files from accidental modifications by the system administrator(s).
Super user (root) only assignable flags
- sappnd, sappend : sets the system append-only flag (by super-user only)
- sunlnk, sunlink : sets the system undeletable flag (by super-user only)
- schg, schange, simmutable : sets the system immutable flag (by super-user only)
Normal user assignable flags
- uappnd, uappend : sets the user append-only flag (by owner or super-user only)
- uunlnk, uunlink : sets the user undeletable flag (by owner or super-user only)
- uchg, uchange, uimmutable : sets the user immutable flag (by owner or super-user only)
To edit these flags chflags command is used. For example:
# chflags sunlink testfile => Undeletable # chflags nosunlink testfile # chflags schg httpd.conf => System immutable (no change) flag # chflags noschg httpd.conf
File Ownership
To change the file ownership:# chown –R vijay:wheel *
Note: Unix commands and file locations used here have been tested on FreeBSD systems.
Wednesday, September 11, 2013
Unix - DHCP
After addition of a new network interface card (NIC) in a DHCP client and/or changing cable from one port to another, client might not establish the network connectivity. In such cases first check whether the active NIC's MAC address is there on DHCP server's database. If it is not there then add the MAC address and restart the server. If the problem persists, refresh the DHCP client as below:
# service netif restart
# dhclient eth1
# service netif restart
# dhclient eth1
Subscribe to:
Posts (Atom)

