Showing posts with label My Linux tips. Show all posts
Showing posts with label My Linux tips. Show all posts

Tuesday, 11 November 2008

Introduction Linux Tips

Ini dia saya sajikan “fresh from the oven” tips n trick linux yang cukup bagus bagi para linuxer newbie seperti saya. Meski Cuma copas dari e-book “Suse Linux - 100 tips and tricks by Patrick Lambert”, tetapi tips-trick ini sudah diseleksi dengan ketat, dijamin berguna dan tokcer. Hebatnya lagi tips dan trick ini masih murni ditulis dengan bahasa Inggris, Kenapa ? Namanya juga copas. Ada sih jawaban lainnya yaitu karena ada statement ini dalam e-book tersebut “ This book is copyright by Patrick Lambert. It is provided free of charge in the hope that it will be useful. You may copy, distribute and print this book. You may not modify it without prior written consent from the author”. Jadi daripada report-report ngontek Bang Patrick, ya mending saya copas saja sebagian tips n trick dalam e-book ini, itung-itung sekalian memenuhi syarat Google Adsenses. Ibaratnya kencing sambil berlari, Hemat waktu dan lega didapat secara bersamaan, meski air seni muncrat kemana-mana. Enjoy it !!

Annoying boot messages

When recompiling your kernel, you might end up seeing strange messages on bootup like:
modprobe: cannot find net-pf-5
modprobe: cannot find char-major-14
These are messages from the modules loader telling you that he can't find specific modules. This usualy happens when you compile modules, but modprobe tries to load modules that were not compiled and it can't find them. The way to remove those messages is to set the modules to off. In the file /etc/conf.modules you may want to add:
alias net-pf-5 off
alias char-major-14 off
This will stop modprobe from trying to load them. Of course you could also try to resove the problem by compiling the modules and make sure modprobe knows where they are.

Reference : Suse Linux - 100 tips and tricks by Patrick Lambert

Who is online?

Many system administrators use scripts to help them in the process of managing a server. A common problem is finding out exactly what users are on the system and what they are doing. Several tools are available on the system to see who is online, what processes are running, and pipeing them together can resolve many problems. Here are 2 small scripts that will show, first if a user is online, and then what he is running:

who | grep $1

ps -aux | grep $1

The variable $1 here means the first command line argument, from a shell script. The who command first checks if the user is online, then ps will show all the processes currently running under that user's UID.

Reference : Suse Linux - 100 tips and tricks by Patrick Lambert

Don't grep grep

A useful tool in scripting is the "grep" function. This program will find a string in a file. It is often used also to find if a process is running:

ps ax | grep sendmail

That command will find if sendmail is running. The problem is that you might end up with an other entry for this command. Because you grep for "sendmail", you may well end up with this command showing because the "sendmail" string is in the command line. To avoid that, you can use the -v flag to grep:

ps ax | grep sendmail | grep -v grep

That command will find all the lines in the current process list that have the "sendmail" string in it, and will remove the lines containing the string "grep".

Reference : Suse Linux - 100 tips and tricks by Patrick Lambert

Who owns this port

Several utilities exist to check which ports are open, who is connected to your system and even what process owns a port number. First a few ground rules. Ports below 1024 are reserved for common services, and only root can use them. Standard port numbers can be found in /etc/services. The maximum number of ports is 65k, so you have more than enough Internet ports for all your services. Here are some useful utilities. Netstat is a command that will list both the open ports and who is connected to your system. You should run it like this:

netstat -an | more

This way you can find out who is connected to which service. Another interesting command is the fuser program. This program can tell you which user and process owns a port. For example, the following command will tell you who owns port 6000:

fuser -v -n tcp 6000

Reference : Suse Linux - 100 tips and tricks by Patrick Lambert

Names and name servers

Internet hostnames and domains are resolved using the Domain Name System (DNS) using Name Servers (NS). These name servers are usually hosted by your Internet provider. You can also host your own name server, using the program named. Every name server, upon receiving a request to resolve a hostname, will ask an upstream name server if it doesn't know the answer. Your name server may ask your ISP's name server, which will ask the backbone's main name server, which will ask a root server. Linux knows which name server to ask by looking in /etc/resolv.conf. In that file, a number of name servers may be specified in the following way:

nameserver 192.168.0.1

nameserver 205.237.65.254

The name server itself, named, has a configuration file which is usually /etc/named.conf. In that file, you configure the domain names you are responsible for, and the zone file to use. A nice introduction to running a name server is available in the various named man pages. Various utilities are related to resolving hostnames. One is called whois, and will query the Internet main name servers to know who owns a domain:

whois linux.org

Another utility is called nslookup. That command will allow you to resolve hosts, and to get all kinds of information about a domain. See the man page for more.

Reference : Suse Linux - 100 tips and tricks by Patrick Lambert

Access to various networks

Big corporations often sub-divide their networks into small networks, hidden behind gateways. To access them, you need to tell your Linux system that there is a gateway to use to access the networks. The route program makes it easy to add networks, hosts and gateways to your routing table. To add a default gateway, for example to access the Internet, you can set it as default with the following line:

route add default gw 10.0.0.1

This will work if you need to access the Internet via the 10.0.0.1 gateway. Now, if you want to access networks 10.1.0.0 and 10.2.0.0 through other gateways, here is what you will want to do:

route add -net 10.1.0.0 gw 10.0.0.10

route add -net 10.2.0.0 gw 10.0.0.20

Reference : Suse Linux - 100 tips and tricks by Patrick Lambert

Display IP rather than hostname

When dealing with networking issues, it often helps to be able to use only IP addresses rather than hostnames. Why? For 2 reasons. First, the name server might not always be available if routing is being changed. And most important, you may not have the time to wait for all the IP resolving to be done. Fortunately, many networking utilities in Linux share a common option flag. The -n flag. It will allow you to make the utility display IP addresses rather than hostnames. Here are a few examples:

netstat -an

traceroute 1.2.3.4 -n

arp -n -a -i eth0 -a proxy

These commands were all given the -n flag and will display only IP addresses.

Reference : Suse Linux - 100 tips and tricks by Patrick Lambert

Domains to search in

When you try to access a Web site, or any remote site, you need to specify the full hostname. This means the machine name plus the domain name:

lynx my.yahoo.com

If you have a few domain names that you access a lot, you can make your life easier. You can edit /etc/resolv.conf and add the domains there:

search domain.net yahoo.com

This means that the system will search in those domains for hostnames. From now on type:

lynx my

The system will now look for "my", if that hostname doesn't exist it will look for "my.domain.net", and at last "my.yahoo.com".

Reference : Suse Linux - 100 tips and tricks by Patrick Lambert

Find files

Find is a very useful and powerful utility. It is often used by system administration and in shell scripts. Here are 2 commands that might be useful:

find / -perm -4000 -print

This command will find every file on the system that is suid. This means that when you run it you will be running it as an other user. For example, traceroute is a utility that needs to be run as root. To allow users to run it, systems administrators will set it suid root so it will be run as root even if a user starts it. This can be useful, but can also be a big security risk if the utility has a security hole in it. Here is another interesting command:

find / -atime +10 -print

This command will find all the files accessed more than 10 days ago. Commands like this one can be useful to find old files that need to be backuped or erased.

Reference : Suse Linux - 100 tips and tricks by Patrick Lambert

Hard to erase files

File names in Linux can have many letters and numbers in them. Usualy, names should not have spaces in them, although Linux can deal with them. There are some characters that should not be used in files, like "/" and "~". Some programs unfortunately will create strange looking file names, often as temporary files. Using the rm command, you should be able to remove them, but it may be hard when strange alphanumeric characters are used. Here are a few ways you should try to get rid of a file with a strange name:

* First you should try the following:

rm -f "file name"

* If this doesn't work you should try the console program mc.

* With graphical file managers, you should be able to pick an icon and remove it, regardless of

the file name.

Reference : Suse Linux - 100 tips and tricks by Patrick Lambert

by TemplatesForYouTFY
SoSuechtig