Red Hat commands and tips (Part1)
There are many commands on Linux and many different ways of doing things.
There are some commands which are important to know and ways of piping them to give you a best result.
I am going to cover some commands which I find interesting and how to best use them.
I would like to point out that some of these commands you will be able to use in any distro, but some are Red Hat/Centos/Fedore specific.
Check which services are enables on runlevel 3
[root@centos63 ~]# chkconfig --list | grep 3:on
auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ip6tables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Check services on runlevel 3, output process name and runlevel 3
[root@centos63 ~]# chkconfig --list | grep 3:on | awk '{print $1,$5}'
auditd 3:on
crond 3:on
ip6tables 3:on
iptables 3:on
lvm2-monitor 3:on
Disable service (smb - samba) from runlevel 3
[root@centos63 ~]# chkconfig --level 3 smb off
Enable service to start on runlevel 3
[root@centos63 ~]# chkconfig --level 3 smb on
Start, Stop and re-start services
[Start]
[root@centos63 ~]# service smb start
Starting SMB services: [ OK ]
[Stop]
[root@centos63 ~]# service smb stop
Shutting down SMB services: [ OK ]
[Re-start]
[root@centos63 ~]# service smb restart
Shutting down SMB services: [ OK ]
Starting SMB services: [ OK ]
Find the IP addresses of your Linux server (only IPs)
[root@centos63 ~]#ifconfig | grep "inet addr" | awk '{print $2}' | cut -d : -f 2
192.168.1.34
127.0.0.1
How to bring eth0 interface down
[root@centos63 ~]# ifdown eth0
Note: Be careful if you are logged via SSH, it will drop the connection.
How to bring eth0 interface up
[root@centos63 ~]# ifup eth0
How to set a default Gateway
[root@centos63 ~]# route add default gw 192.168.1.1
How to delete a default gateway
[root@centos63 ~]# route del default gw 192.168.1.1
How to add a static route to netwotk 192.168.3.0/24
[root@centos63~]# route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.1.1
Check File System usage (human readable)
[root@centos63 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
47G 1.1G 44G 3% /
tmpfs 499M 0 499M 0% /dev/shm
/dev/sda1 485M 52M 408M 12% /boot
Check free memory
[root@centos63 ~]# free -m
total used free shared buffers cached
Mem: 996 121 875 0 7 44
-/+ buffers/cache: 69 927
Swap: 2015 0 2015
Check all running processes
[root@centos63 ~]# ps -eaf
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 20:40 ? 00:00:01 /sbin/init
root 2 0 0 20:40 ? 00:00:00 [kthreadd]
root 3 2 0 20:40 ? 00:00:00 [migration/0]
root 4 2 0 20:40 ? 00:00:00 [ksoftirqd/0]
root 1207 1054 0 21:53 ? 00:00:00 sshd: root@pts/0
root 1209 1207 0 21:54 pts/0 00:00:00 -bash
root 1288 1 0 22:09 ? 00:00:00 smbd -D
root 1290 1288 0 22:10 ? 00:00:00 smbd -D
root 1373 1163 0 22:20 tty1 00:00:00 -bash
postfix 1447 1131 0 22:20 ? 00:00:00 pickup -l -t fifo -u
Check if specific process is running
[root@centos63 ~]# ps -eaf | grep smb
root 1288 1 0 22:09 ? 00:00:00 smbd -D
root 1290 1288 0 22:10 ? 00:00:00 smbd -D
root 1461 1209 0 22:31 pts/0 00:00:00 grep smb
Check all open TCP ports on your Server
[root@centos63 ~]# netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 52 192.168.1.34:22 192.168.1.33:55348 ESTABLISHED
tcp 0 0 :::139 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 :::445 :::* LISTEN
There are many very useful commands, these a just some of the commands and combinations I use.
If you found this useful, let me know and I will write some more useful commands to share with you.
Hope you have enjoyed.
by Renato de Oliveira
Tomorrow I will be writing a post on how DNS works. There are many sysadmins whom don't know how this great system works.
ReplyDelete