Linux Imp
Linux Imp
COMMANDS:
_____________
# chkconfig <service> on
# chkconfig telnet on - it will 'on' the 'telnet' service if 'off'.
# for i in 'seq 5'; do seq 10000 > file$i.txt; done - it will create 5 files
at a time named file1.txt to file5.txt
with 10000 nos. entries in each.
(this command not successfull running)
# netstat -ntl | grep <service> --to chk tcp/udp ports for given service
USER MANAGEMENT:
_______________
# /etc/password
# /etc/shadow > both files contain user related info.
7- # chage -l <user name> -this command will display the password policies
of the given user (use #chage --help)
8- # chage <user name> -to set the passoword policy for given user
9- # groupadd <group name> - command used to create a new group.
10- # groupdel <group name> - command used to delete a group.
11- # groupmod <group name> - command used to modify a group . (#groupmod
--help)
SUDO USER:
__________
TASK:
Set an user as a 'sudo user' with authority of creating user with password.
#Command Aliases
U1 ALL = C1
U1 ALL = C2
TASK:
1- create a new group.
2- add an existing user to the newly created group.
3- chk the task.
------------
(NB: here group1 is newly created group and user1 is an
existing user)
1- # groupadd group1
(# tail /etc/group) -to verify the created group
# id user1
(chk user1 group details before changing it)
NB. use '&&' to run 2 command at the same time (eg. # command1 &&
command2)
# nano <file name> -command used to see existing file in detail view.
(cat like command)
FILE MANAGEMENT:
_________________
# ls -l <file name>
NB. This color pattern may be change, so dont always rely on it.
NB: # head -n 3 <file name> -- will show top 3 lines of given file
# tail -n 3 <file name> -- will show bottom 3 lines of given file
FILE PERMISSIONS:
_________________
Permission value:
eg. # chmod 666 <file name> - this command will assign '4 (read)+ 2
(write)' permission to 'user+group+others
(ugo) on given file.
# chmod o+w <file name> - this command will assign write permission
to others on given file
# chmod o-w <file name> - this command will remove write permission
to others on given file
# chmod g+6 <file name> - this command will assign read(4)+write(2)
permission to grou on given filex
TASK: Other users can edit the files created by user 'james'
#cd /home
#chmod o+rwx james
NB: # id <user name> - this command will show the UID and GID etc. of
given user
SYMBOLIC LINKS:
_______________
(used to link two files togather)
QUOTA MANAGEMENT:
_________________
3- # vi /etc/fstab
output cut--
(/dev/mylvm/lv1 /root/disk1 ext4
defaults,usrquota,grpquota 0 0)
DISK PARTITIONING:
__________________
TOOLS (commands)
a- 'fdisk'
b- 'parted'
c- 'mke2fs' 'ext2,ext3,ext4' filesystems.
d- 'mkfs.ext4'
(# fdisk -l ' run this command to chck the created partition in list)
step7- # mkfs.ext4 /dev/sda4 (to format the partition using 'ext4 file
system, here /dev/sda4 'sda4'is newly created partition' it may be differ)
step8- # mkdir /home/disk4 (create a directory)
step9- # mount /dev/sda4 /home/disk4 (mount the partition on created
directory)
step10-# vi /etc/fstab (enter the details of created partition here)
YUM REPOSITORY:
________________
6- copy 'Package' folder from mounted rhel iso or dvd into '/home/redhat'
folder.
[redhat]
name=yum install (optional)
baseurl=file:///home/redhat (repository location)
gpgcheck=0
1- # fdisk /dev/sda
2- # press 'n' (for new partition)
3- # assign size here '+1G' if 1gb required
4- # press 't' (to assign partition id, for swap use '82')
5- # press 'p' (to print the partition table)
6- # press 'w' (to write the partition, reboot may also required)
7- # mkswap /dev/sda4 (sda4 may be differ, this overlap the swap partition
with existed one)
3- # swapon -v /swapfile1G
4- # swapon -s (to chk the current status. new swap should be
seen here)
NB. u can enter the details of new swap in fstab for permanent entry
5- # vi /ets/fstab
6- # swapon -a
7- # swapon -s
- first you need to create one or more partitions with label '8e'.
- create 'physical volume' from using created partitions.
- create 'volume groupe' it can have one or more partitions.
- create 'logical volume' from 'physical volume' as much size as you wish.
- format the 'logical volume' with ext4 filesystem.
- create a directory and mount it.
- enter the detalis in '/etc/fstab' file for permanent mounting.
NB. (for example you have created two partitions '/dev/sdb2 nd
/dev/sdb3' with partition label '8e')
RESIZING/EXTENDING LVM:
_______________________
- now you can extend the size of 'logical volume' using 'lvextend'
command.
REMOVING LVM:
_____________
- delete or hide the 'lvm' entry from '/etc/fstab' file.
- umount the 'logical volume' from directory
# lvremove /dev/vg01/lv01
# lvdisplay
# vgremove /dev/vg01
# vgdisplay
7- # df-h or df-h /raid0 or df -h /dev/md0 (to chk the space used by raid0,
here both partitions will be one/combined)
(both partition will be merged, becoz
raid0 work like a LVM)
RAID-1 (MIRRORING):
7- # df-h or df-h /raid1 or df -h /dev/md1 (to chk the space used by raid1,
here half partition size will be seen)
(only single partition size will be seen,
becoz other partitios is used for
mirroring)
2- # mdadm --stop /dev/md0 (to stop the configured raid, here 'md0' for
raid 0, for raid1, used 'md1' and so on)
# at <time>
# at 23:15 <press 'enter'>
at> cd /saif && touch at.txt - to create a blank file in '/saif'
direcctory with name 'at.txt' , at 23:15 (11:15)
at> <press 'ctrl+d'> - to save, and end the task
# batch
at> mkdir atdir
at> touch pp.txt
at> cp pp.txt atdir
<press 'ctrl+d'>
# batch
at> touch ping.txt
at> ping -c 4 192.168.136.128 >> ping.txt
at> cp ping.txt atdir
<press 'ctrl+d'>
-- here a blank file named 'ping.txt' will b created, system
will ping (4 times) to given IP add,
result will be redirected to 'ping.txt' file, and this file
will b copied into 'atidir' directory.
# rpm -qa | grep cron - to verify that 'cron' packages are installed
or not.
-Telnet
-SSH
# ssh [email protected]
-Traceroute
-Netstat
(used to reveals TCP/UDP sockets)
-arp
IP-V4 CONFIGURATIONS:
____________________
- DHCP
- STATIC IP
- VIRTUAL/SUB INTERFACES
KEY DIRECTORIES--
# cd /etc/sysconfig/network-scripts/
2- # ifconfig eth0:1 10.10.10.1 netmask 255.255.255.0 - it will create
(temporarily) a sub-interface of eth0 'eth0:1'
with given ip add.
3- # cd /etc/sysconfig/network-scripts/
4- # cp -v /etc/sysconfig/network-scripts/ifcfg-eth0 ifcfg-eth0:1
5- # vi /etc/sysconfig/network-scripts/ifcfg-eth0:1
8- # ethtool <interfacae>
# ethtool eth0 -- show imp. info regarding interface eg. duplex,
speed, port type etc.
IPV6 COMFIGURATION:
__________________
-Self-configuration.
-Can be configure via 'neighbor discovery auto-config by a
router, via DHcpv6, or manually.
Trying ::1...
ftp: connect to address ::1Connection refused
Trying 127.0.0.1...
Connected to localhost (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (localhost:saif): anonymous - type here 'anonymous'
NB. (You can also login via any 'user' except 'root', login process is
same as above, use '<user name>'
and its 'password')
ftp> !pwd
ftp> !ls -l
# vi /etc/vsftpd/vsftpd.conf
-now 'anonymous login will be denied, but local 'user' login is enables (by
default), login via 'local users' only.
-chk 'selinex' setting to solve the issue for 'ftp home dir'.
# sestatus -command to know the 'selinux' status, enforcing or disabled.
LFTP:
____
(lftp package need to download)
or
or
[saif@server ~]$ lftp <remote ip>
lftp 192.168.136.130:~> open -u <remote user> 192.168.136.130
NB.(if connection established sucessfully, this obove output will get, when
running 'netstat -ant | grep ftp or 21')
TASK-1: You want that a user named 'ftpuser01' (created on ftp server), is
only user to login via ftp/lftp locally/remotely.
rest all users (including 'root') not allowed to login via ftp/lftp
locally or remotely.
TASK:
Define primary zone for: 'example.com' FQDN is 'server1.example.com'
IP DNS server is: 192.168.10.100
# system-config-network
--dns configuration
--hostname: server1.example.com
--primaary dns: 192.168.10.100
# vi /etc/hosts
192.168.10.100 server1.example.com
# vi /etc/resolve.conf
search example.com
nameserver 192.168.10.100
# vi /etc/sysconfig/network
networking=yes
hostname=server1.example.com
zone "1.0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "example.com" IN {
type master; --------------------- 'master' this indicates that this is a
primary zone.
file "example.com";
allow-update { none; };
};
-------
-------
-------
zone "example.com" IN {
type master;
file "example.com";
allow-update { none; };
};
3- # cd /var/named/
5- # vi expample.com
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
$TTL 1D
@ IN NS server1.example.com.
server1 IN A 192.168.10.100
--- save the file
' ps -ef | grep -i named -- chk the 'named' process is running or not
6- # cd /var/named/ && ll
8- # cd /var/named/
' tail data/named.run' -- run this command here, it will show that
zones creation is sucessfully done or failed.
# tail data/named.run
exiting
zone 0.in-addr.arpa/IN: loaded serial 0
zone 1.0.0.127.in-addr.arpa/IN: loaded serial 0
zone
1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa/IN: loaded
serial 0
zone example.com/IN: loaded serial 25042020
zone localhost.localdomain/IN: loaded serial 0
zone localhost/IN: loaded serial 0
managed-keys-zone ./IN: loaded serial 13
running
zone example.com/IN: sending notifies (serial 25042020) -- here 'example.com'
sending notifications.
' dig @localhost server1.example.com' -- to trace the dns
configurations.
;; QUESTION SECTION:
;server1.example.com. IN A
ANSWER SECTION:
server1.example.com. 86400 IN A 192.168.10.100
;; AUTHORITY SECTION:
example.com. 86400 IN NS server1.example.com.
-- # vi /etc/named.conf
options {
listen-on port 53 { 127.0.0.1; }; ----- here add ip
'192.168.10.100'
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { localhost; }; --------------------------------
here set 'localhost' to 'any'
recursion yes;
TASKS:
# nslookup www.example.com
Server: ::1
Address: ::1#53
9- # vi /var/named/example.com
$TTL 1D
@ IN NS server1.example.com.
# cd /var/named/
' tail data/named.run' -- run this command here, it will show that
applied changes are sucessfully done or failed.
# nslookup www.example.com
Server: ::1
Address: ::1#53
-- # vi /etc/named.conf
options {
listen-on port 53 { 127.0.0.1; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { localhost; };
recursion yes;
options {
listen-on port 53 { 192.168.10.100; }; -- eneter server ip add here.
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; }; ------------------------------ allow
query for any one.
recursion yes;
TASK:
-- creating a reverse zone for server 192.168.10.100.
1- # vi /etc/named.rfc1912.zones
zone "1.0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
2- # vi /etc/named.conf
include "/etc/named.rfc1912.zones";
zone "example.com" IN {
type master;
file "example.com";
allow-update { none; };
};
zone "1.0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "10.168.192.in-addr.arpa" IN {
type master;
file "192.168.10.zone";
allow-update { none; };
};
3- # cd /var/named && ll
5- # vi 192.168.10.zone
$TTL 1D
@ IN SOA server1.example.com. dns-admin.example.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
10.168.192.in-addr-arpa. IN NS server1.example.com
20 IN PTR server1.example.com.
' tail data/named.run' -- run this command here, it will show that
zones creation is sucessfully done or failed.
TASK:
1- # cp -v /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
4- # chkconfig dhcpd on
# chkconfig nfs on
TASK:
1- # vi /etc/exports
(write here....)
/projectx *(rw) ---this dir will b available for export, to (*) 'all'
in (rw) 'read/write' mode.
-'save it'
3- # cat /etc/exports
5- # showmount server1
# mount
# ls -dl /projectx/
drwxr-xr-x. 2 root root 4096 May 2 22:31 /projectx/ --assign full
permission to 'root' as group also,
otherwise clint can't upload data
in '/projectx' directory
# ls -dl /projectx/
drwxrwxrwx. 2 root root 4096 May 2 22:31 /projectx/
CLIENT END:
--install 'nfs-utils' package if not installed
# mount --to chk the currint mount position, 'projectx' should be mounted
and seen here.
# showmount -e <server name or ip>
# showmount -e server1.example.com
/projectx *
# mount
# df -h
# seq 1000 > projectx/nfs.txt --it will upload file named 'nfs.txt' in
'/projectx' directory, chk it on server.
SAMBA CLIENT:
_____________
(Used for file sahring with Windows envoirement)
5- it will be connected, use 'help' command to see list the usage commands
6- get <filename> - to get/download any file from windows (also can use
'mget')
7- put <filename> - to put/upload any file from linux to windows (can use
also 'mput')