Samstag, 25. Juni 2011

Linux Terminal Command Reference

System Info

date – Show the current date and time
cal – Show this month's calendar
uptime – Show current uptime
w – Display who is online
whoami – Who you are logged in as
finger user – Display information about user
uname -a – Show kernel information
cat /proc/cpuinfo – CPU information
cat /proc/meminfo – Memory information
df – Show disk usage
du – Show directory space usage
free – Show memory and swap usage

Keyboard Shortcuts

Enter – Run the command
Up Arrow – Show the previous command
Ctrl + R – Allows you to type a part of the command you're looking for and finds it

Ctrl + Z – Stops the current command, resume with fg in the foreground or bg in the background
Ctrl + C – Halts the current command, cancel the current operation and/or start with a fresh new line
Ctrl + L – Clear the screen

command | less – Allows the scrolling of the bash command window using Shift + Up Arrow and Shift + Down Arrow
!! – Repeats the last command
command !$ – Repeats the last argument of the previous command
Esc + . (a period) – Insert the last argument of the previous command on the fly, which enables you to edit it before executing the command

Ctrl + A – Return to the start of the command you're typing
Ctrl + E – Go to the end of the command you're typing
Ctrl + U – Cut everything before the cursor to a special clipboard, erases the whole line
Ctrl + K – Cut everything after the cursor to a special clipboard
Ctrl + Y – Paste from the special clipboard that Ctrl + U and Ctrl + K save their data to
Ctrl + T – Swap the two characters before the cursor (you can actually use this to transport a character from the left to the right, try it!)
Ctrl + W – Delete the word / argument left of the cursor in the current line

Ctrl + D – Log out of current session, similar to exit

Learn the Commands

apropos subject – List manual pages for subject
man -k keyword – Display man pages containing keyword
man command – Show the manual for command
man -t man | ps2pdf - > man.pdf – Make a pdf of a manual page
which command – Show full path name of command
time command – See how long a command takes

whereis app – Show possible locations of app
which app – Show which app will be run by default; it shows the full path

Searching

grep pattern files – Search for pattern in files
grep -r pattern dir – Search recursively for pattern in dir
command | grep pattern – Search for pattern in the output of command
locate file – Find all instances of file
find / -name filename – Starting with the root directory, look for the file called filename
find / -name ”*filename*” – Starting with the root directory, look for the file containing the string filename
locate filename – Find a file called filename using the locate command; this assumes you have already used the command updatedb (see next)
updatedb – Create or update the database of files on all file systems attached to the Linux root directory
which filename – Show the subdirectory containing the executable file called filename
grep TextStringToFind /dir – Starting with the directory called dir, look for and list all files containing TextStringToFind

File Permissions

chmod octal file – Change the permissions of file to octal, which can be found separately for user, group, and world by adding: 4 – read (r), 2 – write (w), 1 – execute (x)
Examples:
chmod 777 – read, write, execute for all
chmod 755 – rwx for owner, rx for group and world
For more options, see man chmod.

File Commands

ls – Directory listing
ls -l – List files in current directory using long format
ls -laC – List all files in current directory in long format and display in columns
ls -F – List files in current directory and indicate the file type
ls -al – Formatted listing with hidden files

cd dir – Change directory to dir
cd – Change to home
mkdir dir – Create a directory dir
pwd – Show current directory

rm name – Remove a file or directory called name
rm -r dir – Delete directory dir
rm -f file – Force remove file
rm -rf dir – Force remove an entire directory dir and all it’s included files and subdirectories (use with extreme caution)

cp file1 file2 – Copy file1 to file2
cp -r dir1 dir2 – Copy dir1 to dir2; create dir2 if it doesn't exist
cp file /home/dirname – Copy the file called filename to the /home/dirname directory

mv file /home/dirname – Move the file called filename to the /home/dirname directory
mv file1 file2 – Rename or move file1 to file2; if file2 is an existing directory, moves file1 into directory file2

ln -s file link – Create symbolic link link to file
touch file – Create or update file
cat > file – Places standard input into file
cat file – Display the file called file

more file – Display the file called file one page at a time, proceed to next page using the spacebar
head file – Output the first 10 lines of file
head -20 file – Display the first 20 lines of the file called file
tail file – Output the last 10 lines of file
tail -20 file – Display the last 20 lines of the file called file
tail -f file – Output the contents of file as it grows, starting with the last 10 lines

Compression

tar cf file.tar files – Create a tar named file.tar containing files
tar xf file.tar – Extract the files from file.tar

tar czf file.tar.gz files – Create a tar with Gzip compression
tar xzf file.tar.gz – Extract a tar using Gzip

tar cjf file.tar.bz2 – Create a tar with Bzip2 compression
tar xjf file.tar.bz2 – Extract a tar using Bzip2

gzip file – Compresses file and renames it to file.gz
gzip -d file.gz – Decompresses file.gz back to file

Printing

/etc/rc.d/init.d/lpd start – Start the print daemon
/etc/rc.d/init.d/lpd stop – Stop the print daemon
/etc/rc.d/init.d/lpd status – Display status of the print daemon
lpq – Display jobs in print queue
lprm – Remove jobs from queue
lpr – Print a file
lpc – Printer control tool
man subject | lpr – Print the manual page called subject as plain text
man -t subject | lpr – Print the manual page called subject as Postscript output
printtool – Start X printer setup interface

Network

ifconfig – List IP addresses for all devices on the local machine
ping host – Ping host and output results
whois domain – Get whois information for domain
dig domain – Get DNS information for domain
dig -x host – Reverse lookup host
wget file – Download file
wget -c file – Continue a stopped download

SSH

ssh user@host – Connect to host as user
ssh -p port user@host – Connect to host on port port as user
ssh-copy-id user@host – Add your key to host for user to enable a keyed or passwordless login

User Administration

adduser accountname – Create a new user call accountname
passwd accountname – Give accountname a new password
su – Log in as superuser from current login
exit – Stop being superuser and revert to normal user

Process Management

ps – Display your currently active processes
top – Display all running processes
kill pid – Kill process id pid
killall proc – Kill all processes named proc (use with extreme caution)
bg – Lists stopped or background jobs; resume a stopped job in the background
fg – Brings the most recent job to foreground
fg n – Brings job n to the foreground

Installation from source

./configure
make
make install
dpkg -i pkg.deb – install a DEB package (Debian / Ubuntu / Linux Mint)
rpm -Uvh pkg.rpm – install a RPM package (Red Hat / Fedora)

Stopping & Starting

shutdown -h now – Shutdown the system now and do not reboot
halt – Stop all processes - same as above
shutdown -r 5 – Shutdown the system in 5 minutes and reboot
shutdown -r now – Shutdown the system now and reboot
reboot – Stop all processes and then reboot - same as above
startx – Start the X system

Donnerstag, 22. Juli 2010

apt-get update

The basics

apt-get update
Resynchronise installed packages with their sources. (Always do this before an upgrade.)

apt-get upgrade
Install the newest version of all packages installed on the system.

apt-get dist-update
Upgrade to the latest version of your distribution.

apt-get install xxx yyy zzz
Install programs xxx, yyy and zzz along with all their dependencies.

apt-get remove xxx yyy zzz
Remove programs xxx, yyy and zzz.

apt-get purge xxx yyy zzz
Remove programs xxx, yyy and zzz and delete any configuration files that they used.

apt-get check
Update the package cache and check for any broken dependencies.

apt-get clean
Clean out retrieved package files.

apt-get autoclean
Clean out retrieved package files, but only those that are no longer needed.

apt-get autoremove
Remove any packages that were installed to satisfy dependencies but are no longer required.



Advanced stuff
So much for the basics, what about those neat tricks I mentioned? Well, did you know you can use apt-get to get a package’s source code?

apt-get source xxx
Retrieve source files for package xxx.

Or its build dependencies?

apt-get build-dep xxx
Get all the dependencies needed to build package xxx.

Or that you could get it to fetch and build the package for you?

apt-get source xxx -b
Fetch the source code then compile it. (The -b switch means ”build it„.)

The result with be a .deb package which you can install using the Debian package manager command:

dpkg -i xxx.deb



Really advanced stuff

apt-get moo
Try it! :)

Sonntag, 20. Juni 2010

# /etc/systune.conf

# Format:
# :
# :
# ...

# Filesystem tuning

# defaults*10 for kernel 2.0
/proc/sys/kernel/file-max:10240
/proc/sys/kernel/inode-max:30720

# defaults*10 for kernel 2.2
/proc/sys/fs/file-max:40960
/proc/sys/fs/inode-max:81920

# VM tuning

# More aggresive buffering, usable for servers
/proc/sys/vm/bdflush:100 5000 640 2560 150 30000 5000 1884 2

# Network tuning

# Maximal number of remembered connection requests for heavy loaded server
/proc/sys/net/ipv4/tcp_max_syn_backlog:8192

# Number of TCP retries, less for fast recovery
/proc/sys/net/ipv4/tcp_retries1:2

# Timeout about 8 sec. for outgoing SYN packets
/proc/sys/net/ipv4/tcp_syn_retries:1

# More open sockets
/proc/sys/net/ipv4/ip_local_port_range:10000 65000

# Disable select acknowledgments (SACKs).
/proc/sys/net/ipv4/tcp_sack:0

# Disable timestamps as defined in RFC1323.
/proc/sys/net/ipv4/tcp_timestamps:0

# Network settings

# IP forwarding
/proc/sys/net/ipv4/ip_forward:1

# domain name
#/proc/sys/kernel/domainname:my.domain.com

# Enable syncookies
/proc/sys/net/ipv4/tcp_syncookies:1

# Don't respond for broadcast ICMP
/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts:1

# FreeBSD isn't RFC1122 compatible
/proc/sys/net/ipv4/icmp_ignore_bogus_error_responses:1

# ECN doesn't work everywhere
/proc/sys/net/ipv4/tcp_ecn:0

Donnerstag, 20. Mai 2010

/etc/fstab

Field definitions

/etc/fstab contains the following fields separated by a space or tab:

					

  • - defines the storage device (i.e. /dev/sda1).
  • - tells the mount command where it should mount the to.
  • - defines the file system type of the device or partition to be mounted. Many different file systems are supported. Some examples are: ext2, ext3, reiserfs, xfs, jfs, smbfs, iso9660, vfat, ntfs, swap, and auto. The 'auto' type lets the mount command to attempt to guess what type of file system is used, this is useful for removable devices such as cdroms and dvds.
  • - define particular options for filesystems. Some options relate only to the filesystem itself. Some of the more common options are:
  • auto - File system will mount automatically at boot, or when the command 'mount -a' is issued.
  • noauto - The filesystem is mounted only when you tell it to.
  • exec - Allow the execution binaries that are on that partition (default).
  • noexec - Do not allow binaries to be executed on the filesystem.
  • ro - Mount the filesystem read only
  • rw - Mount the filesystem read-write
  • sync - I/O should be done synchronously
  • async - I/O should be done asynchronously
  • flush - specific option for FAT to flush data more often, thus making copy dialogs or progress bars to stays up until things are on the disk
  • user - Permit any user to mount the filesystem (implies noexec,nosuid,nodev unless overridden.)
  • nouser - Only allow root to mount the filesystem. (default)
  • defaults - Default mount settings (equivalent to rw,suid,dev,exec,auto,nouser,async).
  • suid - Allow the operation of suid, and sgid bits. They are mostly used to allow users on a computer system to execute binary executables with temporarily elevated privileges in order to perform a specific task.
  • nosuid - Block the operation of suid, and sgid bits.
  • noatime - Do not update inode access times on the filesystem. Can help performance (see atime options).
  • nodiratime - Do not update directory inode access times on the filesystem. Can help performance (see atime options).
  • relatime - Update inode access times relative to modify or change time. Access time is only updated if the previous access time was earlier than the current modify or change time. (Similar to noatime, but doesn't break mutt or other applications that need to know if a file has been read since the last time it was modified.) Can help performance (see atime options).
  • - Is used by the dump utility to decide when to make a backup. When installed (not installed by a standard installation of Arch Linux), dump checks the entry and uses the number to decide if a file system should be backed up. Possible entries are 0 and 1. If 0, dump will ignore the file system, if 1, dump will make a backup. Most users will not have dump installed, so they should put 0 for the entry.
  • fsck reads the number and determines in which order the file systems should be checked. Possible entries are 0, 1, and 2. The root file system should have the highest priority, 1, all other file systems you want to have checked should get a 2. File systems with a value 0 will not be checked by the fsck utility.

Example

Here is an example /etc/fstab using kernel naming (/dev/sdx) descriptors:

#                                    

none /dev/pts devpts defaults 0 0
none /dev/shm tmpfs defaults 0 0

/dev/cdrom /media/cd iso9660 ro,user,noauto,unhide 0 0
/dev/dvd /media/dvd udf ro,user,noauto,unhide 0 0
/dev/fd0 /media/fl auto user,noauto 0 0

/dev/sda2 / ext4 defaults,noatime 0 1
/dev/sda6 /home ext4 defaults,noatime 0 2
/dev/sda7 swap swap defaults 0 0

Defining filesystems

You can define the filesystems in the /etc/fstab configuration in three different ways: by kernel naming descriptors, by UUID, or by labels. The advantage of using UUIDs or labels is that they are not dependent on disk order. This is useful if you change your storage device order in the BIOS, you switch storage device cabling, or because some BIOS's may occasionally change the order of storage devices.

Kernel naming

You can get kernel naming descriptors using fdisk:

# fdisk -l

...

Device Boot Start End Blocks Id System
/dev/sda1 * 1 2550 20482843+ b W95 FAT32
/dev/sda2 2551 5100 20482875 83 Linux
/dev/sda3 5101 7650 20482875 83 Linux
/dev/sda4 7651 121601 915311407+ 5 Extended
/dev/sda5 7651 10200 20482843+ 83 Linux
/dev/sda6 10201 17849 61440561 83 Linux
/dev/sda7 17850 18104 2048256 82 Linux swap / Solaris
/dev/sda8 18105 18113 72261 83 Linux
/dev/sda9 18114 121601 831267328+ 7 HPFS/NTFS

UUIDs

UUIDs are generated by the make-filesystem utilities (mkfs.*) when you create a filesystem. blkid will show you the UUIDs of mounted devices and partitions:

# blkid

/dev/sda1: UUID="76E4F702E4F6C401" LABEL="vista" TYPE="ntfs"
/dev/sda2: LABEL="Root" UUID="24f28fc6-717e-4bcd-a5f7-32b959024e26" TYPE="ext4"
/dev/sda6: LABEL="Home" UUID="03ec5dd3-45c0-4f95-a363-61ff321a09ff" TYPE="ext4"
/dev/sda7: LABEL="swap" UUID="4209c845-f495-4c43-8a03-5363dd433153" TYPE="swap"
/dev/sda10: UUID="0ea7a93f-537c-4868-9201-0dc090c050e4" TYPE="crypto_LUKS"
/dev/mapper/sda10: UUID="d3560bbb-b5d5-46c5-a7a8-434c885217c7" UUID_SUB="425ab275-d520-4636-8d16-55fb2b957971" TYPE="btrfs"

An example /etc/fstab using the UUID identifiers:

#                                    

none /dev/pts devpts defaults 0 0
none /dev/shm tmpfs defaults 0 0

/dev/cdrom /media/cd iso9660 ro,user,noauto,unhide 0 0
/dev/dvd /media/dvd udf ro,user,noauto,unhide 0 0
/dev/fd0 /media/fl auto user,noauto 0 0

UUID=24f28fc6-717e-4bcd-a5f7-32b959024e26 / ext4 defaults,noatime 0 1
UUID=03ec5dd3-45c0-4f95-a363-61ff321a09ff /home ext4 defaults,noatime 0 2
UUID=4209c845-f495-4c43-8a03-5363dd433153 swap swap defaults 0 0

Labels

The device or partition is required to be labeled first. To do this, you can use common applications like gparted to label partitions or you can use e2label to label ext2, ext3, and ext4 partitions. Keep in mind that not all file system have labeling support (e.g. FAT file systems).

A device or partition must not be mounted before attempting to label them. Initially you will need to boot from a Live{CD|USB} before you can label with a gparted-like application or for ext partitions you can use e2label.

e2label /dev/ Arch_Linux

Labels can be up to 16 characters long. Technically labeling can have spaces too, however there is no way to have your fstab or GRUB configuration file (for that matter) be able to recognize them by that label if you do.

Labels should be unambiguous, meaning that each label should be original to prevent any possible conflicts. To enter labels into your fstab, here is an example:

#                                    

none /dev/pts devpts defaults 0 0
none /dev/shm tmpfs defaults 0 0

/dev/cdrom /media/cd iso9660 ro,user,noauto,unhide 0 0
/dev/dvd /media/dvd udf ro,user,noauto,unhide 0 0
/dev/fd0 /media/fl auto user,noauto 0 0

LABEL=Arch_Linux / ext4 defaults,noatime 0 1
LABEL=Arch_Swap swap swap defaults 0 0

Tips

Some tips.

atime options

The use of noatime, nodiratime or relatime can help disk performance for ext2, ext3, and ext4 filesystems. Linux by default keeps a record (writes to the disk) every times it reads from the disk. This was more purposeful when Linux was being used for servers and doesn't have much use for desktop use. This works good for almost all applications but Mutt that needs this information. For mutt, you should only use the relatime option.

Freitag, 19. März 2010

Google Public DNS launched





maybe its too late for me to share this news as its been more than a month they launched, i just write in case someone need it or perhaps i need it in the future.

Google started Public DNS service like OpenDNS. Google Public DNS server IP address are

1
2
8.8.8.8
8.8.4.4

cool ip huh ? wondering how much google buy it ~~

As web pages become more complex and include more resources from multiple origin domains, clients need to perform multiple DNS lookups to render a single page. The average Internet user performs hundreds of DNS lookups each day, slowing down his or her browsing experience. As the web continues to grow, greater load is placed on existing DNS infrastructure.
Since Google’s search engine already crawls the web on a daily basis and in the process resolves and caches DNS information, we wanted to leverage our technology to experiment with new ways of addressing some of the existing DNS challenges around performance and security. We are offering the service to the public in the hope of achieving the following aims:

* Provide end users with an alternative to their current DNS service. Google Public DNS takes some new approaches that we believe offer more valid results, increased security, and, in most cases, better performance.
* Help reduce the load on ISPs’ DNS servers. By taking advantage of our global data-center and caching infrastructure, we can directly serve large numbers of user requests without having to query other DNS resolvers.
* Help make the web faster and more secure. We are launching this experimental service to test some new ways to approach DNS-related challenges. We hope to share what we learn with developers of DNS resolvers and the broader web community and get their feedback

you can use google dns for free, for linux edit /etc/resolv.conf and put those dns

Disable CPU Throttling for a faster result

Just noticed that CentOS has the “cpuspeed” service that throttles the CPU and causes my pages to parse 2X slow.

# service cpuspeed status
Frequency scaling enabled using ondemand governor

# cat /proc/cpuinfo

model name : Intel(R) Xeon(R) CPU X5570 @ 2.93GHz
stepping : 5
cpu MHz : 1600.000

and to disable it

# service cpuspeed stop
Disabling ondemand cpu frequency scaling: [ OK ]
# chkconfig cpuspeed off

# cat /proc/cpuinfo

model name : Intel(R) Xeon(R) CPU X5570 @ 2.93GHz
stepping : 5
cpu MHz : 2934.000

page generations and mysql queries are 2X faster now.

Solve and Reduce CPU/memory usage of Firefox

Firefox is the best browser around right now, with a large open-source community behind it. Firefox maybe the best in terms of features and flexibility, but all of this comes at a price. Firefox is a resource hog. Firefox 3 has been a lot better at managing resources, yet it has high memory usage, and occasionally, CPU usage hit 100% and the system hangs. It can take up 140 MB of RAM when multiple tabs are open.

There are many reasons for Firefox hanging and/or using excessive memory. Plugins and extensions, which are not part of the default Firefox install may cause this. Poorly optimized sites which load several images and ads may cause this. These are inevitable.

Before mentioning the tips, let me say that upgrading to Firefox 3 is absolutely essential. Firefox 2 was notorious for poor resource and memory management, and Firefox 3 has improved in that aspect a lot. The tips mentioned here are for Firefox 3 (but will work for Firefox 2 too).

  1. Disable Java:
    Disable the Java plugin, by going to Tools>Options>Content tab> uncheck Enable Java. Most sites do not use Java. So, you end up wasting CPU resources for a plugin(yes, it is sorta plugin) that you do not use.
  2. Install Flashblock:
    If updating Flash plugin does not help, install Flashblock extension. You will see a play button instead of the Flash content. When you want to play something, click the play button.
The fact is, these little things can be the difference between a crashing browser and a perfectly-working one

tweaking firefox for ‘flash’ web browsing

Fast loading web pages while surfing the Internet may have more to do with your web browser settings and preferences than your Internet connection speed.

Try these easy Firefox tweaks and you’ll see that you’re surfing the Internet from 3 to 30 times faster!


To get started, open your Firefox web browser. In the address/location bar type [about:config] and then press your Enter key. (NOTE: DON’T TYPE THE BRACKETS.)

Open Firefox Web Browser

Tweak #1:
In the Filter bar type [network.http.pipelining]. Then, double-click on this line under Preference Name in order to change the value from false to true.

Firefox Web Browser Tricks

Tweak #2:
In the Filter bar type [network.http.pipelining.maxrequests]. Then, double-click on this line under Preference Name and change the value from 4 to a higher number anywhere from 10 to 30. I set mine to 30.

Firefox Web Browser Tricks

Tweak #3:
In the Filter bar type [network.http.proxy.pipelining]. Then, double-click on this line under Preference Name in order to change the value from false to true.

Firefox Web Browser Tweaks

Tweak #4:
In the Filter bar type [network.dns.disableIPv6]. Then, double-click on this line under Preference Name in order to change the value from false to true.

Firefox Web Browser Tricks

Tweak #5:
In the Filter bar type [plugin.expose_full_path]. Then, double-click on this line under Preference Name in order to change the value from false to true.

Firefox Web Browser Tweaks

Tweak #6:
In the Filter bar type [network.protocol-handler.external.ms-help]. Now, you are going to create a new Preference Name with an Integer Value. To do this, right-click on this line under Preference Name and select New, then Integer.

Firefox Web Browser Tweaks

In the New Integer value box type in [nglayout.initialpaint.delay] and click OK. Then in the Enter Integer value box type [0] (that’s a zero) and click OK.

Firefox Tricks

Tweak #7:
In the Filter bar again type [network.protocol-handler.external.ms-help]. Now, you are going to create another new Preference Name with an Integer Value. To do this, right-click on this line under Preference Name and select New, then Integer. In the New Integer value box type in [content.notify.backoffcount] and click OK. Then in the Enter Integer value box type [5] and click OK.

Firefox Tricks

Tweak #8:
In the Filter bar again type [network.protocol-handler.external.ms-help]. Now, you are going to create another new Preference Name with an Integer Value. To do this, right-click on this line under Preference Name and select New, then Integer. In the New Integer value box type in [ui.submenuDelay] and click OK. Then in the Enter Integer value box type [0] (that’s a zero) and click OK.

Firefox Tweaks

Now, close your web browser and restart it. You’ll see how much faster web pages are loading. I sure did.

Let me know if these tweaks increase your Internet browsing speed. Know of any other tweaks or tricks? Let me know and I’ll add them.

Increase Your Server/HDD Performance With “noatime” Dramatically

Most people when they try to optimize their servers they always say tweak mysql, install APC, Xcache, or something similar but most people forget about optimizing the HDD. Forums often cause high I/O. You usually have to upgrade your hdd to 10k rpm+ but with noatime, you might not need to do that.

My I/O was around 1500-2000 blocks/a sec. With noatime modification I was able to reduce it to under 500. That’s atleast a 300% improvement if I do my math correctly. I remember reading a blog, someone with raid 0, gained 900% in improvements when they changed to noatime.

What’s noatime?
Linux has a special mount option for file systems called noatime. If this option is set for a file system in /etc/fstab, then reading accesses will no longer cause the atime information (last access time – don’t mix this up with the last modified time – if a file is changed, the modification date will still be set) that is associated with a file to be updated (in reverse this means that if noatime is not set, each read access will also result in a write operation). Therefore, using noatime can lead to significant performance gains.
Warnings
I’m a noob. However I did on my server and it worked. Also if you google noatime, you will a lot of threads on it and how it improves I/O. Use at your own risk. However I don’t think there’s any risk.

Step One.
# pico /etc/fstab (or whatever you use “nano”, “vi” etc)

Step Two.
Next add “noatime” into the file. I added noatime to 4 mounts. My /home /dir /var and /usr. For me those 4 usually cause the most I/O. Most people’s fstab should look like mine below except without the “noatime” line in there. I did read somewhere that, you should not add noatime to /proc and /boot.

Step Three.
type
# mount -a -o remount

thats all! with this mods could improve up to 300% performance boost from I/O of a servers

List of public DNS

if your ISP have problem with DNS, you can use public dns for name resolution.

Level 3 Communications

1
2
3
4
5
6
4.2.2.1
4.2.2.2
4.2.2.3
4.2.2.4
4.2.2.5
4.2.2.6

OpenDNS.com

1
2
208.67.222.222
208.67.220.220

Scrubit.com

1
2
67.138.54.100
207.225.209.66

Verizon

1
2
3
4
5
6
7
8
9
10
11
151.197.0.38
151.197.0.39
151.202.0.84
151.202.0.85
151.202.0.85
151.203.0.84
151.203.0.85
199.45.32.37
199.45.32.38
199.45.32.40
199.45.32.43

Service provider:dnsadvantage
Dnsadvantage free dns server list:

1
2
156.154.70.1
156.154.71.1

save it on note, in case you cant online because of dns not resolviing.

To add DNS server, take property of your LAN Card, Click “Internet Protocol (TCP/IP)” click the button property. On next page, you have option to specify your own dns server.

tweaking tcp/ip Syctl.conf

The TCP/IP parameters for tweaking a Linux-based machine for fast internet connections are located in /proc/sys/net/… (assuming 2.1+ kernel). This location is volatile, and changes are reset at reboot. There are a couple of methods for reapplying the changes at boot time, ilustrated below.

Locating the TCP/IP related parameters

All TCP/IP tunning parameters are located under /proc/sys/net/… For example, here is a list of the most important tunning parameters, along with short description of their meaning:

/proc/sys/net/core/rmem_max - Maximum TCP Receive Window
/proc/sys/net/core/wmem_max – Maximum TCP Send Window
/proc/sys/net/ipv4/tcp_timestamps – timestamps (RFC 1323) add 12 bytes to the TCP header…
/proc/sys/net/ipv4/tcp_sack – tcp selective acknowledgements.
/proc/sys/net/ipv4/tcp_window_scaling – support for large TCP Windowsmag glass 10x10 tweaking tcp/ip Syctl.conf (RFC 1323). Needs to be set to 1 if the Max TCP Window is over 65535.

Keep in mind everything under /proc is volatile, so any changes you make are lost after reboot.

There are some additional internal memory buffers for the TCP Window, allocated for each connection:
/proc/sys/net/ipv4/tcp_rmem – memory reserved for TCP rcv buffers (reserved memory per connection default)
/proc/sys/net/ipv4/tcp_wmem – memory reserved for TCP snd buffers (reserved memory per connection default)

The tcp_rmem and tcp_wmem contain arrays of three parameter values: the 3 numbers represent minimum, default and maximum memory values. Those 3 values are used to bound autotunning and balance memory usage while under global memory stress.

Applying TCP/IP Parameters at System Boot

You can edit /etc/rc.local, or /etc/boot.local depending on your distribution so the parameters get automatically reapplied at boot time. The TCP/IP parameters should be self-explanatory: we’re basically setting the TCP Window to 256960, disabling timestamps (to avoid 12 byte header overhead), enabling tcp window scaling, and selective acknowledgements:

echo 256960 > /proc/sys/net/core/rmem_default
echo 256960 > /proc/sys/net/core/rmem_max
echo 256960 > /proc/sys/net/core/wmem_default
echo 256960 > /proc/sys/net/core/wmem_max

echo 0 > /proc/sys/net/ipv4/tcp_timestamps
echo 1 > /proc/sys/net/ipv4/tcp_sack
echo 1 > /proc/sys/net/ipv4/tcp_window_scaling

Change the values above as desired, depending on your internet connection and maximum bandwidth/latency. There are other parameters you can change from the default if you’re confident in what you’re doing – just find the correct syntax of the values in /proc/sys/net/… and add a line in the above code analogous to the others. To revert to the default parameters, you can just comment or delete the above code from /etc/rc.local and restart.

Another method to reapply the values upon boot is to include the following in your /etc/sysctl.conf (adjust RWIN values as needed):

net.core.rmem_default = 256960
net.core.rmem_max = 256960
net.core.wmem_default = 256960
net.core.wmem_max = 256960

net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1

Notes:
Execute sysctl -p to make these new settings take effect.
To manually set the MTU value under Linux, use the command:
ifconfig eth0 mtu 1500 (where 1500 is the desired MTU size)

Changing Current Values without rebooting

The current TCP/IP parameters can be edited without the need for reboot in the following locations:

/proc/sys/net/core/
rmem_default = Default Receive Window
rmem_max = Maximum Receive Window
wmem_default = Default Send Window
wmem_max = Maximum Send Window

/proc/sys/net/ipv4/
You’ll find timestamps, window scalling, selective acknowledgements, etc.

Keep in mind the values in /proc will be reset upon reboot. You still need to add the code in /etc/rc.local or /etc/boot.local in order to have the changes applied at boot time as described above.

Other TCP Parameters to consider

TCP_FIN_TIMEOUT
This setting determines the time that must elapse before TCP/IP can release a closed connection and reuse its resources. During this TIME_WAIT state, reopening the connection to the client costs less than establishing a new connection. By reducing the value of this entry, TCP/IP can release closed connections faster, making more resources available for new connections. Addjust this in the presense of many connections sitting in the TIME_WAIT state:

# echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
(default: 60 seconds, recommended 15-30 seconds)

Notes:
You can use any of the earlier described methods to reapply these settings at boot time.
Here is a quick way to view the number of connections and their states:

netstat -tan | grep ‘:80 ‘ | awk ‘{print $6}’ | sort | uniq -c

TCP_KEEPALIVE_INTERVAL
This determines the wait time between isAlive interval probes. To set:

echo 30 > /proc/sys/net/ipv4/tcp_keepalive_intvl
(default: 75 seconds, recommended: 15-30 seconds)

TCP_KEEPALIVE_PROBES
This determines the number of probes before timing out. To set:

echo 5 > /proc/sys/net/ipv4/tcp_keepalive_probes
(default: 9, recommended 5)

TCP_TW_RECYCLE
It enables fast recycling of TIME_WAIT sockets. The default value is 0 (disabled). The sysctl documentation incorrectly states the default as enabled. It can be changed to 1 (enabled) in many cases. Known to cause some issues with hoststated (load balancing and fail over) if enabled, should be used with caution.

echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
(boolean, default: 0)

TCP_TW_REUSE
This allows reusing sockets in TIME_WAIT state for new connections when it is safe from protocol viewpoint. Default value is 0 (disabled). It is generally a safer alternative to tcp_tw_recycle

echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
(boolean, default: 0)

Note: The tcp_tw_reuse setting is particularly useful in environments where numerous short connections are open and left in TIME_WAIT state, such as web serversmag glass 10x10 tweaking tcp/ip Syctl.conf. Reusing the sockets can be very effective in reducing server load.

Kernel Recompile Option

There is another method one can use to set TCP/IP parameters, involving kernel recompile… If you’re brave enough. Look for the parameters in the following files:
/LINUX-SOURCE-DIR/include/linux/skbuff.h
Look for SK_WMEM_MAX & SK_RMEM_MAX
/LINUX-SOURCE-DIR/include/net/tcp.h
Look for MAX_WINDOW & MIN_WINDOW

taken from speedguidenet

How to increase IP_CONNTRACK value

First of all, let us see what IP_CONNTRACK is. It is nothing but the number of sessions that can be handled simultaneously by netfilter in kernel memory.

A) Temporarily, you can increase this by echoing a high value to ip_conntrack_max file.

echo >> /proc/sys/net/ipv4/ip_conntrack_max

But since /proc is a virtual space, if you restart iptables or if you reboot
your server the value set will be lost.

B) The permanent solution is to append it directly to the kernel parameters:

# open /etc/sysctl.conf

# Append this line >> net.ipv4.ip_conntrack_max = CONNTRACK_MAX

where ,CONNTRACK_MAX = RAMSIZE (in bytes) / 16384 / (x / 32)
where x is the number of bits in a pointer (for example, 32 or 64 bits).

To save the changes quit the editor and execute the command:

# sysctl -p

C) If you love shell commands, use the following command:

# sysctl -w net.ipv4.ip_conntrack_max=CONNTRACK_MAX and then run

# sysctl -p

To see the new value you can ‘cat’ ” /proc/sys/net/ipv4/ip_conntrack_max ” file.

or sysctl -a | grep conntrack

D) For servers having APF firewall, you need to adopt a different method since most of the sysctl parameters are loaded by APF.

# Open APF configuration file “/etc/apf/conf.apf”.

# Locate the parameter “SYSCTL_CONNTRACK”, replace the value and then restart APF.

Tuning Linux kernel for high volume media serverChange to ‘deadline’ I/O scheduler * From command line (change the device ‘sda’ to appropriate device

Change to ‘deadline’ I/O scheduler

*
From command line (change the device ‘sda’ to appropriate device):

1
echo “deadline” > /sys/block/sda/queue/scheduler

*
kernel parameter, change /boot/grub/menu.lst, add kernel parameter

1
elevator=deadline

Change VM parameters

There are two variables which control the behaviour of VM flushing and allocation and affect network and disk performance

1
2
3
4
    *
vm.dirty_background_ratio
*
vm.dirty_ratio

To set these values from command line

1
2
echo 20 > /proc/sys/vm/dirty_background_ratio
echo 60 > /proc/sys/vm/dirty_ratio

to make it permanent, edit /etc/sysctl.conf:

1
2
vm.dirty_background_ratio = 20
vm.dirty_ratio = 60

Increase readahead

To get current readahead value:

1
2
blockdev --getra /dev/sda
256

To increase it to a higher value like 16K:

1
blockdev --setra 16384 /dev/sda

Disable updating access time stamp for file system

Edit /etc/fstab, remove “atime” attribute if there is, add “noatime” attribute.

Donnerstag, 18. März 2010

# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.

# Controls IP packet forwarding
net.ipv4.ip_forward = 0

# Controls source route verification
net.ipv4.conf.default.rp_filter = 1

# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0

# Controls whether core dumps will append the PID to the core filename
# Useful for debugging multi-threaded applications
kernel.core_uses_pid = 1

# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1

# Controls the maximum size of a message, in bytes
kernel.msgmnb = 65536

# Controls the default maxmimum size of a mesage queue
kernel.msgmax = 65536

# Controls the maximum shared segment size, in bytes
kernel.shmmax = 4294967295

# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 268435456

Dienstag, 16. März 2010

# Disables packet forwarding
net.ipv4.ip_forward = 0
# Enables source route verification
net.ipv4.conf.default.rp_filter = 1
# Disables the magic-sysrq key
kernel.sysrq = 0
# Decrease the time default value for tcp_fin_timeout connection
net.ipv4.tcp_fin_timeout = 25
# Decrease the time default value for tcp_keepalive_time connection
net.ipv4.tcp_keepalive_time = 3600
# Turn on the tcp_window_scaling
net.ipv4.tcp_window_scaling = 1
# Turn on the tcp_sack
net.ipv4.tcp_sack = 1
# tcp_fack should be on because of sack
net.ipv4.tcp_fack = 1
# Turn on the tcp_timestamps
net.ipv4.tcp_timestamps = 1
# Enable TCP SYN Cookie Protection
net.ipv4.tcp_syncookies = 1
# Enable ignoring broadcasts request
net.ipv4.icmp_echo_ignore_broadcasts = 1
# Disable ICMP Redirect Acceptance
net.ipv4.conf.all.accept_redirects = 0
# Enable bad error message Protection
net.ipv4.icmp_ignore_bogus_error_responses = 1
# Don't Log Spoofed Packets, Source Routed Packets, Redirect Packets
net.ipv4.conf.all.log_martians = 0
# Make more local ports available
net.ipv4.ip_local_port_range = 1024 65000
# Increase maximum amount of memory allocated to shm
kernel.shmmax = 1073741824
# Improve file system performance
vm.bdflush = 100 1200 128 512 15 5000 500 1884 2
# This will increase the amount of memory available for socket input/output queues
net.ipv4.tcp_rmem = 4096 25165824 25165824
net.core.rmem_max = 25165824
net.core.rmem_default = 25165824
net.ipv4.tcp_wmem = 4096 65536 25165824
net.core.wmem_max = 25165824
net.core.wmem_default = 65536
net.core.optmem_max = 25165824
#ab wann speicher als dreckig betrachtet wird
vm.dirty_ratio=10
vm.dirty_background_ratio=5
#vfs cache pressure
vm.vfs_cache_pressure=50
#gibt den grad an wann ausgelagert wird
vm.swappiness=20
# If you are feeling daring, you can also use these settings below, otherwise just remove them. (Should increase performance)
net.core.netdev_max_backlog = 2500
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.core.rmem_default = 114688
net.core.wmem_default = 114688
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_retries1 = 3
net.ipv4.tcp_retries2 = 15
net.ipv4.tcp_retrans_collapse = 1
net.ipv4.ip_default_ttl = 64
net.ipv4.ipfrag_time = 30
net.ipv4.ip_no_pmtu_disc = 0
net.unix.max_dgram_qlen = 10
net.token-ring.rif_timeout = 600000
vm.overcommit_memory = 0
vm.page-cluster = 3
kernel.ctrl-alt-del = 0
kernel.panic = 0
kernel.acct = 4 2 30
kernel.printk = 3
kernel.shmall = 2097152
kernel.shmmax = 33554432
dev.raid.speed_limit_min = 1000
dev.raid.speed_limit_max = 200000
#ab wann speicher als dreckig betrachtet wird
vm.dirty_ratio=10
vm.dirty_background_ratio=5
#vfs cache pressure
vm.vfs_cache_pressure=50
#gibt den grad an wann ausgelagert wird
vm.swappiness=20

then

sysctl -p

sysctl -w net.ipv4.route.flush=1

/etc/sysconfig/kernel

## Path: System/Kernel
## Description:
## Type: string
## Command: /sbin/mkinitrd
#
# This variable contains the list of modules to be added to the initial
# ramdisk by calling the script "mkinitrd"
# (like drivers for scsi-controllers, for lvm or reiserfs)
#
INITRD_MODULES="processor thermal fan"

## Type: string
## Command: /sbin/mkinitrd
#
# This variable contains the list of modules to be added to the initial
# ramdisk that is created for unprivilegd Xen domains (domU); you may need
# drivers for virtual block and network devices in addition to filesystem
# and device-mapper modules.
#
DOMU_INITRD_MODULES="xennet xenblk"

## Type: string
## ServiceRestart: boot.loadmodules
#
# This variable contains the list of modules to be loaded
# once the main filesystem is active
# You will find a few default modules for hardware which
# can not be detected automatically.
#
MODULES_LOADED_ON_BOOT=""

## Type: string
## Default: ""
#
# The file name of a binary ACPI Differentiated System Description Table
# (DSDT). This table is appended to the initial ram disk (initrd) that
# the mkinitrd script creates. If the kernel finds that its initrd
# contains a DSDT, this table replaces the DSDT of the bios. If the file
# specified in ACPI_DSDT is not found or ACPI_DSDT is empty/not specified,
# no DSDT will be appended to the initrd.
# Example path /etc/acpi/DSDT.aml
# You can also override Secondary System Description Tables (SSDTs).
# Add DSDT and SSDT files separated by spaces, e.g. "DSDT.aml SSDT1.aml"
# The files must be named DSDT.aml and/or SSDT[1-9]*.aml.
# For compatiblity reasons, if only one file is added it is assumed it is
# the DSDT and will be used as such, in future the above naming scheme
# will be enforce.
# Be aware that overriding these tables can harm your system.
# Only do this if you know what you are doing and file a bug on
# bugzilla.kernel.org so that the root cause of the issue will get fixed.
ACPI_DSDT=""

## Type: string(yes)
## Default: ""
#
# Skip doing a minimal preparation of the /usr/src/linux source tree so
# that most header files can be directly included. If set, /usr/src/linux
# will not be touched.
#
SKIP_RUNNING_KERNEL=""

SCHED_MINTIMESLICE="1000"
SCHED_MAXTIMESLICE="40000"

Dienstag, 9. März 2010

# Disables packet forwarding
net.ipv4.ip_forward = 0
# Enables source route verification
net.ipv4.conf.default.rp_filter = 1
# Disables the magic-sysrq key
kernel.sysrq = 0
# Decrease the time default value for tcp_fin_timeout connection
net.ipv4.tcp_fin_timeout = 25
# Decrease the time default value for tcp_keepalive_time connection
net.ipv4.tcp_keepalive_time = 3600
# Turn on the tcp_window_scaling
net.ipv4.tcp_window_scaling = 1
# Turn on the tcp_sack
net.ipv4.tcp_sack = 1
# tcp_fack should be on because of sack
net.ipv4.tcp_fack = 1
# Turn on the tcp_timestamps
net.ipv4.tcp_timestamps = 1
# Enable TCP SYN Cookie Protection
net.ipv4.tcp_syncookies = 1
# Enable ignoring broadcasts request
net.ipv4.icmp_echo_ignore_broadcasts = 1
# Disable ICMP Redirect Acceptance
net.ipv4.conf.all.accept_redirects = 0
# Enable bad error message Protection
net.ipv4.icmp_ignore_bogus_error_responses = 1
# Don't Log Spoofed Packets, Source Routed Packets, Redirect Packets
net.ipv4.conf.all.log_martians = 0
# Make more local ports available
net.ipv4.ip_local_port_range = 1024 65000
# Increase maximum amount of memory allocated to shm
kernel.shmmax = 1073741824
# Improve file system performance
vm.bdflush = 100 1200 128 512 15 5000 500 1884 2
# This will increase the amount of memory available for socket input/output queues
net.ipv4.tcp_rmem = 4096 25165824 25165824
net.core.rmem_max = 25165824
net.core.rmem_default = 25165824
net.ipv4.tcp_wmem = 4096 65536 25165824
net.core.wmem_max = 25165824
net.core.wmem_default = 65536
net.core.optmem_max = 25165824
#ab wann speicher als dreckig betrachtet wird
vm.dirty_ratio=10
vm.dirty_background_ratio=5
#vfs cache pressure
vm.vfs_cache_pressure=50
#gibt den grad an wann ausgelagert wird
vm.swappiness=20
# If you are feeling daring, you can also use these settings below, otherwise just remove them. (Should increase performance)
net.core.netdev_max_backlog = 2500
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.core.rmem_default = 114688
net.core.wmem_default = 114688
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_retries1 = 3
net.ipv4.tcp_retries2 = 15
net.ipv4.tcp_retrans_collapse = 1
net.ipv4.ip_default_ttl = 64
net.ipv4.ipfrag_time = 30
net.ipv4.ip_no_pmtu_disc = 0
net.unix.max_dgram_qlen = 10
net.token-ring.rif_timeout = 600000
vm.overcommit_memory = 0
vm.page-cluster = 3
kernel.ctrl-alt-del = 0
kernel.panic = 0
kernel.acct = 4 2 30
kernel.printk = 3
kernel.shmall = 2097152
kernel.shmmax = 33554432
dev.raid.speed_limit_min = 1000
dev.raid.speed_limit_max = 200000
After you make the changes to the file, you can make them effective immediately by typing in /sbin/sysctl -p

Also, you will need to issue sysctl -w net.ipv4.route.flush=1 to flush the routing table to make some of these changes happen instantly.

Lastly, you can increase the size of the interface queue by typing /sbin/ifconfig eth0 txqueuelen 1000
## increase TCP max buffer size setable using setsockopt()
net.core.rmem_max =16777216
net.core.wmem_max =16777216
## increase Linux autotuning TCP buffer limits
## min, default, and max number of bytes to use
## set max to at least 4MB, or higher if you use very high BDP paths
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
## don't cache ssthresh from previous connection
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_moderate_rcvbuf = 1
## recommended to increase this for 1000 BT or higher
net.core.netdev_max_backlog = 2500
## for 10 GigE, use this, uncomment below
## net.core.netdev_max_backlog = 30000
## Turn off timestamps if you're on a gigabit or very busy network
## Having it off is one less thing the IP stack needs to work on
## net.ipv4.tcp_timestamps = 0
## disable tcp selective acknowledgements.
net.ipv4.tcp_sack =0
##enable window scaling
net.ipv4.conf.all.rp_filter=1
net.ipv4.tcp_window_scaling=1
net.ipv4.tcp_timestamps=1
net.ipv4.conf.all.log_martians=1
net.ipv4.icmp_echo_ignore_all=0
net.ipv4.icmp_echo_ignore_broadcasts=0
net.ipv4.icmp_ignore_bogus_error_responses=1
####################
# Added by Anthony #
####################

# Controls IP packet forwarding
net.ipv4.ip_forward =0

# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1

# Disables IP source routing
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel
kernel.sysrq =1

# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1

# Increase maximum amount of memory allocated to shm
# Only uncomment if needed!
# kernel.shmmax = 67108864
# Disable ICMP Redirect Acceptance
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.accept_redirects = 0

# Enable Log Spoofed Packets, Source Routed Packets, Redirect Packets
net.ipv4.conf.default.log_martians = 1
net.ipv4.conf.all.log_martians = 1

# Decrease the time default value for tcp_fin_timeout connection
net.ipv4.tcp_fin_timeout =25

# Decrease the time default value for tcp_keepalive_time connection
net.ipv4.tcp_keepalive_time =1200

# Turn on the tcp_window_scaling
net.ipv4.tcp_window_scaling = 1

# Turn on the tcp_sack
net.ipv4.tcp_sack = 1

# tcp_fack should be on because of sack
net.ipv4.tcp_fack = 1

# Turn on the tcp_timestamps
net.ipv4.tcp_timestamps = 1

# Enable TCP SYN Cookie Protection
net.ipv4.tcp_syncookies =1

# Enable ignoring broadcasts request
net.ipv4.icmp_echo_ignore_broadcasts = 1

# Enable bad error message Protection
net.ipv4.icmp_ignore_bogus_error_responses = 1

# Make more local ports available
# net.ipv4.ip_local_port_range = 1024 65000
# Set TCP Re-Ordering value in kernel to '5'

net.ipv4.tcp_reordering = 5

# Lower syn retry rates
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries =3

# Set Max SYN Backlog to '2048'
net.ipv4.tcp_max_syn_backlog =2048

# Various Settings
net.core.netdev_max_backlog = 1024

# Increase the maximum number of skb-heads to be cached
#net.core.hot_list_length = 256

# Increase the tcp-time-wait buckets pool size
net.ipv4.tcp_max_tw_buckets = 360000
#ab wann speicher als dreckig betrachtet wird
vm.dirty_ratio=10
vm.dirty_background_ratio=5
#vfs cache pressure
vm.vfs_cache_pressure=50
#gibt den grad an wann ausgelagert wird
vm.swappiness=5
fs.file-max=85000

net.core.rmem_default = 114688
net.core.wmem_default = 114688
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_retries1 = 3
net.ipv4.tcp_retries2 = 15
net.ipv4.tcp_retrans_collapse = 1
net.ipv4.ip_default_ttl = 64
net.ipv4.ipfrag_time = 30
net.ipv4.ip_no_pmtu_disc = 0
net.unix.max_dgram_qlen = 10
net.token-ring.rif_timeout = 600000
vm.overcommit_memory = 0
vm.page-cluster = 3
kernel.ctrl-alt-del = 0
kernel.panic = 0
kernel.acct = 4 2 30
kernel.printk = 3
kernel.shmall = 2097152
kernel.shmmax = 33554432
dev.raid.speed_limit_min = 1000
dev.raid.speed_limit_max = 200000

Montag, 16. November 2009

ipfire

net.ipv4.ip_forward = 1
net.ipv4.ip_dynaddr = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1

net.ipv4.tcp_sack = 0
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_window_scaling = 0
net.ipv4.tcp_syn_retries = 3
net.ipv4.tcp_synack_retries = 3

net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.default.log_martians = 1

net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.all.log_martians = 1

kernel.printk = 1 4 1 7
vm.swappiness=0
vm.mmap_min_addr = 4096

Sonntag, 1. November 2009

Problemlösung: apt-get dist-upgrade

Immer mal wieder tritt folgendes Problem auf:
dpkg: Fehler beim Bearbeiten von /var/cache/apt/archives/........dep ....
versuche ».....« zu überschreiben, welches auch in Paket ..... ist.

und das apt-get dist-upgrade stoppt.

Lösen kann man es mit:
dpkg --force-overwrite -i /var/cache/apt/archives/..........deb

Bitte genau schauen was da nach dem .../apt/archives/... steht und dann noch:
apt-get -f install


Beispiel:
dpkg: Fehler beim Bearbeiten von /var/cache/apt/archives/kdelibs-data_4%3a3.3.0-1_all.deb

dann einfach:
dpkg --force-overwrite -i /var/cache/apt/archives/kdelibs-data_4%3a3.3.0-1_all.deb

apt-get -f install

Freitag, 30. Oktober 2009

Tweaking Endian throughput

Tweaking Endian

Tweaking En ( throughput)

edit the following file - /etc/rc.d/rc.firewall.up - and add the following lines

# set network tweaks
echo 49152 > /proc/sys/fs/file-max
echo 262144 > /proc/sys/net/core/rmem_default
echo 262144 > /proc/sys/net/core/rmem_max
echo 262144 > /proc/sys/net/core/wmem_default
echo 262144 > /proc/sys/net/core/wmem_max
echo 4096 87380 8388608 > /proc/sys/net/ipv4/tcp_rmem
echo 4096 65536 8388608 > /proc/sys/net/ipv4/tcp_wmem
echo 4096 4096 4096 > /proc/sys/net/ipv4/tcp_mem
echo 1 > /proc/sys/net/ipv4/tcp_low_latency
echo 4000 > /proc/sys/net/core/netdev_max_backlog
echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range
echo 16384 > /proc/sys/net/ipv4/tcp_max_syn_backlog

To apply the throughput changes you'll need to run :
/etc/rc.d/rc.netaddress.down; /etc/rc.d/rc.netaddress.up

Freitag, 18. September 2009

VI - Visual Editor

VI - Visual Editor - der standard UNIX Editor





Der Linux/Unix standard Editor VI

VI (ausgesprochen: wie-ei) ist einer der ältesten Editoren unter UNIX bzw. Linux. Auch wenn es heutzutage per GUI einfachere und intuitiv zu bedienende "Luxus"-Editoren gibt, sind grundlegende Kenntnisse von VI ein großer Vorteil, vor allem dann, wenn man per PUTTY oder SSH nur einen remote Zugriff auf ein Linux/UNIX System hat oder das System einfach von einer Shell aus administrieren möchte.

VI entstand 1976, stammt also aus der Zeit der "Dump Terminals", der dummen seriellen Konsolen. Diese waren langsam und erlaubten gerade mal einfache Cursor-Positionierungen auf dem Bildschirm. Popup-Menüs und Maussteuerung waren darauf ausgeschlossen bzw. unbekannt. VI wurde für diese einfachen Bildschirm-Konsolen geschrieben. Seine Bedienung und sein Komfort orientieren sich daran und sind entsprechend einfach gehalten, aber letztendlich genial.
Der wesentliche Vorteil von VI ist, dass er auf fast jedem Linux/UNIX System anzutreffen ist. Dabei ist es nicht mal immer VI sondern oft ist vi nur ein Link auf einen seiner Clones, wie z.B Elvis oder VIM (VI-iMproved).
Der Lernaufwand lohnt sich für jeden User, der sich oft bzw. gern auf der Shell bewegt.

In VI gibt es 3 verschiedene Modi

Die Unterscheidung dieser drei Modi ist das "Hauptproblem" für den VI-Neuling. Hat er das einmal begriffen, läßt sich der Rest leichter verstehen/erlernen.

Diese Modi sind:
  1. Editiermodus: Mittels Editiermodus bewegt man sich durch den Text bzw. die Datei und führt Textkorrekturen aus.
    In diesen Mode geht VI, wenn er gestartet wird.
  2. Eingabemodus: in diesem Mode wird der Text eingegeben bzw. erfasst
  3. der "Last Line" - Kommandozeilen Modus: Zum Speichern, Beenden und komplexere Funktionen z.B. Suchen und Ersetzen

Wechsel zwischen den Modi

Input-Mode --- [ESC] ---> Edit-Mode -- : --> Last-Line-Mode
Input-Mode <-- i oder a -- Edit-Mode <-- [RETURN] -- Last-Line

Beim Aufruf von vi test.txt wird die Datei test.txt (sofern vorhanden) geöffnet und VI geht in den Edit-Mode.
Durch Eingeben von :q[RETURN] wird in den Kommandozeilen-Mode gewechselt VI beendet.
Im Edit-Mode werden die eingebenen Zeichen als Steuerzeichen interpretiert. Um Text schreiben zu können, muss man zunächst mittels i oder a in den Input-Mode wechseln. Im Input-Mode werden alle Zeichen als Text erfasst. Durch Dücken der Escape-Taste wird der Input-Mode beendet und man befindet sich wieder im Edit-Modus.

VI ist ein sehr mächtiger Editor mit ca. 200 Funktionen. Viele Tasten sind mehrfach belegt. So unterscheidet VI z.B. zwischen (Klein) o = Einfügen einer Zeile nach der aktuellen Zeile und (Groß) O = Einfügen vor aktueller Zeile. VI stammt eben aus der Zeit, als es kaum Alternativen zum Erstellen von Programm-Code gab. Heute verwendet man dazu meist Editoren auf der GUI wie z.B. Kate oder Geany, die auch syntaktische Prüfungen durchführen können oder die Code-Syntax farblich darstellen. VI ist und bleibt für die Shell der standard Editor.

Auch der Linux Page Reader "less" verwendet die Syntax der VI-Kommandos. Hier kann man sich mit VI-Kenntnissen leichter bewegen und Textstellen suchen.



VI - die Grundfunktionen

Für das "Gelegenheits-Editieren" z.B. zur Administration von Rechnern kommt man mit nachfolgenden, wenigen VI-Funktionen ganz gut aus.

Funktionen zum Speichern und Beenden von VI sind "Last Line"-Kommandos

TasteFunktion
:
Doppelpunkt im Edit Fenster startet den Last-Line-Mode
qQuitVI verlassen
q!QuitVI ohne Speichern verlassen/Verlassen erzwingen
wWriteDatei speichern
wqWrite & QuitZusammenhängen von w und q
/mustersuchesuche nach muster vorwärts
?mustersuchesuche nach muster rückwärts
nnextwiederhole letzte Suche

VI prüft vor dem Beenden, ob der Text verändert wurde und gibt eine entsprechende Warnung aus. Hat man eine Datei ohne Schreibberechtigung aufgerufen, oder möchte man die Änderungen verwerfen ohne zu speichern, so muss VI mit q! verlassen werden. Anderenfalls läßt sich VI nur nach vorherigem Speichern mit q beenden. Eine Alternative für :wq ist die Eingabe von ZZ.

Bewegen und Löschen im Edit-Modus
Bei den meisten Linux Systeme funktioniern die Cursor-Steuertasten einwandfrei. Falls das mal nicht der Fall sein sollte, kann man sich auch anders durch den Text bewegen.

FunktionZeichenWortZeileDatei
vorwärtslwjL
rückwärtshbkH
löschenxdwdd

TasteFunktion
0NULLGehe zum Zeilenanfang
$Zeilenendegehe ans Ende der Zeile
HHomegehe zum Anfang der Datei
LLastgehe zum Ende der Datei
12GGotogehe zu Zeile 12 der Datei (ohne Zahl = letzte Zeile)

Wechsel in den Input Mode:
TasteFunktion
iinsertText vor dem Cursor einfügen
IInsertText am Zeilenanfang einfügen
aappendText nach dem Cursor einfügen
AAppendText am Zeilenende anhängen
oopenLeerzeile/Text nach aktueller Zeile einfügen
OOpenLeerzeile/Text vor aktueller Zeile einfügen

Im Input-Mode werden Zeichen eingefügt (nicht überschrieben). Der Input-Mode wird mit Escape verlassen. Falls die Cursor-Tasten nicht oder schlecht implementiert sind, lösen sie u.U. Escape-Sequenzen aus, die VI veranlassen den Input-Mode zu beenden.


Spezielle Funktionen:
TasteFunktion
. wiederholt letztes Änderungskommando
uundomacht die letzte Änderung rückgängig
xx-enZeichen löschen (aus-X-en von Text)
rnreplaceErsetzt aktuelles Zeichen mit Zeichen n
xp tauscht aktuelles mit nachfolgendem Zeichen
JJoinhängt die nächste an die aktuelle Zeile an
löscht [Return] der aktuellen Zeile

Fast alle VI Funktionen können durch Voranstellen einer Zahl mehrfach ausgeführt werden. So löscht beispielsweise 12dd zwölf Zeilen ab der aktuellen Zeile.

Mit den oben aufgeführten Funktionen und dem Verständnis der drei Modi von VI lässt sich VI schon recht gut bedienen und produktiv einsetzen.




VI - mehr Funktionen

Wer mehr als nur gelegentlich mal eine Config-Datei editieren möchte, wird zusätzliche Funktionen benötigen: wie. z.B. Cut'n'Paste, suchen + ersetzen und Text überschreiben.
Die nachfolgenden Tabellen erheben keinen Anspruch auf Vollständigkeit. Sie sind entsprechend in "Funktionsgruppen" gegliedert. Fast alle VI-Kommandos können durch voranstellen einer Zahl entsprechend häufig ausgeführt werden. So ersetzt beispielsweise 15rx ab dem Cursor 15 Zeichen durch "x" oder 20~ dreht bei den nächsten 20 Buchstaben die Groß- Kleinschreibung um.

Yank und Put

Cut and Paste heißt in der VI-Sprache Yank und Put. Wobei das nicht ganz stimmt, den yank ist ein Copy-Befehl. Durch yy wird die aktuelle Zeile in den allgemeinen Puffer geschrieben. p für Put fügt den Puffer hinter der aktuellen Zeile ein. Das oben schon beschriebene dd Delete funktioniert ähnlich wie Yank, mit dem Unterschied, dass dd die entsprechende Anzahl Zeilen, nach dem Kopieren in den allgemeinen Puffer, löscht. Somit kann man die mit dd gelöschte(n) Zeile(n) an anderer Stelle im Text per p wieder einfügen.

Neben dem allgemeinen Pufffer kennt VI 35 weitere "benannte" Puffer. 26 davon sind über die Buchstaben a...z und 9 über die Ziffern 1...9 zu adressieren. Diese werden über "x[n]yy adressiert, wobei x der Buchstabe oder die Ziffer des Puffes ist und die Option n die Anzahl der zu kopierenden Zeilen ist. Ein vorangestelltes doppeltes Anführungszeichen teilt VI also mit, dass man einen benannten Puffer adressieren möchte.

Delete, Yank und Put in der Übersicht:
TasteFunktion
xlöscht aktuelles Zeichen
Xlöscht Zeichen vor Cursor
dwlöscht Wort
ddlöscht Zeile
d$löscht bis zum Ende der Zeile (alt: D)
d/musterlöscht bis muster
"addlöscht Zeile und speichert sie in Puffer a
ywkopiert Wort
yykopiert Zeile
y$kopiert bis zum Ende der Zeile
"ayykopiert Zeile in Puffer a
pfügt allg. Puffer hinter aktueller Zeile ein
Pfügt allg. Puffer vor aktueller Zeile ein
"apfügt Puffer a hinter aktueller Zeile ein
:r dateifügt datei zwischen aktueller und nächster Zeile ein

Aus der Tabelle kann man sehr schön erkennen, dass sich Funktionen in VI häufig aus anderen Funktionen zusammensetzen. So ist beispielsweise die Funktion xp zum Tauschen zweier hintereinanderliegender Buchstaben um z.B. aus einem "ie" ein "ei" zu machen, nichts anderes als die Funktion x (Löschen eines Zeichens) gefolgt von p (Einfügen hinter Cursor).

Suchen und Ersetzen

Suchen und Ersetzen wird im VI über "Last-Line" oder Doppelpunkt Kommandos durchgeführt. Das einfache Vor- und Rückwärtssuchen ist weiter oben schon aufgeführt. Delete, Yank und Put in der Übersicht:

Suchen:
EingabeFunktion
/mustersucht muster in Datei vorwärts
/muster/nsucht n-tes muster in Datei vorwärts
/muster/+npositioniere Cursor in n-te Zeile hinter muster
/muster/-npositioniere Cursor in n-te Zeile vor muster
?mustersucht muster in Datei rückwärts
nwiederholt letzte Suche
Nwiederholt letzte Suche in umgekehrter Richtung

Suchen und Ersetzen:
EingabeFunktion
s/alt/neuersetzt 1. Vorkommen in aktueller Zeile von alt durch neu
s/alt/neu/gersetzt alle Vorkommen in aktueller Zeile von alt durch neu
1,10s/alt/neu/gersetzt alle Vorkommen in Zeilen 1 bis 10 von alt durch neu
1,$s/alt/neu/gcersetzt alle Vorkommen in Datei von alt durch neu
inkl. Rückfrage. Diese muss mit y oder n beantwortet werden

In einem gut installierten VIM kann man, ähnlich wie bei der Bash, mittels Up- & Down-Cursor-Tasten durch die letzen Kommandos blättern und diese ggf. editieren und wiederholen.


Eingeben/Ändern mit Wechsel in den Input Mode:
TasteFunktion
aappendRechts vom Cursor einfügen
AAppendAm Zeilenende anhängen
iinsertLinks vom Cursor einfügen
IInsertAm zeielanfang einfügen
oopenöffnet neue, leere Zeile nach aktueller Zeile
OOpenöffnet neue, leere Zeile vor aktueller Zeile
ssubstituelöscht aktuelles Zeichen und geht in Input-Mode
SSubstitutelöscht aktuelle Zeile und geht in Input-Mode
RReplaceÜberschreiben einschalten
cwchange wordWort löschen und in den Input Mode wechseln
ccchangewie S - ganze Zeile ersetzen
c$Changeab Cursor den Rest der Zeile ersetzen
CChangewie c$ - ab Cursor den Rest der Zeile ersetzen

Ersetzungen/Änderungen ohne Wechsel in den Input Mode:
TasteFunktion
xaus-X-enZeichen unter Cursor löschen
rxreplaceZeichen unter Cursor durch x ersetzen
~Case changeWechsel von Groß- in Kleinbuchstaben und umgekehrt
JJoinZeilen verbinden
. letztes Änderungskommando wiederholen
uundoletzte Änderung rückgängig machen
:e! alle Änderungen seit dem letzten Speichern verwerfen



VI - Kommandozeilen Parameter

Beim Aufrufen von VI bzw VIM lassen sich einige Parameter gleich mit übergeben. Dies ist keine komplette Übersicht aller Möglichkeiten. Die Beispeile sollen proimär als Anregungen dienen:

EingabeFunktion
vi "+12" test.txtöffnet die Datei test.txt und positioniert Cursor auf Zeile 12
vi "+12" test.txt "+:4sp"öffnet die Datei test.txt in zwei Fenstern, wovon das obere 4 Zeilen hoch ist, den Fokus erhält und auf Zeile 12 positioniert wird.
Wird :sp ohne Zahl angegeben, so werden zwei gleich große Fenster geöffnet.
vi "+:6sp test.dat" test.txtÖffnet zwei Fenster, das obere ist 6 Zeilen hoch, hat den Fokus und enthält die Datei test.dat. Das untere enthält die Datei test.txt.
vi "+'\"" test.txtöffnet test.txt und geht zu der Zeile, in der der Cursor beim letzten Editieren stand.
kann man auch als Alias definieren: alias vi="vim \"+'\\\"\""
vi "+syntax on" "+set number" s.cschaltet beim Öffnen der Datei das Syntax Coloring und die Zeilennummerierung ein

Parameter, die man bei jedem Aufruf von VI verwenden möchte, wie z.B. set number sollte man in die Datei .vimrc im Home Verzeichnis des Users eintragen.

Arbeitet man mit zwei Fenstern gleichzeitig, kann man mit [Strg][w][w] zwischen den beiden Fenstern springen. Beide Fenster kann man durch :qa bzw. :wqa ohne bzw. mit Speichern schließen.



VI und LESS

Wenn man sich mit VI auskennt, kann man auch das Linux-Anzeige Programm less deutlich besser nutzen. Die Funktionen zum Suchen und Positionieren innerhalb der Datei sind identisch.

Mehrnoch! Haben Sie gerade eine Datei mit less zum Anschauen geöffnet und sehen, dass Sie diese editieren möchten, reicht die Eingabe von "v" um die Datei mit dem Editor zu öffnen.
Hier kann Ihnen Ubuntu einen kleinen Streich spielen. Standardmäßig ist in Ubuntu Nano als Editor definiert und wenn man mit VI bzw. Vim fitt ist, empfindet man dies eher als störend. Um Abhilfe zu schaffen, rufen Sie sudo update-alternatives --config editor auf:

user@pc:~$ sudo update-alternatives --config editor

Es gibt 6 Alternativen, die »editor« bereitstellen.

Auswahl Alternative
-----------------------------------------------
1 /bin/ed
+ 2 /bin/nano
3 /usr/bin/mcedit-debian
4 /usr/bin/vim
5 /usr/bin/vim.basic
6 /usr/bin/vim.tiny

Drücken Sie die Eingabetaste, um die Vorgabe[*] beizubehalten,
oder geben Sie die Auswahlnummer ein: 4
Verwende »/usr/bin/vim«, um »editor« bereitzustellen.
user@pc:~$

Falls das nicht funktioniert, können Sie den Link auch manuell ändern: Wechseln Sie dazu als Root nach /etc/alternatives und löschen Sie dort die Links "editor" und "editor.1.gz". Anschließend legen Sie dort neue Links auf Vim an:

ln /usr/bin/vim editor
ln /usr/share/man/man1/vim.1.gz editor.1.gz

Freitag, 11. September 2009

Freie DNS Server

Statt der kompromittierten DNS-Server des Providers kann man unzensierte DNS-Server nutzen. Hier ein Liste von freien DNS-Server IPs:

Chaos Computer Club

  • 194.150.168.168
  • 213.73.91.35
  • 80.237.196.2
  • 194.95.202.198

FoeBuD e.V.

  • 85.214.73.63

Germany Privacy Foundation

  • 87.118.100.175
  • 62.141.58.13
  • 87.118.104.203
  • 85.25.251.254
  • 94.75.228.29

OpenDNS

  • 208.67.222.222
  • 208.67.220.220

OpenNIC

  • 58.6.115.42
  • 58.6.115.43
  • 119.31.230.42
  • 200.252.98.162
  • 217.79.186.148
  • 82.229.244.191
  • 216.87.84.211
  • 66.244.95.20

ValiDOM

  • 78.46.89.147
  • 88.198.75.145

Samstag, 5. September 2009

Systemstart durch Init-V

Direkt nach dem Kernel-Start wird unter Unix das Programm /sbin/init gestartet. Du siehst ihn als ersten Eintrag wenn du ps afx aufrufst. Du kannst dem Init-Prozess schon beim lilo/grub-Start Parameter übergeben, dazu später mehr.
Danach führt Init eine Reihe von Skripten aus, diese starten dann diverse Dienste oder konfigurieren deinen Rechner. Das richtig Interessante sind aber die Runlevels. Mit diesen Runlevels kannst du deinen Rechner in verschiedenen Konfigurationen hochfahren, zum Beispiel mit oder ohne Netzwerk.

Die Runlevels werden mit Nummer belegt, leider hat fast jede Distri eine andere Vorstellung davon. Aber es besteht Hoffnung, und zwar durch die Linux Standart Base, damit versuchen die meisten Distributoren eine einheitlich Basis für Linux zu schaffen.
Also, laut LSB sind die Runlevels so definiert:

0 System anhalten
1 Single User Mode: Nur ein Benutzer kann arbeiten, meistens root. Es sollten nur die wichtigsten Dienste gestartet sein
2 Mulituser, no network: Es können mehrere Benutzer arbeiten, ohne Netzwerk-Exports (NFS) (multiuser with no network services exported)
3 Normal, Multiuser: Normaler Modus
4 Reserviert: normale Benutzung, Multiuser
5 Multiuser mit X-Anmeldung: Es erscheint der X-Server zur Benutzer-Anmeldung
6 Reboot: Rechner wird neugestartet


Deinen aktuellen Runlevel erfährst du als root mit dem Befehl runlevel:

root # runlevel #Der aktuelle Runlevel