Wednesday, February 29, 2012

Linux administration and Networking commands

Here are some of the basic linux administration and networking commands. These commands are often used by system admins in day to day work. I hope this post will be helpful for some of the admins.


df
Display filesystem information
Most common use: df -h

du
Display usage
Most common use, under a specific directory: du -a
Easily and quickly identify the size of files/programs in certain directories. A word of caution is that you should not run this command from the / directory. It will actually display size for every file on the entire Linux harddisk.

find
Find locations of files/directories quickly across entire filesystem
Most common use: find / -name appname -type d -xdev

You may also try the commands: locate
or try slocate


ifconfig
Command line tool to configure or check all network cards/interfaces
Most common uses: ifconfig and also ifconfig eth0 10.1.1.1
Using the plain ifconfig command will show you the details of all the already configured network cards or interfaces. This is a great way to get a check that your network hardware is working properly.


netstat
Summary of network connections and status of sockets
Most common uses: netstat and also netstat |head and also netstat -r
Netstat command simply displays all sockets and server connections. The top few lines are usually most helpful regarding webserver administration. Therefore if you are doing basic webserver work, you can quickly read the top lines of the netstat output by including the |head (pipe and head commands). Using the -r option gives you a very good look at the network routing addresses. This is directly linked to the route command.


nslookup
Checks the domain name and IP information of a server
Most common use: nslookup www.hostname.com
You are bound to need this command for one reason or another. When performing server installation and configuration this command gives you the existing root server IP and DNS information and can also provide details from other remote servers. Therefore, it is also a very useful security command where you can lookup DNS information regarding a particular host IP that you may see showing up on your server access logs


ping
Sends test packets to a specified server to check if it is responding properly
Most common use: ping 10.0.0.0 (replace the 10.0.0.0 with a true IP address)
This is an extremely useful command that is necessary to test network connectivity and response of servers. It creates a series of test packets of data that are then bounced to the server and back giving an indication whether the server is operating properly.


ps
Lists all existing processes on the server
Most common uses: ps and also ps -A |more
The simple command will list every process associated with the specific user running on the server. This is helpful in case you run into problems and need to for instance kill a particular process that is stuck in memory.


rm
Removes/deletes directories and files
Most common use: rm -r name (replace name with your file or directory name)
The -r option forces the command to also apply to each subdirectory within the directory. This will work for even non-empty directories.


route
Lists the routing tables for your server
Most common use: route -v
This is pretty much the exact same output as the command netstat -r. You can suit yourself which you prefer to run.


sudo
The super-user do command that allows you to run specific commands that require root access.
Most common use: sudo command (replace command with your specific one)
This command is useful when you are logged into a server and attempt a command that requires super-user or root privileges. In most cases, you can simply run the command through sudo, without having to log in as root. In fact, this is a very beneficial way to administer your server without daily use of the root login, which is potentially dangerous.  


top
Displays many system statistics and details regarding active processes
Most common use: top
This is a very useful system administrator tool that basically gives you a summary view of the system including number of users, memory usage, CPU usage, and active processes.
  
touch
Allows you to change the timestamp on a file.
Most common use: touch filename
Using the basic touch command, as above, will simply force the current date and time upon the specified file. This is helpful, but not often used. 


traceroute
Traces the existing network routing for a remote or local server
Most common use: traceroute hostname
(replace hostname with the name of your server such as reallylinux.com)
This is a very powerful network command that basically gives the exact route between your machine and a server. In some cases you can actually watch the network hops from country to country across an ocean, through data centers, etc.


w
An extension of the who command that displays details of all users currently on the server
Most common uses: w
This is a very important system admin tool I use commonly to track who is on the server and what processes they are running. It is obviously most useful when run as a superuser.


who
Tool used to monitor who is on the system and many other server related characteristics
Most common uses: who and also who -q and also who -b
The plain command just lists the names of users currently on the server. Using the -q option allows you to quickly view just the total number of users on the system. Using the -b option reminds you how long it has been since you rebooted that stable Linux server! 


kill
This command is used to kill a running process on the server. You need to process id to execute the kill command. Consider you run " pstree -p " which will list all the process with its respective process id. To kill a particular process use the command " kill ".




1 comment:

  1. Hi Admin,
    Actually i wants to get my career foundation on Linux so i have planned to take Linux Administration Training in Chennai and got certification also, now am searching a blog related to linux, i had more useful info's in your post, keep sharing your updates relevant to linux for helping the beginner like me.

    ReplyDelete