Home
GUI to CLI: Ctrl + Alt + F6 CLI to GUI: Ctrl + Alt + F1
Show Linux Version
[a] uname - Print kernel and system information.
$ uname -r
$ uname -mrs
$ uname -a
cat /etc/*-release
# cat /etc/centos-release
# cat /etc/redhat-release
[b] lsb_release - Print distribution-specific information.
$ lsb_release -a
[c] /proc/version file - Print running kernel information
$ cat /proc/version
$ cat /etc/*release
OR
$ lsb_release -a
[root@ns1 ~]# vim /etc/bashrc
# /etc/bashrc
alias c='clear'
alias p='poweroff -f'
alias r='reboot'
cal
:x
-----------------------CentOS/Redhat 6+ ------------------------------------
LAN
[root@mail network-scripts]# vi ifcfg-eth0
DEVICE=eth0
HWADDR=6c:3b:e5:32:59:90
TYPE=Ethernet
UUID=32c5553f-07e0-4784-988a-9404813380a4
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
USERCTL=no
IPV6INIT=no
IPADDR=192.168.19.254
NETMASK=255.255.255.0
-------
WAN
[root@mail network-scripts]# vi ifcfg-eth1
DEVICE=eth1
HWADDR=cc:b2:55:ba:c0:66
TYPE=Ethernet
UUID=cd57fc3a-9623-49d5-8778-2c0f6b42c893
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPV6INIT=no
USERCTL=no
IPADDR=203.82.197.42
NETMASK=255.255.255.248
DNS2=202.22.200.44
GATEWAY=203.82.197.41
DNS1=102.22.192.9
Enable/Disable an Network Interface
[root@mail ~]# ifconfig eth0 up
OR
[root@mail ~]# ifup eth0
[root@mail ~]# ifconfig eth0 down
OR
[root@mail ~]# ifdown eth0
# service network restart
LAN/WAN
#mii-tool [ show Conned LAN]
#yum install iptraf
#iptraf [ Lan Traffic]
--------------------------------------------------------------------------------
RPM INSTALL
## rpm -qa sendmail* rpm-qa netconfig
FOR vim
vim-common
vim-enhanced
vim-minimal
vim-X11
------------------------------
HOST NAME
#hostname ns1
crl+D
#vim /etc/sysconfig/network
network=yes
hostname=ns1.pcs.bd
# vi /etc/resolve.conf
nameserver 103.20.140.18
nameserver 202.22.200.44
Check and Configure the Network Card:
[root@ns1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
#Broadcom Corporation Net link BCM57875 Gigabyte Ethernet PCI Express
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0C:29: EB: B2: CA
ONBOOT=yes
TYPE=Ethernet
PEERDNS=no
USERCTL=no
IPV6INIT=no
IPADDR=192.168.20.1
NETMASK=255.255.255.0
NETWORK=192.168.20.0
BROADCAST=192.168.20.255
After changing you have to reload/restart the NIC(eth0) card by following command:
[root@ns1 ~]# ifdown eth0
[root@ns1 ~]# ifup eth0
[root@ns1 ~]# service network restart
After complete the NIC configure you have to change the host name by following this command:
[root@ns1 ~]# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=ns1
Now Edit hosts file for host name resolution by following this command:
[root@ns1 ~]# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
210.207.201.1 ns1.worldcm.com ns1
VIM-Text EDIT
set nu [ Line number ]
15 shift g: 15th line
1 shift g: 1st line
shift g: last line
Copy
yy = 1 Line copy
5yy = 5 line copied
Past
p = past
u = undo
ctl+r = redo
Delete
dd = 1 line delete
3dd = 3 line delete
dw= 1 word delete
Search
/(key word)
/n = next
/N = previous
Replace
%s/world.bd/pcs.bd/g
------------------------------------------------------------------------------------
Remote Copy
scp -r root@203.82.196.18:/etc/postfix /root/f/ [ Remote linux pc ]
scp -r root@203.82.196.18:/etc/postfix/*.* /root/f/ [ Remote linux pc ]
D:\>pscp.exe C:\Users\Administrator\Desktop\tINKERBWL.txt root@192.168.80.77:/root/f [windows to Linux]
D:\>pscp.exe -r root@192.168.80.77:/root/f C:\Users\Administrator\Desktop\ [Linux to windows]
Download pscp.exe: http://the.earth.li/~sgtatham/putty/latest/x86/pscp.exe
cd /f/postfix [Local pc]
cp -r * /etc/postfix
TAR/ZIP
VMwareTools-9.9.0.2304977.tar.gz
$ cd ~/Desktop/
$ tar -xvf VMwareTools [TAB]
$ cd vmware-tools [TAB]
$ ls
$ ./vmware-install.pl
$ ls /mnt/hgfs
$ share folder [ show share folder]
$ ln -s /mnt/hgfs/share folder/ ~/Desktop/share folder [create Desktop shortcut]
----------------------------------------------------
ZIP
# zip -r archive_name.zip directory_to_compress
# unzip archive_name.zip
TAR
# tar -cvf archive_name.tar directory_to_compress
# tar -xvf archive_name.tar.gz
# tar -xvf archive_name.tar -C /tmp/extract_here/
TAR.GZ
# tar -zcvf archive_name.tar.gz directory_to_compress
# tar -zxvf archive_name.tar.gz
# tar -zxvf archive_name.tar.gz -C /tmp/extract_here/
TAR.BZ2
# tar -jcvf archive_name.tar.bz2 directory_to_compress
# tar -jxvf archive_name.tar.bz2 -C /tmp/extract_here/
Creat tar file
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
tar -cvf output.tar /dirname
tar -cvf name.tar /path/to/directory
tar -tvf /tmp/data.tar
tar -cvf /tmp/data.tar /home/vivek/data
tar -cvf output.tar /dirname1 /dirname2 filename1 filename2
-------------------------
oracle.ZIP
# unzip file name
# ls
# pwd [present directory]
# whoami [ show user]
# exit
$ cd /uo1/soft/database/
$ ./runinstaller
RPM
#rpm -ivh vsftpd [ install RPM]
# rpm -qa vsftpd [ Quiary RPM]
# cd /
# ls
# cd media/RHEL_6.0[TAB]\i386\Disk\1/Packages/
# ls | less [ page view]
# rpm -i vsftp [TAB]
# service vsftpd restart
# rpm -qa vsftpd
# rpm -qa | grep -i vsftpd [You should then find the exact package name]
# rpm - e vsftpd [RPM remove]
#rpm -ev webmin
# yum remove vsftpd [RPM remove]
CD Copy
# cp -ivr /media/RHEL_6.0[TAB]\i386\Disk\1/* /var/ftp/pub/
# cp -r /etc/postfix /root/f
Time Set
/etc/sysconfig/clock
mv /etc/localtime /etc/localtime.bak
cp /usr/share/zoneinfo/Asia/Dhaka /etc/localtime
Example 2: set time zone to UTC
cp /usr/share/zoneinfo/UTC /etc/localtime
OR
ln -s /usr/share/zoneinfo/Asia/Dhaka /etc/localtime
#killall -9 mysqld
wget Command
Resume Partial Downloaded File: There are some scenarios where we start downloading a large file but in the middle Internet got disconnected , so using the option ‘-c’ in wget command we can resume our download from where it got disconnected.
# wget -c http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
Limiting Download Speed :
# wget --limit-rate=100k http://mirror.nbrc.ac.in/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
Red hat Linux Essential Commands
Login process as a root user:
ns1 login: root
Passwd: redhat
[root@ns1~]#
Or Login process as a normal user:
ns1 login: u1
Passwd: redlinux
# system-configure-user
[u1@ns1~]$
[root@ns1~]# ls [Viewed file/folder]
[root@ns1~]# ls -l
[root@ns1~]# ls -la
[root@ns1~]# ls -l /home
[root@ns1~]# ls -ld /var/named/
[root@ns1~]# cd /var/named [Directory will change]
[root@ns1 named]#
[root@ns1 named]# cd ..
[root@ns1~]# cd /
[root@ns1 /]# cd
[root@ns1~]# cd - [To go previous working directory]
User Create & delete command:
[root@ns1 ~]# useradd u1
Or [root@ns1 ~]# adduser u2
[root@ns1 ~]# userdel -rf u1
Password Change command:
[root@ns1 ~]# passwd [for root user password change]
[root@ns1 ~]# passwd u1 [for normal user password change]
Normal Command used in Linux-------------------------------------------------------------------
[root@ns1 ~]# date [Showing date & time]
[root@ns1 ~]# pwd [Showing present working directory]
[root@ns1 ~]# uname -r [Showing Linux Kernel Version]
[root@ns1 ~]# swichdesk kde [Switching to KDE Desktop if stay install]
Creating a Directory:
[root@ns1 ~]# mkdir soft [Create a directory into /root]
[root@ns1 ~]# mkdir /data [Create a directory into /]
[root@ns1 ~]# mkdir -p /Server/software/Data [Create a directory in between subdirectory]
Creating a file:
[root@ns1 ~]# touch f1 [Create a file into /root]
[root@ns1 ~]# touch /data/f2 [Create a file into /data/]
Remove file and directory:
[root@ns1 ~]# rm -rf soft [Remove file/folder]
[root@ns1 ~]# rm -rf /data/f2
Copy file and folder:
[root@ns1 ~]# cp /data/f2 /root/soft [Copy file/folder]
[root@ns1 ~]# cp /data/f2 /root/soft/f3 [Copy and Rename file/folder]
File/folder Moving and Renaming:
[root@ns1 ~]# mv f1 /data/f4 [Moving and Renaming]
[root@ns1 ~]# mv -r f1 /data/f4
User logout command:
[root@ns1 ~]# logout
[root@ns1 ~]# ctrl+d
[root@ns1 ~]# exit
Computer Shutdown Command:
[root@ns1 ~]# shutdown -h now
[root@ns1 ~]# init 0
[root@ns1 ~]# p [If staying alias]
Computer Reboot Command:
[root@ns1 ~]# reboot
[root@ns1 ~]# init 6
[root@ns1 ~]# r [If staying alias]
[root@ns1 ~]# ctrl+alt+del
User, Group and Permission--------------------------------------------------------------
[root@ns1 ~]# useradd u2 [User Create]
[root@ns1 ~]# passwd u2 [Password Change]
[root@ns1 ~]# groupadd arkgroup [Group Create]
[root@ns1 ~]# useradd u3 -G arkgroup [User Create and insert into a Group
[root@ns1 ~]# gpasswd -M u1,u2 arkgroup [Insert multi User into a Group]
[root@ns1 ~]# cat /etc/passwd [Showing User information]
u1:x:500:500::/home/u1:/bin/bash
/bin/nologon [ Logon inactive]
[root@ns1 ~]# cat /etc/group [Showing Group information]
arkgroup:x:506:u1,u2,u3
[root@ns1 ~]# ls -l
-rw- -wx -w- 1 root root 1468 25 Dec 3:42 soft
Symbol Meaning
0 No Permission (rwx Deny)
1 x Permission (rw Deny)
2 w Permission (Usually not use) (xr Deny)
3 rw Permission (Usually not use) (x Deny)
4 r Permission (wx Deny)
5 rw Permission (Use for folder) (w Deny)
6 wr Permission (x Deny)
7 (All Permission)
user
[root@ns1 ~]# setfacl -m u:u1:rwx /var/test [Folder all permisson]
setfacl -m u:u1:--- /var/test [ No permisson]
setfacl -m u:u1:r-- /var/test [ Red permisson]
Group
[root@ns1 ~]# setfacl -m g:g1:rwx /var/test [Folder all permisson]
'' :--- /var/test [ No permisson]
[root@ns1 ~]# chmod 756 /data [Change Permission for /data folder]
[root@ns1 ~]# chmod 744 /data
[root@ns1 ~]# chmod 777 /data
[root@ns1 ~]# chown u1 /data [Change Owner for /data folder]
[root@ns1 ~]# chown root /data/f1
[root@ns1 ~]# chgrp root /data
[root@ns1 ~]# chgrp u1 /data [Change Group for /data folder]
[root@ns1 ~]# chgrp sysadmin /data/f1
[root@ns1 ~]# ls -ld /data/
drwxr-xr-x 2 root root 4096 Dec 30 19:42 /data/
[root@ns1 ~]# chmod 766 /data
[root@ns1 ~]# ls -ld /data/
drwxrw-rw- 2 root root 4096 Dec 30 19:50 /data/
Mail user
adduser -s /bin/false u1 [u1 only mail user]
Mail ProbleM
#mailq [show Q mail]
#postsuper -d All [mail Q Delete]
#tail -f /var/log/maillog
#cat /var/log/maillog
Log
[root@ns1 ~]#tail -f /var/log/messages
[root@ns1 ~]# tail -f -n /var/log/message
here we will see some files nearly 10 lines
# cd /home/
# cd /var/spool/mail/
#ls
#vi abdullah
Mail Disk space
df -h
du -h --max-depth=1
cd /home/ftpadmin/
#cd /home
#du -h --max-depth=1
#du -h --max-depth=1 | sort
#du -h --max-depth=1 | grep career
#cd /home
#du -h --max-depth=1 | grep career
#du -h --max-depth=1 | grep shadin
#exit
#vi abdullah
#df -h
#du -s
#du -ch
#ls
#cd /home
#ls
#du -ch
#df -h
#du -ah
#du -h
#du
#ntsysv
# system-configure-user
CentOS / Redhat 7 Command..................................................................................................T.
# ip addr show
Configuring Multiple Addresses Using ip Commands
~]# ip address add 192.168.2.223/24 dev eth1
~]# ip address add 192.168.4.223/24 dev eth1
~]# ip addr
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:fb:77:9e brd ff:ff:ff:ff:ff:ff
inet 192.168.2.223/24 scope global eth1
inet 192.168.4.223/24 scope global eth1
#ip route add 192.0.2.0/24 via 10.0.0.1
Static route configuration can be stored per-interface in a /etc/sysconfig/network-scripts/route-interface file. For example, static routes for the eth0 interface would be stored in the /etc/sysconfig/network-scripts/route-eth0 file. The route-interface file has two formats: ip command arguments and network/netmask directives. These are described below.
#systemctl restart network.service
#systemctl start network
#systemctl stop network.service
#sudo systemctl stop network
[root@nagios-server /]# firewall-cmd –permanent –zone=public –add-service=http
[root@nagios-server /]# firewall-cmd –permanent –zone=public –add-service=https
[root@nagios-server /]# firewall-cmd –reload
Setup network on centos 7
# yum install NetworkManager-tui
let’s start, Type “nmcli d” command in your terminal for quick identification of Ethernet cards installed in your machine.
Here we have 2 interfaces named “enp0s17” and “enp0s18” . it might be different in your case ( Eg: em1 or p4p1 ).
GUI Mode
Recommended for beginners
Step 1 » Type this command “nmtui” to open Network manager and press enter after choosing ” Edit a connection” ( Use TAB for choosing options ) .
Step 2 » Now you can see all network interfaces, choose one and click “Edit“.
» DHCP configuration
Step 3 » For DHCP,
1. Choose “Automatic” in IPv4 CONFIGURATION.
2. Choose Automatic Connect check box.
3. Press OK and quit Network manager.
Now Restart network service by typing below command.
systemctl restart network Now your server will get IP Address from DHCP .
» Static configuration
Step 4 » For manual IP address,
1. Choose “Manual” in IPv4 CONFIGURATION.
2. Add IP Address with Subnet , Gateway and DNS server ( Refer below image ).
3. Choose Automatic Connect check box.
4. Press OK and quit Network manager.
Now Restart network service by typing below command.
systemctl restart network That’s it, Interface will have static IP.
Command Mode
Step 1 » Network interface config files are located in /etc/sysconfig/network-scripts/ directory. Open ifcfg-enp0s17 file ( For interface enp0s17 ) and you can see the content like below.
[root@krizna ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s17
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s17
UUID=7f1aff2d-b154-4436-9497-e3a4dedddcef
ONBOOT=no
HWADDR=00:0C:29:A1:B5:D6
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
» DHCP configuration
Step 2 » For DHCP
Find the below lines in config File.
BOOTPROTO=none
ONBOOT=no and replace with
BOOTPROTO=dhcp
ONBOOT=yes Now Restart network service by typing below command.
systemctl restart network Now your server will get IP Address from DHCP
» Static configuration
Step 3 » For Static IP.
Find the below lines in config File.
BOOTPROTO=none
ONBOOT=no and replace with
BOOTPROTO=static
ONBOOT=yes And add the below lines at the end of the file.
IPADDR=172.27.0.32
NETMASK=255.255.255.0
GATEWAY=172.27.0.1
DNS1=172.27.0.5 File will look like below after changes.
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s17
UUID=f0c5b37d-299a-43cb-b74b-618bb252d129
ONBOOT=yes
HWADDR=00:0C:29:A1:B5:CC
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=192.168.1.5
Now Restart network service by typing below command.
systemctl restart network Now Interface will have static IP.
Additionally you can use /etc/sysconfig/network file for hostname and DNS .
HOSTNAME=server.krizna.com
DNS1=192.168.1.5
DNS2=8.8.8.8
SEARCH=krizna.com
restart sshd.service
[root@centos7 ~]# service sshd restart
Redirecting to /bin/systemctl restart sshd.service
Stop service:
systemctl stop httpd
systemctl start httpd
Restart service (stops/starts):
systemctl restart httpd
Reload service (reloads config file):
systemctl reload httpd
List status of service:
systemctl status httpd
chkconfig service on:
systemctl enable httpd
chkconfig service off:
systemctl disable httpd
chkconfig service (is it set up to start?)
systemctl is-enabled httpd
chkconfig –list (shows what is and isn’t enabled)
systemctl list-unit-files --type=service
-------------------------------
http://www.server-world.info/en/