Sunday, 5 July 2020

How to check the most recent system shutdown time?


276. How to check the most recent system shutdown time?

# last -x | grep shutdown | head -1
# last -x shutdown

277. Command to check processor statistics?

# mpstat 
# iostat

278. What are the common standard ports used?

=> 21/20 ftp
= 22 ssh
= 23 telnet
= 25 smtp
= 53 DNS (tcp/udp)
= 68 DHCP
= 69 TFTP
= 80/443 http/https (tcp)
= 88/464 Kerberos (tcp/udp)
= 110 pop3
= 123 NTP(udp)
= 137 nmbd
= 138,139,445 smbd
= 143 IMAP
= 161 SNMP
= 389/636 LDAP/LDAPS (tcp)
= 514 (udp) syslogd
= 2049 NFS

279. How can you make the file untouchable.txt to be immutable (un-alterable) so that it will not be able to be changed or deleted by any user including root?

To achieve this you can use attributes to change the file to be immutable using below command
chattr +i untouchable.txt

280. How can you run a PHP statement from the command line without creating a file?

You can use the PHP interactive input
# php -r ‘echo “Hello Worldrn”;’
 
281. How to reduce/extend a root lvm?

To Reduce 
– boot into rescue mode without mounting file system (linux rescue nomount).
– activate the lvms if required as explained in previous answer.
– run file system check on respective lvm.
– reduce file system : #resize2fs /dev/vg1/rootlv 10G
– Next, reduce the corresponding lvm : #lvreduce -L 10G /dev/vg1/rootlv (reducing the LV to 10GB)
– Run fsck again.
– Verify the lvm is reflecting the correct size.

To extend 
– no need to boot into rescue, this could be done online.
– unmount the respective file system first (this is not absolutely necessary, size can be extended online, but always recommended to unmount respective file system)
– Extend the lv : #lvextend -L +1G /dev/vg1/rootlv (extending the size to 1GB plus)
– Extend the file system : #resize2fs /dev/vg1/rootlv
– Run fsck if necessary.

282. How to find out backup superblocks for a logical volume?

# dumpe2fs /dev/vg1/rootlv | grep -i “backup superblock”
# mke2fs -n /dev/vg1/rootlv | grep -i -A1 “superblock backup”
 
283. Find out list of actual devices associated with a logical volume using lvs command?

# lvs -o +segtype,devices
# vgdisplay -v <vgname>
# grep device /etc/lvm/archive/<name>.vg

284. How to scan bus so that all newly added devices/luns would come up?

# rescan-scsi-bus.sh 
# echo “- – -” > /sys/class/scsi_host/host<ID>/scan 

285. Command to check all (active/inactive) network interfaces in redhat linux?

# ifconfig -a 
# ip add
# cat /proc/net/dev

286. How do you change the network speed of an interface to 100Mbps with auto-negotiation off and duplex in full mode(example for interface eth0)?

# ethtool -s eth0 speed 100 autoneg off duplex full 
To make this changes persistent need to add the below line to /etc/sysconfig/network-scripts/ifcfg-eth0 file:
ETHTOOL_OPTS=”speed 100 autoneg off duplex full”

287. How do you check the network routing table using commands?

# route -n
# netstat -nr

288. How do you backup and restore iptables (configurations)?

# iptables-save > /tmp/iptables.out
# iptables-restore < /tmp/iptables.out

289. Please explain the checking for Rootkit infections in Linux?

A Rootkit is an advanced form of malware that can yield a range of security issues and in many cases go undetected by average antivirus programs. Hence, advanced anti-spyware tools need to be used for checking Rootkit infections in Linux. One such is the rkhunter.

A few other notable security tools available for checking rootkit infections in Linux are:
Chkrootkit
ClamAV
LMD (Linux Malware Detect)
Lynis

290. What is the difference between command ‘ping’ and ‘ping6’?

Both the commands are same and used for the same purpose except that the fact that ping6 is used with ipv6 IP address.

291. You want to search for all the *.tar files in your Home directory and wants to delete all at once. How will you do it?

# find /home/ -name '*.tar' | xargs rm -rf

292. How do Enable / Disable Ethernet Device?

Open and Edit this file #vi /etc/sysconfig/network-scripts/devicename
For enable ONBOOT = yes
For disable ONBOOT =no

292. Check if any user is using the file system?

Check to the what users are currently using the file system:
# fuser -cu /dev/hdc1

293. What are Zombie process in UNIX and how to find them ?

Zombie process is a process whose execution is completed but have not been removed from the process table.
When a program forks and the child finishes before the parent , kernel has some of the child information .
In case parent needs to check for child's exit status - parent calls 'wait()'. Child is said to be a zombie process in the duration child terminating and the parent calling 'wait()'.

# ps aux | grep -w Z

294. How to sort a text file in linux?

The sort command found in linux to arrange the records of a file in a particular order.
By default, the sort command sorts file assuming the contents are ASCII. Using options in sort command, it can also be used to sort numerically.

sorts the contents of a text file, line by line.

standard command line program that prints the lines of its input or concatenation of all files listed in its argument list in sorted order.

It supports sorting alphabetically, in reverse order, by number, by month and can also remove duplicates.

sort by items not at the beginning of the line, ignore case sensitivity and return whether a file is sorted or not. 

By default, the entire input is taken as sort key. Blank space is the default field separator.

295. How will you restrict IP so that the restricted IP’s may not use the FTP Server?

Block suspicious IP by integrating tcp_wrapper. Need to enable the parameter “tcp_wrapper=YES” in the configuration file at ‘/etc/vsftpd.conf’. And then add the suspicious IP in the ‘host.deny’ file at location ‘/etc/host.deny’.

295. Block IP Address, how to?

Open ‘/etc/hosts.deny’ file and add ip addres.
# vi /etc/hosts.deny

296. Q:23 How  to find WWN numbers of HBA cards in Linux Server ?

Method 1
To find the HBA cards installed on your system use :
# lspci -nn | grep -i hba

To check the available HBA ports :
# ls -l /sys/class/fc_host

To find the state of HBA ports (online/offline) :
# more /sys/class/fc_host/host?/port_state

To find the WWN numbers of the above ports :
# more /sys/class/fc_host/host?/port_name

Method 2 : Using systool
To check the available HBA ports :
# systool -c fc_host

To find the WWNs for the HBA ports :
# systool -c fc_host -v | grep port_name

To check the state of the HBA ports (online/offline) :
# systool -c fc_host -v | grep port_state

297. How canyou check BIOS settings from the command line?

# dmidecode | more
# Biosdecode | more
# Hwinfo | more

298. Can we think of systemd over init system?

Systemd is the first process of the Linux system and very well designed process in compare with init.
Systemd is multithreaded and faster than init. Systemd is standard processes to control programs need to be run during Linux boot. It was conceived from the top, not just to fix the bugs, but to be a correct implementation of all the base system services. A systemd, may refer to all packages, utilities and the
libraries around the daemon. It was designed to overcome all the shortcomings of init. It is itself a background process which is designed to start the processes in parallel, and thus reducing the boot time and computational overheading.

 It has a lot of other features as compared to init.
Systemd support multiple useful commands with unified command-line interfaces
Systemd makes the boot process much simpler
Systemd support backward compatibility
Systemd supports SELinux integration
Systemd is an incredibly fast service

299. What are MAJOR and MINOR numbers of special files?

Major and minor numbers are associated with the device special files in the /dev directory and are used by the operating system to determine the actual driver and device to be accessed by the user-level request for the special device file.

Special files for char drivers are identified by a “c” in the first column of the output of ls –l and the two numbers (separated by a comma) in the device file entries before the date of last modification are the major device number and minor device number for the particular device.
For example,
Cd /dev
Ls –l

300. What is the ctrl+D error?

ctrl+D error is one of the common errors occur when the root user tries to make any Permanent entry in fstab file & by mistake changes the path location of mounted file systems in os, it gives error while rebooting the system and fails to load.

fstab is a system configuration file on the Linux operating system that contains information about major filesystems. This file is located in /etc directory and can be viewed like “cat /etc/fstab”.

We have set steps to recovery system from ctrl+D error.
1. Boot system using bootable CV/DVD of Linux of the current version installed
2. Read ctrl+D error for the exact issue
3. Connect using Root User and it will connect you in single-user mode
4. Access /etc/fstab file and make required changes 
5. Try normal system reboot

                                                                                           MENU         PREVIOUS

No comments:

Post a comment