Monday, February 12, 2018

Linux Administrator Daily Tasks


  • ------------------------------------------Filesystem------------------------------------------


 # mount -o loop,offset=$((10860003 * 512)) disk.img /mnt
blkid
lsblk -f
mount -l
lshw -short
file -Ls
dmesg

format a USB storage device with FAT32 file system
mkfs –t vfat <USB-device-mount-point>

find out the USB device mount point
fdisk -l


mkfs.ext4 <USB-device-mount-point>
mkfs.ntfs <USB-device-mount-point>

unmount the drive,you can’t format a mounted drive.
fdisk -l
sudo umount /dev/sdb1
sudo mkfs.vfat /dev/sdb1
sudo mkfs.ntfs /dev/sdb1

man mkfs.ntfs
man mkfs.vfat

Set label name to USB drives
sudo mkfs.vfat /dev/sdb1 -n sk


  • ------------------------------------------System------------------------------------------

denyhosts
top
top -u sunsail
vmstat
w
uptime
ps
free
iostat
mpstat
pmap
cat /proc/cpuinfo
cat /proc/meminfo
cat /proc/zoneinfo
cat /proc/mounts
cat /etc/issue
uname -r
paste
lsblk -l
uname
history
sudo
mkdir
touch
chmod
chown
tar
date
ptree
pkill
killall

view the amount of free disk space
df –h

list files sorted by size
ls –lSr

see how much space /some/dir is consuming
du -sh /some/dir

List all running processes containing the string stuff
ps aux | grep stuff


extracting entire archive
tar -zxvf backup.tar.gz

extract .xz file
unxz tor-browser-linux32-5.5.4_en-US.tar.xz
tar xvf tor-browser-linux32-5.5.4_en-US.tar

extract .bz2 file
bzip2 -dk FileZilla_3.29.0_x86_64-linux-gnu.tar.bz2
tar xvf FileZilla_3.29.0_x86_64-linux-gnu.tar

linux version
lsb_release -a
cat /etc/issue
cat /etc/os-release
cat /etc/lsb-release
cat /etc/*-release
cat /proc/version

kernel version
uname -r

32x 64x query
uname –m
This displays only the machine hardware name and indicates, as above, whether your system is 32-bit (“i686” or “i386”) or 64-bit (“x86_64”)
The “arch” command is similar to the “uname -m” command and prints to the screen whether your system is 32-bit (“i686”) or 64-bit (“x86_64”)
~$ arch
i686
The “arch” command is similar to the “uname -m” command and prints to the screen whether your system is 32-bit (“i686”) or 64-bit (“x86_64”)
~$ arch
i686

virtual machine check
On Linux
$ dmesg |grep -i hypervisor
$ dmidecode -s system-manufacturer

watch is used to run any designated command at regular intervals.
watch -n 5 "ls -l | wc l"

md5sum ubuntu-6.10-desktop-i386.iso
sha256sum ubuntu-9.10-dvd-i386.iso

Validating the Files On Microsoft Windows GUI
https://wiki.centos.org/TipsAndTricks/sha256sum


iw distinguishes between wireless LAN hardware devices (the physical layer, referred to as phy) and the network interface configured to use that hardware (e.g. wlan0,
similar to an Ethernet eth0 interface). To see the list of devices, and interfaces for each device
iw dev


configure it to start Automatically while system start-up
# chkconfig tgtd on
verify that the run level configured correctly for the tgtd service
# chkconfig --list tgtd

identify processes using files, directories, or sockets
Who is Using a File or Directory
$ fuser  .
$ fuser -v ./
Check Processes Using TCP/UDP Sockets
fuser -v -n tcp 5000
the processes that are using my 'home' directory
$ fuser ~
$ fuser ~ -v
check for the root directory
$ fuser /
$ fuser / -v
$ fuser -v /home/ismail
$ fuser -v -m /home/ismail/.bashrc
$ fuser -v -n tcp 8080
$ fuser -v -n udp 53
kill this TCP listener, you can use option -k
fuser -i -k 8080/tcp
shows all processes at the (local) TELNET port
fuser telnet/tcp
list signals
fuser -l
STOP a process
fuser -i -k STOP [FILE/DIRECTORY]
kills all processes accessing the file system /home
fuser -km /hom


  • ------------------------------------------Networking------------------------------------------


netstat
iptraf
tcpdump
strace
nmap

list open files
lsof
list open files owned by user
lsof -u user1
list open file via tcp
lsof -i TCP:1-1024
lsof -i TCP:80
PID 27808
lsof -Pan -p 27808 -i
lsof -p 2


ifconfig
ifconfig -a
ifconfig  eth0 up
ifconfig  eth0 down
ifconfig  eth0 192.168.70.131
ifconfig  eth0 netmask 255.255.255.0
ifconfig  eth0 broadcast 192.168.70.255


list out all connections
ss|less
Filter out tcp,udp or unix connections
ss -t
ss -A tcp
ss -u
ss -x
List all udp connections
ss -ua
ss -a -A udp
ss -nt
ss -ltn
udp
ss -lun
prints out the statistics
ss -s




netstat -a
netstat -at
netstat -s
netstat -au
netstat -l
netstat -lu
netstat -lt
netstat -tulpn  ## To output numerical service sockets
netstat -plan
netstat -plan | grep ":80"
-p, --program Show the PID and name of the program to which each socket belongs.
# netstat -anp

Messaging
wall
write
talk

Get the PCI address of the NIC:
# lspci | grep Mellanox

Check what ethernet devices exist currently
# ls -al /sys/class/net
# ls  /sys/class/net



look at the last ten lines of /var/log/messages
$ sudo tail /var/log/messages
someone last log in to the system
# lastlog
 the system last rebooted
 # last reboot
 the login history of users
 # last | grep sysadmin

 temporary set the IP address
 ifconfig eth0 192.168.8.185
 ifconfig eth0 192.168.8.185 netmask 255.255.255.0 up
 temporary change the MAC address
 ifconfig eth0 down hw ether AA:BB:CC:DD:EE:FF && ifconfig eth0 up



  • **Network Troubleshooting 

ping 192.168.0.2                          # ping a host
netstat -nr                                    #show routing table without resolving domain names
netstat -ni                                    # show informations about errors/collisions
traceroute www.example.com  # find route to example.com
tcpdraceroute www.example.com  # find route to example.com using tcptraceroute (which uses tcp to discover path).

netstat -i -I em0                          # show statistics about your network card
sockstat -c                                 # show connected sockets
sockstat -l                                  # show listening sockets and processes

arp -na                                       # show arp table
arp -d 192.168.0.2                     # delete a record from arp table
arp -s 192.168.0.2  00:10:b5:99:bf:c4       # add a static record in arp table

tcpdump -tlni em0                      # listen on em0 network interface and sniff packets that pass via em0
tcpdump -tlni em0 -n icmp       # listen for ICMP traffic on em0 network interface
tcpdump -i nfe0 -c1 -n -s0 -vvvv icmp    # capture one ICMP packet and decode itvagran

No comments:

Post a Comment