LINUX
LINUX
/etc/fstab => contains mount points '/dev/sda or UUID' <mount point> <type>
<options> <dump (dump command to backup)> <pass (order that fsck checks for error
during boot time)>
- You can mount by using UUID , Label or device
lsblk => disks options
mount => display all system mounts
mount -a => causes all filesystems mentioned in fstab to be mounted as indicated,
except for those whose line contains the noauto keyword.
The use of UUID helps when the disks's naming order changes or disk added and
removed
//samba/share nfs://export user@sshfs:/home/user /mnt/share
- There are 3 ways you can view mounted fs: mount, /etc/mtab, /proc/mounts
- There are virtual fs like cgroug, fuse, proc, selinux and real like / /boot /home
/var
- sync command is used to flush write buffers to disk . Use it before ejecting a
usb
- eject command to eject a removable device under software control
- Vmemory in linux can be disk partition(type 82) or a swap file . Managed with
swapon / swapoff command
- You can format swap fs with mkswap . The swap file can be created with dd or
fallocate command and should be owned by root and be 0600
#fallocate -l 10M /mnt/swap
#mkswap /mnt/swap
#chmod 600 /mnt/swap
#swapon /mnt/swap and add it to fstab file
- free command displays available ram and swap
- fdisk to create partition and wipefs
#btrfs --version
#btrfsck /dev/sdb1
#btrfs fi show -m => list devices
- copy on write is also available in ZFS . It allows instant backups (snapshots).
It may not work well on large files . you can disable it with the attribute
'NoDataCoW' .
#chattr +C /data-btrfs/nocow
#lsattr -d /data-btrfs/nocow
- a btrfs is always a LV and we can easily extend that volume across multiple disks
- Raid levels : Linear uses partitions of different sizes and volume is expanded
across all disks. Spare disks are not supported - Raid 0 ; Raid 1 ; Raid 4/5/6
- Partition type : 0xDA Non FS (recommended) ; OxFD Raid auto
- You can use sfdisk , it can read partitioning instructions from standard input,
so we can dump the partition table from one disk to another .
#fdisk /dev/sdb
#sfdisk -d /dev/sdb | sfdisk --force /dev/sdc
- /proc/mdstat displays the existing raid devices
#mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sdb1
/dev/sdc1
- you can include a host spare by adding --spare-devices=1 /dev/sdd1
#lsmod => Show the status of modules in the Linux Kernel
---------
#cat /proc/mdstat
#lsmod | grep raid
---------
- to persist raid config , save the config in /etc/mdadm.conf file
#mdadm --detail --scan >> /etc/mdadm.conf
#mdadm --stop /dev/md0 => stop the raid
#mdadm --assemble --scan => start the raid
--------------------
#mkfs.btrfs -m raid1 -d raid1 /dev/sdd /dev/sde
- In the lsblk output, maj number represents the type of device and the driver to
be used while the minor number can represents the incrementation
- hdparm (ata) and sdparm(scsi) are used to tune disk performance
#hdparm -tT /dev/sda1
#sdparm (--command=eject) /dev/sda
#sdparm --get=WCE/dev/sda => to see if write cache is enabled
- vm.dirty_background_ration : the % of sys memory that can be filled with dirty
pages before they are written to disk by system bkgrd processes.
- vm.dirty_ratio : max amount of system memory that can be filled with dirty pages
before process itself writes to disk.
#cat /proc/vmstat |grep nr_dirty
#sysctl -a | grep vm.dirty
- The iSCSI target is the server that shares disks or LV n the network.
=============
#vmstat => r: total number processes waiting for CPU time
b: total number blocked processes, waiting for disk or network IO
swpd : used Vmemory
Free : Free Vmemory
Buff : Memory uses as bufers (what's in directories ,permissions)
Cache : Memory used as cache (contents of files)
Si : memory swapped from disk every second
So : " " to disk every second
Bi : Blocks in per second
Bo : Blocks out per second
In : Interrupts per second
Cs : Context switches per second
#vmstat -S M => displays memory usage in Mb
#vmstat -a => display active/inactive memory
---------------------
#free -m ; sync (writes buffers through the disk)
#bash -c "echo 3 > /proc/sys/vm/drop_caches"
---------------------
ls -R / => buffer content
#vmstat 5 3
#uptime [1,5,15min]
#who , w , who -l , who -T (if messaging is on/off)
#mesg / mesg y
#tty => which terminal are you in
#netstat -alt , x (listening socket)
#ps ps-e => all processes runing on system
#pstree
- procps package
COLLECTD
apt install collectd rrdtool
#yum install -y collectd collect-rrdtool rrdtool collectd-web httpd
- /etc/collectd.conf is the config file
- on Centos make sure Apache server is listening on ipv4
- set web permissions in collectd.conf in apache directory by adding "Require ip
<ip> only network bits
BUILDING C PROGRAM
- Sources repo are located in /etc/apt/sources.list
- add deb and deb-src repos
* deb-src http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free
rpi
#apt-get source nmap : obtaining source packages
- Installing software compilation tools : #apt-get install build-essential OR yum
groupinstall "Development Tools"
#./configure = configure script create the makefile instruction set to compile for
your system
#make = looks for makefile and instruction to compile
#sudo make install
- compile C program : #gcc app.c -o out
- To create a patch , copy the source code to a new verison file , edit the new
version file and use diff to compare version and create pacth file.
#diff -u app.c app2.c > app.patch
#patch < app.patch
BACKUP
- with tar there is no compression but you can compress it during or after the
creation.
- tar is used to create on file from one or more directories
#tar -c to create an archive ; -t test ; -x expand or restore
#tar -cv(verbose)f(file) <new> <location> --exclude <file>
#gzip -z to compress ; #gunzip etc.tar.gz to expand
#gzip -1 (lower algorithm) <file>
#bzip2 -j to compress ; #bunzip2 etc.tar.bz2
#rsync -a(archive to maintain permissions)r(recursive)v /home/ /backup to mirror
directories
#rsync -rve ssh /home/ fred@svr1:/backup
- you can configure a rsync server (port 873). to configure it on ubuntu , edit the
file /etc/defult/rsync <RSYNC_ENABLE=true>
and /etc/rsyncd.conf
{ [doc]
path = /usr/share/doc
read only = true
}
#service rsync start
#rsync -av server1::doc/ /data (on client)
- if you stop it during process and start it again ; it will continue . By
default , deletion is not sync ; you can use :
#rsync -av --delete server1::doc/ /data (on client)
- dd can be used to image a disk or partition
#dd if=/dev/cdrom of=/tmp/disk.iso => copy content of cdrom to iso file
#dd if=/dev/sda of=/tmp/sda.mbr count =1 bs=512 => copy one block on a block size
of 512 bytes
- rewinding tape device: /dev/st*
- non-rewinding tape device : /dev/nst*
- utility to control magnetic tapes : /bin/mt
- Backup suites : bacula, amanda, BackupPC
- Bacula components are : Director tcp 9101, Client TCP 9102, Storage 9103.
- It requires a catalog like MySQL, SQLite and PostegreSQL . #apt-get install
bacula
> mysql -u root -p -e "USE bacula; SHOW TABLES;"
-----------------
#mkdir -p -m 700 /bacula/{restore,backup}
#chown -R bacula.bacula /bacula
- on the client , create /bacula/restore directory and on the storage server ,
create /bacula/backup
------------------
- configure the storage server
#/etc/bacula/bacula-sd.conf
<Archive Device = /bacula/backup>
#bacula-sd -tc /etc/bacula/bacula-sd.conf => to test the config
#service bacula-sd restart
------------------
- configure the Director FileSet
#vi /etc/bacula/bacula-dir.conf
<FileSet {
Name= "Full Set"
Include {
Options {
signature = MD5
}
##Backup targets , you can also exclude files in DIR
File = /etc
File = /home
}
##Configure the Director Job
Job {
Name="RestoreFiles"
Type=restore
Client=bacula-server-fd
FileSet="Full Set"
Storage= File
Pool = Default
Messages= Standard
Where= /bacula/restore
}
#bacula-dir -tc /etc/bacula/bacula-dir.conf =>test the config
#service bacula-director restart
------------------
- To start the bacula console , use bconsole
*label = to create a label , enter new volume name and choose 2 for the File pool
*restore all , select 5 for most recent backup
*done to start the restore
*messages = check if everything was successful
- You can also check the fs if everything was successful
- Backup is created on the storage server : /bacula/backup/<label>
- restore is created on the client : /bacula/restore/
NOTIFYING USERS
- the contents of the file /etc/issue are displayed on "physical consoles" prior to
login . Support for escape characters that can be read by agetty getty mingetty ...
- In the file \n displays the nodename as seen from uname -n
- /etc/issue.net is used for remote connections such as SSh but shows after login
and does not support ESC characters
- the content of /etc/motd is displayed on physical consoles and pseudo consoles
after login . it is controlled via the pam_motd module .
- Ubuntu based systems include /etc/update-motd.d that can contains some scripts to
run. other debian systems include /etc/motd.tail
- in /etc/pam.d/sshd , comment the noupdate
- wall is used to send messages to logged in users . All users can use wall but it
more often used by root. Console messaging needs to be turned on if sent by
standard users but not if sent by root . #wall < MessageFile
#mesg n/y
- if you are root is sends the message whether messaging is on or off
- shutdown can include a command to warn users of the impending disaster. If a time
element is usedrather than now , logins are disabled 5 minutes before the shutdown
by /etc/nologin
#shutdown -h +6 "Server is being shutdown"
=====================================
============================
DNS
#aptitude search "?name(^bind)"
- You can use dpkg or rpm to list the package contents .
#dpkg -L bind9
- main config file /etc/bind/named.conf
- /etc/bind/rndc.key is only readable by the bind user . You can control who have
access to the server using this key
#named -v -V
- /var/cache/bind contains the caching files
- zone files are dns information stored in text file . Bind can auto-create entries
with $GENERATE . /etc/bind/db.local /etc/bind/db.127
$GENERATE 10-254 $ PTR dhcp-$.example.com
- a chroot jail can protect against attack. in /etc/default/bind9 , use -t option
to specify chroot jail
- rndc can be used to control the named service or take remote control of a machine
. #rndc-confgen ; uses tcp 953 .
#sudo -u bind rndc status
#sudo -u bind rndc-confgen
#sudo named-checkconf <domain> /etc/bind/db.local
#sudo named-checkzone localhst /etc/bind/db.local
- dns utils provides tools like dig, nslookup.
- the package is bind but the service is named
- /usr/lib/systemd/system/named.service
- Bind modes : caching-only , forwarding , master (rw) , slave (ro) , listen-on ,
allow-query
- yum install dnsmasq
#groupadd -r dnsmasq && useradd -rg dnsmasq dnsmasq
- some options : domain-needed ;bogus-priv ;no-hosts ;dns-forward-max=100 ;cache-
size=500 resolv-file=/etc/resolv.dnsmasq; no-poll
- djbDNS : secure dns
#nslookup
server x
set type= x
google.com
set debug
#dig +short x
#host x
#named-checkzone example.com db.example
#named.checkconf
#named-checkzone 1.168.192.in-addr.arpa db.1.168.192
#named.checkconf -z : check all zone files
- bind user have write access to config and zone files
{$GENERATE 100-150 student-$ IN A 10.0.0.$}
- if the server has two interfaces, you can add two A records, and the server will
return the record in your network. if not in your subnet , it will use round robin.
- do not forget the trailing dot , or the name will be add to the domain name as
FQDN.
- You can replace @ with $ORIGIN value
- if a record starts with a space or tab , then it is interpreted as the last
resource record.
#rndc reload example.com : reload only example zone
- by default logs are sent to messages or syslog files
logging {
channel bind_log {
file "bind.log" versions 3 size 10m;
severity warning;
};
category default {
bind_log;
};
};
- severity: critical error warning notice info debug dynamic
- rndc status can displayed if query logging is on/off
#rndc querylog
#rndc flush
DHCP
----------------
dnsmasq.conf
interface=enp0s8
dhcp-range=192.168.10.50, 192.168.10.150, 12h
dhcp-host= <MAC>, server2.example.com, 192.168.10.12, 24h
-----------------
#apt install -y isc-dhcp-server
#vi /etc/dhcp/dhcp.conf
- global options effect the complete config.
ddns-update-style none;
option domain-name "example.com"
option domain-name-servers 8.8.8.8, 8.8.4.4;
default-lease-time 86400;
max-lease-time 86400;
log-facility local7;
- reservation with : server2 {
hardware ethernet <MAC>;
fixed-address <ip>
option host-name "h1.test.tg";
}
- You can test the config with #dhcpd -t prior to restart the service
- in /etc/default/isc-dhcp-server , you can edit the listening interfaces.
- arp cache flags : C cache M modified(static)
- log are stored by default in syslog file . you can grep dhcpd.
#journalctl _PID=12996 => Tshoot command
You can restart the networking server on a host so you can see the lifespan of a
dhcp lease
- you also can read logs with #journalctl -f -u isc-dhcp-server
- The lease file is /var/lib/dhcpd/dhcpd.leases
- when you reserve an IP for a MAC , it creates its own lease file.
- You can configure ipv6 in /etc/network/interfaces file .
iface enp0s8 inet6 static
address FC01::1
netmask 64
#ip -6 a s enp0s8
- You can aslo use auto-config in interfaces file
iface enp0s8 inet6 auto
- You can install an RADVD server to advertises the network address to reduce the
need of a dhcp server.
#vim /etc/sysctl.conf
net.ipv6.conf.all.forwarding=1
#sudo sysctl -p
#apt install radvd
#vim /etc/radvd.conf (/usr/share/doc/radvd/examples):
interface enp0s8
{
AdvSendAdvert on;
prefix fc01::/64
{
AdvAutonomous on;
};
};
- LDAP use cases : Linux Auth; DNS entry storage; corporate white pages
- When installing openLDAP on ubuntu , the Directoty Information Tree is created
for you. If your host domain in not correct, neither will your DIT name
- set the server name as fqdn to create a DN . Names of entries in LDAP are always
fqdn and delimited with a comma.
- you need to resolve hostnames with dns or hosts file . The entry for 127.0.1.1 in
the hosts file can cause issues so we remove it.
- Important to have time sync if using LDAP and user authentication . You can
install chrony time server
#apt install -y chrony
- ldap-utils package . The auto-config of DIT is in the package slapd.
- ldapsearch -x -LLL -H ldap:/// -b dc=tech,dc=local dn
- if you do not find results , you can reinstall with #dpkg-reconfigure slapd
- vim structure.ldif
----------------
dn: ou=people,dc=example,dc=com #Entry Name
objectClass: organizationalUnit #Attributes
ou: people
dn: ou=groups,dc=example,dc=com
objectClass: organizationalUnit
ou: groups
-----------------
#ldapadd -W -D cn=admin,dc=example,dc=com -f structure.ldif
- later versions of ldap keep their config in an ldap directory replacing the
/etc/ldap/slapd.conf file.
- you can list directories with ldapsearch or slapcat
#slapcat -b cn=config
#ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=config
- ldap logging (olcLogLevel) : any none conns filter stats
- List current log level : #ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b
cn=config olcLogLevel . You can use journalctl -f -n0 -u slapd from another shell
to see the log results or lack of them
- Modify olcLogLevel : #vim loglevel.ldif
dn: cn=config
changetype: modify
replace: olcLogLevel
olcLogLevel: any
#ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f loglevel.ldif
==========================
WEB SERVICES
- cfdisk for formating
- httpd.conf is the config file. You can load modules in it like dir_module for
DirectoryIndex use , to load index.html where a page is not supplied in the URI
< LoadModule dir_module/mod_dir.so >
#apachectl -M : display loaded modules
#apachectl -M
#apachectl configtest
#
- the document is normally not in the serverroot directory
- LogFormat %h cleint_hostname %u username %t timestamp %s access_method %b size
- CustomLog is used for access logs
- You can load more modules to restrict access to user, group or IPs
#apachetcl configtest
#pgrep apache
- VHosts will allow for different DocumentRoot settings for sites accessed with
different Host names, IP Address or Ports .
- Vhost can have own DocumentRoot ServerName ServerAlias ErrorLog CustomLog
- There is a server status page that can be viewed . You can restrict access to
this page .
- You can use status_module and authz_host_module (to restrict access)
<Location /status>
SetHandler server-status
Require ip 127.0.0.1
</Location>
- To authenticate users , you need to load auth_basic_module authn_file_module and
authz_user_module for authentication type , provider , authorization module. The
authn_core and authz_core needs to be loaded too
#htpasswd -c /etc/apache2/sales.pwd fred => add user and create file ; -D to delete
; none to add existing user ; -v verify user password
- autoindex modules helps listing content of a directory
- <Require valid-user or Require group tech> . authz_groupfile module needed.
- htaccess can restrict access to config files
- Dynamic content can be created with CGI scripts created in PERL or Bash
- alias-module and cgid_module (script execution) neeeds to be enabled
- Adding a scriptAlias allow us to have executable content in a central directory.
ScriptAlias "/cgi-bin/" "/srv/cgi-bin"
<Directory /srv/cgi-bin>
AddHandler cgi-script .sh .pl
Options +ExecCGI
Require all granted
</Directory>
- The .htaccess file provides a way to make config changes on a per-directory basis
without the need to restart the server .
- AllowOverride none => used where htaccess files are not required? use of these
files slows the server down . all => where tenants are allowed complete use of
htaccess files . AuthConfig Options FileInfo => where tenants have a restricted set
of options that are allowed from htaccess files
#apt install php php-apache . The php module mpm_event_module does not work in
threaded mpm mode so we need to run apache in pre-fork mode : mpm_prefork_module
with "Include conf/extra/php_module.conf
- You can load php module and associate .php files from the php config file.
LoadModule php7_module ...
Addhandler php7-script .php
# apt install libapache2-mod-php
- Nginx config is modular underneath the http parent and we can create server
entries. Location entries can be found within server blocks. More than one server
entry is equivalent to vHosts in Apache.
---------------------------------
http {
server {
location / {
root /usr/share/nginx/index.html;
index index.html index.htm;
allow 127.0.0.1; <Location Access restriction>
allow X.X.X.X;
deny all;
}}}
---------------------------------
#sed -i.bak '/^\s*#/d;/^$/d' nginx.conf => remove commented and empty lines
- NGINX is fast to deliver static content but not dynamic content . We might pass
PHP to apache servers (Reverse Proxy)
-----------------------------------
http
server {
location /balancer/ {
proxy_pass http://192.168.56.10/;
}
-----------------------------------
kpota djifa
hotel california , terrain de foot depasser , rentrer dans le premier von a gauche
de hotel california ; 2 e maison etages en carreu a gauche
256 ZSK
257 KSK
- recursion
- 127.0.0.53
- soa explained