Wednesday, 18 May 2016

57 Tips Every Admin Should Know

The longer a person serves as a network admin, the more tips and tricks they are likely to pick up along the way. Some could be shortcuts, others might seem like magic, but all are intended to save you time and help you solve problems. Assume that all of these Windows commands should be run from an administrative command prompt if you are using Vista, Windows 7, or Windows 2008.
Active Directory
1. To quickly list all the groups in your domain, with members, run this command:
dsquery group -limit 0 | dsget group -members –expand
2. To find all users whose accounts are set to have a non-expiring password, run this command:
dsquery * domainroot -filter “(&(objectcategory=person)(objectclass=user)(lockoutTime=*))” -limit 0
3. To list all the FSMO role holders in your forest, run this command:
netdom query fsmo
4. To refresh group policy settings, run this command:
gpupdate
5. To check Active Directory replication on a domain controller, run this command:
repadmin /replsummary
6. To force replication from a domain controller without having to go through to Active
Directory Sites and Services, run this command:
repadmin /syncall
7. To see what server authenticated you (or if you logged on with cached credentials) you can run either of these commands:
set l
echo %logonserver%
8. To see what account you are logged on as, run this command:
whoami
9. To see what security groups you belong to, run this command:
whoami /groups
10. To see the domain account policy (password requirements, lockout thresholds, etc) run this command:
net accounts

Windows Networking

11. To quickly reset your NIC back to DHCP with no manual settings, run this command:
netsh int ip reset all
12. To quickly generate a text summary of your system, run this command:
systeminfo | more
13. To see all network connections your client has open, run this command:
net use
14. To see your routing table, run either of these commands:
route print
netstat -r
15. Need to run a trace, but don’t have Netmon or Wireshark, and aren’t allowed to install either one? Run this command:
netsh trace start capture=yes tracefile=c:\capture.etl
netsh trace stop
16. To quickly open a port on the firewall, run this command, changing the name, protocol, and port to suit. This example opens syslog:
netsh firewall set portopening udp 161 syslog enable all
17. To add an entry to your routing table that will be permanent, run the route add command with the –p option. Omitting that, the entry will be lost at next reboot:
route add 0.0.0.0 mask 0.0.0.0 172.16.250.5 –p
18. Here’s a simple way to see all open network connections, refreshing every second:
netstat –ano 1
19. You can add a | findstr value to watch for only a specific connection, like a client ip.addr or port:
netstat –ano | findstr 216.134.217.20
20. You can use the shutdown to shutdown or reboot a machine, including your own, in a simple scheduled task like this:
shutdown –r –t 0 –m \\localhost
21. To make planned DNS changes go faster, reduce the TTL on the DNS records you plan on changing to 30 seconds the day before changes are to be made. You can set the TTL back to normal after you confirm the changes have been successful.
22. Set a short lease on DHCP scopes that service laptops, and set Microsoft Option 002 to release a DHCP leas on shutdown. This helps to ensure your scope is not exhausted and that machines can easily get on another network when the move to a new site.

Windows 7

23. Want to enable the local administrator account on Windows 7? Run this command from an administrative command prompt. It will prompt you to set a password:
net user administrator * /active:yes
24. You can do the same thing during install by pressing SHIFT-F10 at the screen where you set your initial user password.
Windows 7 supports several useful new keyboard shortcuts:
25. Windows Key+G
Display gadgets in front of other windows.
26. Windows Key++ (plus key)
Zoom in, where appropriate.
27. Windows Key+- (minus key)
Zoom out, where appropriate.
28. Windows Key+Up Arrow
Maximize the current window.
29. Windows Key+Down Arrow
Minimize the current window.
30. Windows Key+Left Arrow
Snap to the left hand side of the screen
31. Windows Key+Right Arrow
Snap to the right hand side of the screen.
32. To quickly launch an application as an administrator (without the right-click, run as administrator), type the name in the Search programs and files field, and then press Ctrl-Shift-Enter.
Here are some tips that can save you from buying commercial software:
33. Need to make a quick screencast to show someone how to do something? The Problem Steps Recorder can create an MHTML file that shows what you have done by creating a screen capture each time you take an action. Click the Start button and type ‘psr’ to open the Problem Steps Recorder.
34. Need to burn a disc? The isoburn.exe can burn ISO and IMG files. You can right click a file and select burn, or launch it from the command line.
35. Windows 7 includes a screen scraping tool called the Snipping Tool. I have tons of users request a license for SnagIt, only to find this free tool (it’s under Accessories) does what they need.
36. You can download this bootable security scanner from Microsoft that will run off a USB key, which is very useful if you suspect a machine has a virus.
37. A great way to save all your command line tools and make them available across all your computers is to install Dropbox, create a folder to save all your scripts and tools, and add that folder to your path. That way, they can be called from the command line or any other scripts, and if you update a script, it will carry across to any other machine you have.

Windows 2008

38. You can free up disk space on your servers by disabling hibernate. Windows 2008 will create a hiberfil.sys equal to the amount of RAM. This is very useful with VMs that have lots of RAM but smaller C: drives. To disable hibernation, and reclaim that space, run this command:
powercfg -h off
39. You can get to the complete collection of Sysinternals tools online. You can even invoke them from the run command. Use the url: http://live.sysinternals.com or the UNC path: \\live.sysinternals.com\tools.
40. Speaking of the Sysinternals tools, almost any command line in this article can be run remotely on another machine (as long as you have administrative rights) using the psexec command included in the Sysinternals tools.
41. You can kill RDP sessions at the command line when you find that all the RDP sessions to a server are tied up.
regsvr32 query.dll [enter] You only have to do this the first time.
query session /server:servername [enter]
reset session # /server:servername [enter]
42. You can create a list of files and display the last time they were accessed, which is very useful when a network drive is low on space and users swear they have to have that copy of Office 2003 on the network. My advice? If they haven’t touched it in two years, burn it to DVD or write it to tape and then delete it from disk:
dir /t:a /s /od >> list.txt [enter]
43. The Microsoft Exchange Err command is one of the best all around troubleshooting tools you will find, as it can decode any hex error code you find as long as the products are installed on the machine. Download it from here.
44. You can see all the open files on a system by running this command:
openfiles /query
45. You can pull all the readable data out of a corrupt file using this command:
recover filename.ext
46. Need to pause a batch file for a period of time but don’t have the sleep command from the old resource kit handy? Here’s how to build a ten second delay into a script:
ping -n 10 127.0.0.1 > NUL 2>&1
47. If your Windows website has stopped responding, or is throwing a 500 error, and you are not sure what to do, you can reset IIS without having to reboot the whole server. Run this command:
iisreset
48. You can use && to string multiple commands together; they will run sequentially.
49. If you find yourself restarting services frequently, you can use that && trick to create a batch file called restart.cmd and use it to restart services:
net stop %1 && net start %1
50. You can download a Windows port of the wget tool from here, and use it to mirror websites using this command:
wget -mk http://www.example.com/

Linux

51. You can list files sorted by size using this command:
ls –lSr
52. You can view the amount of free disk space in usable format using this command:
df –h
53. To see how much space /some/dir is consuming:
du -sh /some/dir
54. List all running processes containing the string stuff:
ps aux | grep stuff
55. If you have ever run a command but forgot to sudo, you can use this to rerun the command:
sudo !!
56. If you put a space before a command or response, it will be omitted from the shell history.
57. If you really liked a long command that you just ran, and want to save it as a script, use this trick:
echo “!!” > script.sh
With 57 tips in this bag of tricks, you’re bound to find something useful. Have your own tips to share? Leave us a comment!

50 UNIX / Linux Sysadmin Tutorials

To wrap this year, I’ve collected 50 UNIX / Linux sysadmin related tutorials that we’ve posted so far. This is lot of reading. Bookmark this article for your future reference and read it whenever you get free time.
  1. Disk to disk backup using dd command: dd is a powerful UNIX utility, which is used by the Linux kernel makefiles to make boot images. It can also be used to copy data. This article explains how to backup entire hard disk and create an image of a hard disk using dd command.
  2. 15 rsync command examples: Every sysadmin should master the usage of rsync. rsync utility is used to synchronize the files and directories from one location to another. First time, rsync replicates the whole content between the source and destination directories. Next time, rsync transfers only the changed blocks or bytes to the destination location, which makes the transfer really fast.
  3. Three sysadmin rules: If you are a sysadmin, you can’t (and shouldn’t) break these three sysadmin rules.
  4. User and group disk quota: This article explains how to setup user and group quote with soft limit, hard limit and grace period. For example, if you specify 2GB as hard limit, user will not be able to create new files after 2GB.
  5. Troubleshoot using dmesg: Using dmesg you can view boot up messages that displays information about the hardware devices that the kernel detects during boot process. This can be helpful during troubleshooting process.
  6. RPM package management examples: 15 examples provided in this article explains everything you need to know about managing RPM packages on redhat based system (including CentOS).
  7. 10 netstat examples: Netstat command displays various network related information such as network connections, routing tables, interface statistics, masquerade connections, multicast memberships etc.,
  8. Manage packages using apt-* commands: These 13 practical examples explains how to manage packages using apt-get, apt-cache, apt-file and dpkg commands.
  9. Modprobe command examples: modprobe utility is used to add loadable modules to the Linux kernel. You can also view and remove modules using modprobe command.
  10. Ethtool examples: Ethtool utility is used to view and change the ethernet device parameters. These examples will explain how you can manipulate your ethernet NIC card using ethtool.
  11. NFS mount using exportfs: This is a linux beginners guide to NFS mount using exportfs. This explains how to export a file system to a remote machine and mount it both temporarily and permanently.
  12. Change timezone: Depending on your Linux distribution, use one of the methods explained in this article to change the timezone on your system.
  13. Install phpMyAdmin: phpMyAdmin is a web-based tool written in PHP to manage the MySQL database. Apart from viewing the tables (and other db objects), you can perform lot of DBA functions through the web based interface. You can also execute any SQL query from the UI.
  14. Setup squid to control internet access: Squid is a proxy caching server. You can use squid to control internet access at work. This guide will give a jump-start on how to setup squid on Linux to restrict internet access in an network.
  15. Add new swap space: Use dd, mkswap and swapon commands to add swap space. You can either use a dedicated hard drive partition to add new swap space, or create a swap file on an existing filesystem and use it as swap space.
  16. Install and configure snort: Snort is a free lightweight network intrusion detection system for both UNIX and Windows. This article explains how to install snort from source, write rules, and perform basic testing.
  17. Register RHEL/OEL linux to support: If you have purchased support from Oracle for your Linux, you can register to oracle support network (ULN) using up2date as explained here.
  18. tftpboot setup: You can install Linux from network using PXE by installing and configuring tftpboot server as explained here.
  19. Delete all iptables rules: When you are starting to setup iptables, you might want to delete (flush) all the existing iptables as shown here.
  20. Disable ping replies: Someone can flood the network with ping -f. If ping reply is disabled as explained here we can avoid this flooding.
  21. Block ip address using fail2ban: Fail2ban is a intrusion preventon framework that scans log files for various services ( SSH, FTP, SMTP, Apache, etc., ) and bans the IP that makes too many password failures. It also updates iptles firewall rules to reject these ip addresses.
  22. Package management using dpkg: On debian, you can install or remove deb packages using dpkg utility.
  23. Alfresco content management system: Alfresco is the best open source content management system. Everything you need to know to install and configure Alfresco is explained here.
  24. Bugzilla bug tracking system: Bugzilla is the best open source bug tracking system. Everything you need to know to install and configure Bugzilla is explained here.
  25. Rpm, deb, dpot and msi packages: This article explains how to view and extract files from various package types used by different Linux / UNIX distributions.
  26. Backup using rsnapshot: You can backup either a local host or remote host using rsnapshot rsync utility. rsnapshot uses the combination of rsync and hard links to maintain full-backup and incremental backups. Once you’ve setup and configured rsnapshot, there is absolutely no maintenance involved in it. rsnapshot will automatically take care of deleting and rotating the old backups.
  27. Create Linux user: This article explains how to create users with default configuration, create users with custom configuration, create users interactively, and creating users in bulk.
  28. Mount and view ISO file: ISO files are typically used to distribute the operating system. Most of the linux operating system that you download will be on ISO format. This explains how to view and mount any ISO file both as regular use and as root user.
  29. Manage password expiration and aging: Linux chage command can be used to perform several practical password aging activities including how-to force users to change their password.
  30. ifconfig examples: Interface configurator command ifconfig is used to initialize the network interface and to enable or disable the interfaces as shown in these 7 examples.
  31. Oracle db startup an sthudown: Every sysadmin should know some basic DBA operations. This explains how to shutdown and start the oracle database.
  32. PostgreSQL install and configure: Similar to mySQL, postgreSQL is very famous and feature packed free and open source database. This is a jumpstart guide to install and configure postgresql from source on Linux.
  33. Magic SysRq key: Have you wondered what the SysRq key on your keyboard does. Here is one use for it. You can safely reboot Linux using the magic SysRq key as explained here.
  34. Wakeonlan Tutorial: Using Wakeonlan WOL, you can turn on the remote servers where you don’t have physical access to press the power button.
  35. List hardware spec using lshw: ls+hw = lshw, which lists the hardware specs of your system.
  36. View hardware spec using dmidecode: dmidecode command reads the system DMI table to display hardware and BIOS information of the server. Apart from getting current configuration of the system, you can also get information about maximum supported configuration of the system using dmidecode. For example, dmidecode gives both the current RAM on the system and the maximum RAM supported by the system.
  37. Use the support effectively: Companies spend lot of cash on support mainly for two reasons: 1) To get help from vendors to fix critical production issues 2) To keep up-to-date with the latest version of the software and security patches released by the vendors. In this article, I’ve given 10 practical tips for DBAs, sysadmins and developers to use their hardware and software support effectively.
  38. Install/Upgrade LAMP using Yum: Installing LAMP stack using yum is a good option for beginners who don’t feel comfortable installing from source. Also, Installing LAMP stack using yum is a good choice, if you want to keep things simple and just use the default configuration.
  39. Template to track your hardware assests: If you are managing more than one equipment in your organization, it is very important to document and track ALL information about the servers effectively. In this article, I have listed 36 attributes that needs to be tracked for your equipments, with an explanation on why it needs to be tracked. I have also provided a spreadsheet template with these fields that will give you a jumpstart.
  40. Disable SELinux: If you don’t understand how SELinux works and the fundamental details on how to configure it, keeping it enabled will cause lot of issues. Until you understand the implementation details of SELinux you may want to disable it to avoid some unnecessary issues as explained here.
  41. Install PHP5 from source: This is a step-by-step guide to install PHP5 from source on UNIX environment.
  42. Install MySQL from source: This is a step-by-step guide to install MySQL from source on UNIX environment.
  43. Launch Linux clients on windows: If you are using SSH client to connect to Linux server from your Windows laptop, sometimes it may be necessary to launch UI application on the remote Linux server, but to display the UI on the windows laptop. Cygwin can be used to install software on Linux from Windows and launch Linux X client software on Windows.
  44. IPCS: IPC allows the processes to communicate with each another. The process can also communicate by having a file accessible to both the processes. Processes can open, and read/write the file, which requires lot of I/O operation that consumes time. This explains different types of IPCS and provides 10 IPCS command examples.
  45. Logical Volume Manager: Using LVM we can create logical partitions that can span across one or more physical hard drives.You can create and manage LVM using vgcreate, lvcreate, and lvextend lvm2 commands as shown here.
  46. 15 Tcpdump examples: tcpdump is a network packet analyzer. tcpdump allows us to save the packets that are captured, so that we can use it for future analysis. The saved file can be viewed by the same tcpdump command. We can also use open source software like wireshark to read the tcpdump pcap files.
  47. Manage partition using fdisk: Using fdisk you can create a maximum of four primary partition, delete an existing partition, or change existing partition. Using fidsk you are allowed to create a maximum of four primary partition, and any number of logical partitions, based on the size of the disk.
  48. VMWare fundamentals: At some point every sysadmin should deal with virtualization. VMWare is a very popular choise to virtualize your server environment. This article will provide the fundamental information for you to get a jumpstart on VMWare.
  49. Rotate the logs automatically: Manging log files is an importat part of sysadmin life. logrotate make it easy by allowing you to setup automatica log rotation based on several configurations. Using logrotate you can also configure it to execute custom shell scripts immediately after log rotation.
  50. Passwordless SSH login setup: Using ssh-keygen and ssh-copy-id you can setup passwordless login to remote Linux server. ssh-keygen creates the public and private keys. ssh-copy-id copies the local-host’s public key to the remote-host’s authorized_keys file.

My Collection of Useful Linux Admin Tricks

The purpose of Theja Cool Solutions is to disseminate information that contributors provide and share what they think is Cool. To continue with this purpose and tradition, I have compiled a list of what I think are Cool Tips and Shortcuts that have greatly improved the efficiency of my life with Linux.
I hope you think they are Cool Solutions too!
Distro Packages:
Ever see a package and wonder what it does or what it’s purpose is? Some package names are very cryptic and without looking them up on the Internet or YaST, you’re kind of left wondering. RPM can tell you on the fly. I’ll give several examples of what we can discover about a particular package.
For our example, we’ll use the package “fam” I know it is a File Alteration Monitor, because I looked it up.
We first need the entire package name. We’ll query the rpm database and grep it.
# rpm -qa | grep fam
fam-2.7.0-9.2
fam-server-2.7.0-9.2
#
We can see there is a server daemon too. We just care about the fam-2.7.0-9.2
To retrieve information about this package we’ll use the rpm –qi parms.
# rpm -qi fam-2.7.0-9.2

Name           :   fam                   Relocations: (not relocatable)
Version        :   2.7.0                 Vendor: SUSE LINUX Products GmbH, Nuernberg, Germany
Release      :    9.2                     Build Date: Fri Jun 16 06:33:35 2006
Install Date:    Tue Mar 17 00:58:38 2009      Build Host: leukozyt.suse.de
Group          :    System/Daemons                Source RPM: fam-2.7.0-9.2.src.rpm
Size              :    78539                            License: Other License(s), see package, LGPL
Signature    :    DSA/SHA1, Fri Jun 16 06:42:18 2006, Key ID a84edae89c800aca
Packager    :    http://bugs.opensuse.org
URL             :    http://oss.sgi.com/projects/fam/
Summary    :   File Alteration Monitoring Daemon
Description :
Fam is a file alteration monitoring service. With it, you can receive
signals when files are created or changed.

This package provides libfam, which is used by KDE and GNOME. It also
provides a tool for the console called fileschanged.

To use fam notifications (it can reduce the network load on NFS
servers, especially if they host user home directories) you need to run
the fam daemon, which can be found in the fam-server package.

Authors:
--------
    Bruce Karsh
    Bob Miller
    SGI corp.

    Author of fileschanged command line tool:
    Ben Asselstine <bda@panix.com>
Distribution: SUSE Linux Enterprise 10 (i586)
#

Discarding All Output

We’ve all seen the string of characters appended to a command, either in a script or in a crontab file.
“>/dev/null 2>&1”
Although a bit cryptic, it means, literally, redirect output to the file /dev/null and fold all errors to the same. Or send all output to a black hole called /dev/null
1 is the file descriptor for STDOUT or Standard Output
2 is the file descriptor for STDERR or Standard Error Output
You can also redirect to a file using the same, but changing the target file.
# ls /var/  >/tmp/listing 2>&1
# cat /tmp/listing 
X11R6
adm
cache
games
lib
lock
log
mail
novell
opt
run
spool
tmp
yp
#

Shutdown and Rebooting

Here are some examples of what you can do with the shutdown command. I don’t show actual examples, because of the nature of the command.
Shutdown the server at a specific time
 # shutdown 8:00

Shutdown the server in 15 mins.
# shutdown +15

Shutdown the server now and reboot it.
# shutdown -r now

Shutdown the server now and halt (power off)
# shutdown -h now

Cancel a shutdown
# shutdown -c

I rarely use shutdown as I have become fond of init 6 and init 0. We are simply changing the runlevel to either 0 (halt) or 6 (restart)
# init 6

This command is equivalent to “shutdown –r now”
# init 0

This one is equivalent to “shutdown –h now”

Adding Local Users

Creating a user through YaST involves a few steps that are a bit time consuming if you have several to add and several servers to add them.
Using useradd can add a single user to a system including password in a second.
 # /usr/sbin/useradd -u 12345 -g users -d /home/user01 -m -c "User Dude - UNIX Administrator -" -s /bin/bash -p '$1$01UBH4p3$sY7PTSrW1rdfQ68E1' user01

-u = uid – If you leave this off, one will be created. Although this is perfectly fine, if you use templates or NFS shares, it might be useful to assign a unique uid to each user. I prefer Employee Numbers. They are always unique and it creates a consistency within your servers. Find what suits your needs and go with it.
-g = default group
-d = Home Directory
-m = Create the Home directory
-c = Comment – Like the name and title of the user. Helpful in determining the user’s role later.
-s = Shell – Which shell will the user use.
-p = Password – Encrypted password hash in single quotes. You can generate one with crypt or if the user is on an existing server, you can copy and paste from the /etc/shadow file.
Finally, “user01” the user’s ID.
I copy these useradd strings and place them in a file that I can encrypt and store securely, so if I have to add them to another box later, I can just copy and paste them on the command line and be done.
Create a default password, like Chang3m3 and crypt it, then copy the hash to this same notepad file for use later.

Password Aging

The password will expire in 90 Days.
# chage -M 90 username 
The password never expires
# chage -M 99999 -E 99999 username
Expire the current password. Useful for password resets and new accounts.
# passwd -e username

NIC Information and settings

If you have a physical server, you can use ethtool to view or set certain parameters for your NICs. Speed, Duplex and AutoNegotiate are the common settings.
To view the current settings, just specify the device name.
# ethtool eth0
Settings for eth0:
          Supported ports: [ MII ]
          Supported link modes:   10baseT/Half 10baseT/Full
                                               100baseT/Half 100baseT/Full
                                               1000baseT/Half 1000baseT/Full
          Supports auto-negotiation: Yes
          Advertised link modes:  10baseT/Half 10baseT/Full
                                               100baseT/Half 100baseT/Full
                                               1000baseT/Half 1000baseT/Full
          Advertised auto-negotiation: Yes
                 Speed: 100Mb/s
                 Duplex: Full
                 Port: Twisted Pair
                 PHYAD: 1
                 Transceiver: internal
                 Auto-negotiation: on
                 Supports Wake-on: g
                 Wake-on: d
                 Current message level: 0x000000ff (255)
                 Link detected: yes

#
Normally you do not want auto-negotiation unless it is done on both sides. Auto-negotiation is a protocol. It does NOT automatically determine the configuration of the port on the other side of the Ethernet cable and then match it.
#  ethtool -s eth1 speed 1000 duplex full autoneg off 
#
It should be noted that ethtool doesn’t work on Virtual Machines.

Disk Usage

Wonder which directory is utilizing the most space of a particular partition? Then it’s time to call in the “ducks”.
“df” with the “-h” option only tells us how much space is in use.
# df -h
Filesystem                      Size  Used Avail Use% Mounted on
/dev/mapper/root-root     20G  3.9G   15G  21% /
devtmpfs                       1.8G  112K  1.8G   1% /dev
tmpfs                 1.8G     0  1.8G   0% /dev/shm
/dev/sda1             479M   37M  418M   9% /boot
/dev/mapper/root-opt  9.9G  639M  8.8G   7% /opt
/dev/mapper/root-tmp  9.9G  1.3G  8.1G  14% /tmp
/dev/mapper/root-var   51G  752M   48G   2% /var
 
 #
“du” estimates disk usage. But using “du” by itself is a little hard to read. That’s where the “-cks” makes the output more readable.
-c = display a grand total
-k = block size 1K
-s = summarize
Using /home as an example, here’s the output for “du –cks”
# du -cks
746592  .
746592  total
#
Not too much meaning, One of the parameters for “du” is FILE or what you want to show size. We’ll run the command again with a “*” to show all home directories.
# du -cks *
72        user01
72        user02
14524    user03
72        user04
730472   user05
72        user06
72        user07
72        user08
72        user09
72        user10
72        user11
72        user12
72        user13
746588  total
#
Now we can see that the most space under /home/ belongs to user03 and especially, user05.
But what if you have a lot of subdirectories and all you care about is maybe the top 10?
We’ll add some pipes to show the Top 10.
“sort” can show us the order, since we want the highest to lowest in usage, we want to use the “-r” (reverse) option and we are using numbers, so we also want the “-n” (numeric) option.
Since we only care about the top 10, we’ll pipe all of this output through “head” and specify “-11” to show only the top 10.
Here is our command, “du -cks * |sort -rn |head -11” and the output.
# du -cks * |sort -rn |head -11
746588  total
730472  user05
14524   user03
72      user01
72      user02
72      user04
72      user06
72      user07
72      user08
72      user09
72      user10
#
Now we can quickly zero in on the offender.
A cool trick I learned a few years ago was to put this command string in my .profile file as an Alias and name it “ducks”
alias ducks='du -cks * |sort -rn |head -11'
Now all I have to type is “ducks” at the command prompt and get the same output.

Ports and process

There are times when I have a new server that needs to communicate to another system on a particular port and I’m not sure if the network guys have opened it for me yet. I can use a quick “netcat” command to see if it’s open or not.
We’ll use ports for eDirectory in this example.
# netcat –v –v –z edirserver1.mydomain.net 524
edirserver1.mydomain.net [10.100.100.2] 524 (ncp) open
 sent 0, rcvd 0
#
The parms for this is “-v” (verbose) add a second “-v” (more verbose), “-z” (zero-IO or don’t actually send any data)
If the port is not open, or of the target server is not listening then netcat will timeout with an error. IP addresses can be used also.
To determine what process is hold a port open, use netstat. We’ll use the options, “-l” (listening sockets), “-n” (show only numeric ports, don’t match them to services) and “-p” (what process is using it)
# netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name 
tcp 0 0 0.0.0.0:5280 0.0.0.0:* LISTEN 698/perl 
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 217/httpd 
tcp 0 0 10.100.10.2:53 0.0.0.0:* LISTEN 220/named 
tcp 0 0 10.100.10.6:53 0.0.0.0:* LISTEN 220/named 
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 220/named 
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 200/sshd 
udp 0 0 0.0.0.0:32768 0.0.0.0:* 220/named 
udp 0 0 10.100.10.2:53 0.0.0.0:* 220/named 
#
We see the usual stuff, DNS, Web, SSH, but what’s perl using 5280 for? Let’s drill down a bit further and look at PID 698.
# ps auwex |grep -w 698
nocat 698 0.0 2.0 5164 3840 ? S Dec25 0:00 /usr/bin/perl -w ./bin/gateway 
PWD=/usr/local/nocat HOSTNAME=catlin.r
#
I’m using “ps” with the following parms:
a = all
x = non-interactive
u = user information
w = wide format
e = environment bits
We can see from the output that the nocat user is in the /usr/local/nocat/ running bin/gateway, a Perl process that is listening on port 5280.
Conclusion
There are literally thousands of tips and tricks you can use to make life much easier and using Linux more enjoyable, this is but a small collection of items I use on a daily basis.
If you have a cool tip or way of making your world more “cool” then please, comment to this article and share your own favorites. The Coolguys will be glad to add it. Sharing is the whole purpose of this site.
Enjoy!