Saturday, September 29, 2007

Tips And Tricks in Linux Administration

This is a compilation of tips and tricks I got from reading the mailing list from CentOS and PLUG which I will update from time to time.

1. How to get users list in a linux machine.

As local user
# cat /etc/passwd
- Seperated by username, password, UID, GID, home directory, shell

# cat /etc/group
- Use this to see group information.

getent passwd
- This handles everything nsswitch.conf does (NIS, LDAP, xyzzy, whatever).

getent passwd cut -d: -f1 sort -u
- To get just a list of usernames

2. To check what is the IP address of the DHCP server where assigned IP leased from:

For CentOS 5, the command:
# grep dhcp-server-identifier /var/lib/dhclient/dhclient-eth0.leases

or for CentOS 4, the command:
# grep dhcp-server-identifier /var/lib/dhcp/dhclient-eth0.leases

To list all PCI device:

/sbin/lspci

To determine the change log of installed software:
rpm -qi –changelog

yum install yum-changelog

Then …

man yum-changelog

or

repoquery –changelog foo

3. Robert Moskowitz Tips on Private Network IP Addresses:

If you use addresses from the 192.168 range, avoid the nets:
192.168.0.0, 192.168.1.0, 192.168.2.0, and 192.168.100.0 These are commonly used by various ‘appliances’. Choose something ‘wierd’ like 192.168.49.0 (or some other prime number less than 255). Though I tend to use 192.168.64.0, 192.168.96.0, or 192.168.128.0

Also avoid the 172.16 and 10. ranges. These are commonly used in Company internal private networks, and if you want to ‘VPN’ to them, it an cause unwanted results (like it won’t work).

This is general advice to anyone using private addresses for small usages.

4. To Get Memory Usage and Information:

free - for summary information

cat /proc/meminfo - for detailed information

5. To get hardware info:

/usr/sbin/dmidecode

6. To test for disk I/O performance:

Download ‘disktest’ utility from Linux Test Project(LTP) and do the ff:

Sequential reads:
disktest -B 4k -h 1 -I BD -K 4 -p l -P T -T 300 -r /dev/sdX

Sequential writes:
disktest -B 4k -h 1 -I BD -K 4 -p l -P T -T 300 -w /dev/sdX

Random writes:
disktest -B 4k -h 1 -I BD -K 4 -p r -P T -T 300 -r /dev/sdX

Random writes:
disktest -B 4k -h 1 -I BD -K 4 -p r -P T -T 300 -w /dev/sdX

Description of the options used:
-B 4k = 4k block ios
-h 1 = 1 second heartbeat
-I BD = block device, direct io
-K 4 = 4 threads, or 4 outstanding/overlapping ios, typical pattern
(use -K 1 for the raw performance of single drive, aka dd type output)
-p = io type, l=linear, r=random
-P T = output metrics type “Throughput”
-T 300 = duration of test 300 seconds
-r = read
-w = write

These tests will run across the whole disk/partition and the write
tests WILL BE DESTRUCTIVE so be warned!

7. To determine PCI information and replacing LAN card info:

/sbin/lspci

In /etc/modprobe.conf

Put or replace alias entries for LAN card and restart network.

8. To get driver info:

/sbin/modinfo 3w-9xxx

No comments: