Wednesday, August 31, 2016

linux usual Cmds



history Command with timestamp
HISTTIMEFORMAT="%d/%m/%y %T "
history 200

grep  usage examples 
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_04_02.html

=============================
Change  root password expiry 
# chage -l root  (that is a lower case L)
# chage -I 1 -m 0 -M 99999 root
====================================================
systemctl is-active application.service
systemctl status application.service
systemctl is-enabled application.service
systemctl is-failed application.service

systemctl list-unit-files  |grep enabled
systemctl list-units --all
systemctl list-units --all --state=inactive
systemctl list-units --type=service
systemctl cat atd.service
systemctl list-dependencies sshd.service
systemctl show sshd.service
systemctl show sshd.service -p Conflicts
https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
======================================================
yum  commands  usage
http://www.thegeekstuff.com/2011/08/yum-command-examples/?utm_source=feedburner
https://www.tecmint.com/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement/

-------------------------------------------------------------------------------------
fuser  command 
How To View Processes Using A Directory
fuser -v /opt/cdu
displays all processes accessing filesystem on which ‘example.txt’ resides.
fuser -v -m example.txt
To list the process numbers and users of processes of a file
fuser -u  /etc/magic
To terminate all of the processes using a given file system,
fuser -k -x -u -c /dev/hd1
fuser -kxuc /home
fuser -kuc /u/home/code

To list all processes that are using a file which has been deleted from a given file system,
fuser -d /usr
What process is using your tcp or udp socket?
fuser -v -n tcp 80
Kill Processes that are Using a particular Program
fuser -v -k socket_serv
fuser -v -k -i socket_serv   -->asking permission to kill

# yum search fuser
psmisc.x86_64 : Utilities for managing processes on your system
======================================================================
To make nfs export in  linux
http://www.redhat.com/docs/manuals/linux/RHL-7.2-Manual/custom-guide/nfs-export.html
NFS  /etc/exports Configuration File
https://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-nfs-server-config-exports.html
to make an nfs export make entry in  /etc/exports 
/EMRBCP   cpvra00a0024(rw,no_all_squash,no_root_squash
/another/exported/directory 192.168.0.3(rw,sync)
/mnt/export speedy.redhat.com(rw)
#service nfs  restart
#exportfs   -r
#/sbin/service nfs start

Make NFS mount  in /etc/fstab
#-#  NAS nfs mount
wfsaloxnsf01.ent.com:/vol/vol90    /app/nfsdocuments    nfs   rw,bg,hard,rsize=32768,wsize=32768,vers=3,actimeo=0,nointr,nosuid,timeo=600,tcp    0 0  

Make NFS mount in command line
mount -t nfs -o ro  server_IP_addr:/share_name /local_mount_point

showmount -e   -->  to see nfs  shares of  a server

to see mounts and properties 
findmnt - find a filesyst
[root@ruvra89a0047 ~]# findmnt
TARGET                       SOURCE                  FSTYPE      OPTIONS
/                            /dev/mapper/system-root ext4        rw,relatime,barrier=1,data=ordered
â"œâ"€/proc                      proc                    proc        rw,relatime
â"‚ â"œâ"€/proc/bus/usb            /proc/bus/usb           usbfs       rw,relatime
â"‚ â""â"€/proc/sys/fs/binfmt_misc                         binfmt_misc rw,relatime
â"œâ"€/sys                       sysfs                   sysfs       rw,relatime
â"œâ"€/dev                       devtmpfs                devtmpfs    rw,relatime,size=8087064k,nr_inodes=2021766,mode=755
â"‚ â"œâ"€/dev/pts                 devpts                  devpts      rw,relatime,gid=5,mode=620,ptmxmode=000
â"‚ â""â"€/dev/shm                 tmpfs                   tmpfs       rw,relatime
â"œâ"€/boot                      /dev/sda1               ext4        rw,relatime,barrier=1,data=ordered
â""â"€/home                      /dev/mapper/system-home ext4        rw,nosuid,nodev,relatime,barrier=1,data=ordered

[root@ruvra89a0047 ~]# blkid
/dev/mapper/system-root: UUID="5574eebc-631c-438e-ad6a-27afff176519" TYPE="ext4"
/dev/sda1: UUID="c481e46c-56f3-4b69-a03c-5987fa92efcc" TYPE="ext4"
/dev/sda2: UUID="xheITH-YMkP-3otM-5jvm-859E-ekIo-JcFRpQ" TYPE="LVM2_member"
/dev/mapper/system-swap: UUID="ee7e76ca-7e72-477c-8b8f-634c0038334c" TYPE="swap"
/dev/mapper/system-home: UUID="5e7fb8b8-95fe-48fa-86f4-8302ffdc1fb6" TYPE="ext4"

# df -Ph
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/system-root       54G   11G   41G  22% /
devtmpfs                     7.8G     0  7.8G   0% /dev
tmpfs                        7.8G     0  7.8G   0% /dev/shm
tmpfs                        7.8G  137M  7.6G   2% /run
tmpfs                        7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/sda1                    488M  202M  251M  45% /boot
/dev/mapper/system-home      240M  2.2M  221M   1% /home
======================================================================









Friday, August 12, 2016

redhat network Commands

copied it from linuxCmdNetwork.docx in laptop

===============Networking===============================
ifconfig -a
ifconfig eth1 up    --->  to activate eth1
ifconfig eth1 down    ---> to de activate the eth1
ifup bond1  ---->  to activate a bond
service network restart   ---->  to restart network service
service network status    ----->   status of the network devices
system-config-network  ---> command to configure the Ethernet

list the network  devices
lspci
lspci -tv
lspci |grep net
systool -c net
systool -c net -v |grep -v "00 00 00"|grep -v "0x000"
systool -c net -d eth6  -v |grep -v "00 00 00"|grep -v "0x000"

To see  speed of  a Interface
systool -c net -d eth6  -v |grep -v "00 00 00"|grep -v "0x000" |egrep "Class |speed"
systool -c net  -v |grep -v "00 00 00"|grep -v "0x000" |egrep "Class|speed"
grep -H .  /sys/class/net/*/speed
grep -H .  /sys/class/net/*/mtu

To  see  the   interface  and   network  slot  info
/opt/dell/srvadmin/bin/omreport  chassis  nics

2) to see  onboard  network ports using dmidecode
Use below command to see the BUS Address for Ethernet ports
dmidecode -t baseboard |egrep -i "Desig|Bus|type|status"
dmidecode -t baseboard |grep -B1 -A3 Ethernet |egrep -i "Desig|Bus|type|status"
Then use below command to see eth# in  each BUS
systool -c net
lspci -tv |grep net

3)To see PCI slot network ports using dmidecode
Use below command to see BUSAddress for PCI slots
            dmidecode -t slot |egrep "Desig|Bus|Current|Type"
Then use below command to see eth# in  each BUS
systool -c net
lspci -tv |grep net


To  assign ipaddress on  interface
ifconfig eth1  xx.xx.xx.xx  netmask  255.xxx.xxx.x  up
service network restart

$ cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=167.143.186.235
NETMASK=255.255.254.0
GATEWAY=167.143.186.1
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
# Added OPTS for RHEL6 (glh)
        BONDING_OPTS="miimon=100 mode=active-backup"

Set static route  via bond1  ip address
$ cat /etc/sysconfig/network-scripts/route-bond1
162.100.228.0/24  via   170.13.151.1  dev  bond1
130.29.230.0/24  via  170.13.151.1 dev bond1

Netstat command
netstat  -rn      >>  to see routing table       
route  -e      >>      to see routing table        
netstat  -in      >>  network statistics summary
netstat  -an     >>  this will list all ports and their status
cat  /proc/net/dev  >>  to see packet send/receive summary through diff interfaces

to See  ports Listening Status
            grep 9080  /etc/services
            glrpc           9080/tcp                # Groove GLRPC
            netstat -anp  |grep 9080
            netstat -an | grep 1002
            netstat -lpn  ==>  to list listening ports
            netstat -lpn  |grep 1002
            netstat  -tulpn  ==> tcp,udp  listening ports

     lsof -i tcp:1002
     lsof -i udp:1002
     lsof -i  :1002
     lsof  -i |grep  glrpc
     lsof |grep glrpc

 http://www.binarytides.com/linux-ss-command/    ss command  usage 
List all connections The simplest command is to list out all connections. $  ss  | less



change network interface names permanently in Linux
In /etc/udev/rules.d/70-persistent-net.rules, you can assign  device name to a particular MAC address.
find out the MAC address interface"grep -H . /sys/class/net/*/address"  , and then define the interface name to that MAC address in the following format.
# interface with MAC address "00:0c:29:43:28:11" will be assigned "eth0"                                                                            
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:43:28:11", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

To see if an interface  have connection 
ethtool eth2
Settings for eth1:
        Supports Wake-on: g
        Wake-on: d
        Link detected: yes 
mii-tool -v
eth0: negotiated, link ok


To enable Jumbo frames in Linux
To set temporary
# ifconfig eth0 mtu 9000
To Make changes permanent:-Edit the network configuration file for eth0 interface - /etc/sysconfig/network-scripts/ifcfg-eth0 (CentOS / RHEL / Fedora Linux):
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Append the following configuration directive, which specifies the size of the frame in bytes:
MTU 9000
 Restart the Interface eth0:
 /etc/init.d/network restart   or service network restart
To confirm the MTU used between two specific devices. use ip command as follows:
# ip route get {IP-address}
# ip route get 192.168.1.1
Do Ping Test
# ping   -s 8192   -I <source interconnect IP address> <destination IP address>
Example:
# ping -s 8192 -I 198.18.0.38 198.18.0.39




To see the bonds and the   related  network adapers
cd /proc/net/bonding
ls
cat bond0 
cd /sys/class/net/
[root@dansrzd180 net]# ls
bond0  bond1  eth0  eth1  eth2  eth3  lo  sit0



Steps to make BONDS
doc-7944    (how to make bond  RH3)
doc-8108    what are diff modes
how to make bond in RH4
http://kbase.redhat.com/faq/docs/DOC-4284
http://www.cyberciti.biz/tips/linux-bond-or-team-multiple-network-interfaces-nic-into-single-interface.html
http://et.redhat.com/~jmh/docs/Xen_networking.pdf


remember to make backup of files being changed  before editing
step1 :- update   /etc/modprobe.conf   with proper entties as below
vi /etc/modprobe.conf 
alias bond0 bonding
options bonding miimon=100 mode=1 max_bonds=2
install bond0 /sbin/modprobe bonding --ignore-install bonding
alias bond1 bonding
install  bond1 /sbin/modprobe bonding -o bond1

step2:  create fcfg-eth1,fcfg-eth3 and ifcfg-bond1  with simillar entries like below in /etc/sysconfig/network-scripts
[root@dansrzd180 network-scripts]# cat ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond1
SLAVE=yes
USERCTL=no
HWADDR=00:24:E8:64:62:53

[root@dansrzd180 network-scripts]# cat ifcfg-eth3
DEVICE=eth3
BOOTPROTO=none
ONBOOT=yes
MASTER=bond1
SLAVE=yes
USERCTL=no
HWADDR=00:15:17:BC:C5:BD

[root@dansrzd180 network-scripts]# cat ifcfg-bond1
DEVICE=bond1
IPADDR=10.28.130.40
NETMASK=255.255.255.0
GATEWAY=
ONBOOT=yes
BOOTPROTO=none
USERCTL=no

step3 :-
update  /etc/hosts  file with interconnect ipaddresses
restart the networks and bringup the bond1
modprobe bonding
service network restart
ifup bond1




Kernal Mudule Commands

lsmod |grep bond   
rmmod    modname
modprobe --show-depends bond1
depmod -a   (generate map files )
modprobe - program to add and remove modules from the Linux Kernel
  eg:-  modprobe  bonding  -o bond1
            ifconfig bond1 down  ; modprobe -r bond1

Configuring the Linux6 host for LACP bonding

step1:Linux Kernel Module Configuration

#/etc/modprobe.d/bonding.conf
alias bond0 bonding
options bond0 miimon=100 mode=4 lacp_rate=1

step2:set Linux Network file Configuration
# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=none
IPADDR=10.29.194.99
NETMASK=255.255.255.0
GATEWAY=10.29.194.1
BONDING_OPTS="mode=4 miimon=100 lacp_rate=1"
 # cat /etc/sysconfig/network-scripts/ifcfg-eth4
DEVICE="eth4"
BOOTPROTO="none"
HWADDR="00:10:18:F3:B7:1C"
ONBOOT="yes"
MASTER=bond0
SLAVE=yes
# cat cat /etc/sysconfig/network-scripts/ifcfg-eth5
cat: cat: No such file or directory
DEVICE="eth5"
HWADDR="00:10:18:F3:B7:1E"
ONBOOT="yes"
MASTER=bond0
SLAVE=yes

Restart network
service network restart


--------------------------------------------------------------------
Set  the  tcp window size  
Method1
Add to  /etc/sysctl.conf  below values
# TCP buffers
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
# autotune TCP buffers
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
then do
sysctl  -p

Method 2
Command
Description
echo "1" > /proc/sys/net/ipv4/tcp_window_scaling
Activate window scaling according to RFC 1323
echo "1" > /proc/sys/net/ipv4/tcp_timestamps
Activate timestamps according to RFC 1323
echo [wmax] > /proc/sys/net/core/rmem_max
Set maximum size of TCP receive window.
echo [wmax] > /proc/sys/net/core/wmem_max
Set maximum size of TCP transmit window.
echo [wmax] > /proc/sys/net/core/rmem_default
Set default size of TCP receive window.
echo [wmax] > /proc/sys/net/core/wmem_default
Set default size of TCP transmit window.
echo "[wmin] [wstd] [wmax]" > /proc/sys/net/ipv4/tcp_rmem
Set min, default, max receive window. Used by the autotuning function.
echo "[wmin] [wstd] [wmax]" > /proc/sys/net/ipv4/tcp_wmem
Set min, default, max transmit window. Used by the autotuning function.
echo "bmin bdef bmax" > /proc/sys/net/ipv4/tcp_mem
Set maximum total TCP buffer-space allocatable. Used by the autotuning function.
ifconfig eth? txqueuelen 1000
Define length of transmit queue. Replace "?" with actual interface number.

Or 
sysctl -w "net.ipv4.tcp_window_scaling=0"
sysctl -w net.ipv4.tcp_congestion_control=cubic
TO see the kernel parameter value
sysctl  net.ipv4.tcp_window_scaling
To set the pagecache
echo "1 8 10" > /proc/sys/vm/pagecache
or
sysctl -w vm.pagecache="1 8 10"
or
echo "vm.pagecache=1 8 10" >> /etc/sysctl.conf
sysctl -p
-----------------------------------------------------------------------------------------