Wednesday, November 23, 2022

Linux Interview Questions

1. What is Linux?

Linux is an open-source operating system based on UNIX. It was named after the founder “Linus Torvalds”. He introduced Linux with the primary goal to offer an operating system at a free or very reasonable price for users. It is based on the Linux kernel and is compatible with different hardware platforms such as Intel, MIPS, HP, IBM, SPARC, and Motorola hardware platforms. Linux’s mascot, a penguin named Tux, is another popular feature. Linux offers a user-friendly environment where they can easily modify and create variations in the source code.

2. Compare Linux with Windows.


3. What are the components of the Linux system?

There are three primary components of the Linux system which are explained below.

Kernel: The kernel is the most important component of Linux. It is in charge of the operating system’s primary functions. It is made up of a number of modules that interface directly with the hardware. Kernel offers the necessary abstraction for system or application programs to mask low-level hardware information.

System libraries: They are specialized functions or programs that allow application programs or system utilities to access Kernel capabilities. These libraries implement the majority of the operating system’s functionality and do not require kernel module code access permissions.

System Utility: Programs in the System Utility category are in charge of performing specialized, individual-level activities. They are more dependable and also provide users control over the computer.

4. What is LILO?

LILO (Linux Loader) is a boot loader for Linux. It is used to load Linux into memory and start the operating system. LILO can be configured to boot other operating systems as well. LILO is customizable, i.e., if the default configuration is not correct, it can be changed. The config file for LILO is lilo.conf. LILO is also a code snippet that loads PC BIOS into the main memory at the time of starting the computer system.

It handles the following tasks:

  • Locating Linux kernel
  • Identifying other supporting programs and loading them in memory
  • Starting the kernel

The selection of various Kernel images and boot routines is supported by LILO. For this reason, it is known as the boot manager.

5. Suppose, you wish to print a file ‘draft’ with 60 lines on a page. What command would you use?

The command used for this purpose would be as follows:

pr -l60 draft

Note: The default page length when using pr is 66 lines. The -l option specifies a different length.

6. What is LD_LIBRARY_PATH?

LD_LIBRARY_PATH is an environment variable used for debugging a new library or a non-standard library. It is also used to identify the directories that need to be searched for; in order to do this, the path to search for the directories needs to be specified.

The variable can be set using the following:

setenv-LD_LIBRARY_PATH--$PATH

It is used to search for the shared objects/dynamic libraries by the operating system for extendable functionality at the runtime.

7. Name a service that you should disable (which acts both as web and FTP servers) on a Linux server.

The finger service should be disabled on a Linux server because a remote user can get important information about the system by using this command.

8. What does sar provide? Where are the sar logs stored?

In Linux, the sar command collects, reports, or saves system activity information, and it serves to log and evaluate a variety of information regarding system activity. With performance problems, sar also permits retroactive analysis of the load values for various sub-systems (CPUs, memory, disks, interrupts, network interfaces, and so on). If CPU utilization is near to 100 percent, the sampled workload is considered to be CPU-bound.

By default, the log files of the sar command are located at the /var/log/sa/sadd file, where the dd parameter indicates the current day.

9. How to check memory stats and CPU stats as a Linux Admin?

Using the free and vmstat commands, we can display the physical and virtual memory statistics, respectively. With the help of the sar command, we can see the CPU utilization and other stats.

vmstat -a

10. How to reduce or shrink the size of the LVM partition?

Below are the logical steps to reduce the size of the LVM partition:

  • Unmount the file system using the unmount command
  • Use the resize2fs command as follows:
    resize2fs /dev/mapper/myvg-mylv
  • Then, use the lvreduce command as follows:
    lvreduce -L 10G /dev/mapper/myvg-mylv
    This way, we can reduce the size of the LVM partition and fix the size of the file system to 10 GB.

Sunday, September 4, 2022

Docker

 Why Docker

While creating an application stack with components like Ansible, Nodejs, MongoDB. We need to check the compatibility with the OS for each component and then check the libraries and dependencies between each other. The same is true when there is an upgrade required on any of the components. Compatibility matrix issue. Long setup time. Different Dev/ QA/ Perf / Prod environments and if the application stack would work identical in each setup.

Solution - Docker (Runs each component in different containers on a single VM).
Containerize application, Run each service in its own dependencies in separate containers.
 
Containers are completely isolated environments with their own process, network, services, mounts except they share the same OS.

Docker uses lxc containers.

Docker does not support Windows container on a Linux host. It needs a Windows host.

Containers vs Virtual Machines
1. Utilization is less for docker
2. Size required is less
3. Boot up time is less.
4. Containers have less isolation compared to the VMs.

It can be a mix of docker on the VMs.

Docker image is a template like we have in a VM which is used to create containers.

2 versions -
1. Community Edition - Free
2. Enterprise Edition - Certified and supported comes with image management, image security.

Community Edition is available on -
1. Linux
2. MAC
3. Windows
4. Cloud Platforms

Docker Install

curl -fsSL https://get.docker.com -o getdocker.sh
sudo sh get-docker.sh

Checking Docker version
docker version

Docker Hub

Start the Docker service and validate
systemctl start docker
systemctl status docker

Install a docker module and run
docker run docker/whalesay cowsay Hello-World

Docker Commands
List containers
docker ps

List all containers including stopped
docker ps -a

To stop docker container
docker stop <container ID> / <container name>

Remove a container completely
docker rm <container name>

To see list of images
docker images

Remove image
docker rmi <image name>
(You must stop any container if it is using this image)

Command to only download the image
docker pull nginx

Append a command
docker run ubuntu sleep 5
(This will install nginx and then keep it running for 5 sec before sleeping)

Execute a command on the container
docker exec distracted_mcclintock cat /etc/hosts

Run - attach and detach
docker run kodekloud/simple-webapp
(This will show the output in the screen without letting you to do anything further)

We can run a container in detached mode
docker run -d kodekloud/simple-webapp

To attach the container
docker attach <container ID>

Installing centos
docker run centos
docker run -it centos bash (This will log you in the centos container)

docker run -d centos sleep 20
docker ps

docker run -d centos sleep 2000
docker stop <container name>
docker ps
docker ps -a

Exited code (0) means they exited under normal conditions
Exited code (137) means it was stopped by the user.

Removing docker container
docker rm <container name> / <container ID>
docker ps -a
(This need to be done to reclaim disk space)
(Multiple container name / ID can be provided while removing containers)

busybox is a small image to do a quick test.

docker images
docker rmi busybox

(If there are any container using the image it need to be removed first before removing the docker image otherwise it will fail)

docker pull ubuntu
(This is to just pull the image and keep it to save the time for downloading during running the docker container)

docker run -d ubuntu sleep 100
docker ps
docker exec <container id> cat /etc/hosts

Docker run commands
docker run redis
docker run redis:4.0

Here :4.0 is the tag. 
If no tag is attached, then the tag used is "latest".

You can find all the available tags for a image from Docker hub

By default, the docker container does not listen to standard input. 
docker run kodekloud/simple-prompt-docker
Hello and Welcome!

docker run -i kodekloud/simple-prompt-docker
Mainak
Hello and Welcome Mainak!

docker run -it kodekloud/simple-prompt-docker
Welcome! Enter your name: Mainak
Hello and Welcome Mainak!

A terminal needs to be attached to get the input prompt. 

Port mapping
Underlying host where docker is installed docker host or docker engine. (192.168.1.5)
Let's say I have configured a webapp and it is running on port 5000.(http://0.0.0.0:5000)

Now how a user can access it. 
1. Users can use the IP of the docker container. 
172.17.0.2 - However, it is an internal IP and only can be accessed from the docker host.

2. For users outside of docker host,  they can use the IP of the docker host but for that a port mapping needs to be done between the container and docker host.

docker run -p 80:5000 kodekloud/simple-prompt-docker

Multiple instances of the application can be run on multiple ports.
docker run -p 8080:5000 kodekloud/simple-prompt-docker

However, using the same port on the docker host is not possible.
docker run -p 8080:5000 kodekloud/simple-prompt-docker
docker run -p 8080:5000 kodekloud/simple-prompt-docker

Docker - Volume mapping
/var/lib/mysql - Data volume (Docker container file-system)
Let's say we have a mysql container and we need to delete the container and re-build it then all data will be lost.

To avoid this, we can map a volume between docker container file-system and docker host file-system. 
docker run -v /opt/datadir:/var/lib/mysql mysql
Here /opt/datadir is the file-system on the docker host.

Inspect Container to check all container information
docker inspect <container id> / <container name>

Container Logs
docker logs <container id> / <container name>

docker run -d ubuntu sleep 1500
docker ps
docker attach <container id>
This cause hang and had to close the terminal
You need to open a separate terminal and stop the docker container
docker stop <container id> / <container name>

docker run timer
(This runs infinitely and prints date / time)
This runs in the attach mode.
docker run -d timer
docker ps
docker attach <container id> / <container name>
It works.

docker run jenkins/jenkins
Check the IP of the docker container from different terminal
docker ps -a
docker inspect <container id> | grep -i ip
Now check from the GUI of the docker host opening Mozilla
http://<container IP>:8080

Now try to access from the browser to the IP of the docker host
This will not open.

docker run -p 8080:8080 jenkins/jenkins
Now try to access from the browser and it works.

Provide the admin password and proceed with the default package installation. 
Create the admin user and finish installation.

Create a job -> TestJob -> Freestyle project -> Ok.

Come out of the docker container and it will stop. Browser refresh will no longer show jenkins.

If we re-run the jenkins installer, it creates a new container and takes back on the initial config page. 

mkdir my-jenkins-data
docker run -p 8080:8080 -v /root/my-jenkins-data:/var/jenkins_home -u root jenkins/jenkins
Complete jenkins config from the browser and create a job

Now exit from the container and create a new container.
Re-run the last run docker command to recreate jenkins container.

As the volume is mapped it will not ask for any configuration and once you login you will be able to see the pre-configured job which was created during the last container install. 

Creating custom docker images
Let's say to deploy a app written in flash python

1. OS-Ubuntu
2. Update opt repo
3. Install dependencies using opt
4. Install python dependencies using pip
5. Copy source code to /opt folder
6. Run the web server using flask command.

Create a file called Dockerfile

FROM Ubuntu
RUN apt-get update && apt-get -y install python
RUN pip install flask flask-mysql
COPY . /opt/source-code
ENTRYPOINT FLASK-APP=/opt/source-code/app.py flask run

docker build . -f Dockerfile -t mainak/my-custom-app

docker push mainak/my-custom-app

Anything on the left is an instruction and on the right are the arguments.

To see the space allocated to run the custom image and even each steps / layers
docker history mainak/my-custom-app

All layers in docker are cached, so even if it fails and rebuild done it starts from the layer it failed and thus improves the processing time.


docker run -it ubuntu bash
apt-get update

Tuesday, July 26, 2022

Ansible

Ansible Controller

Ansible Target 1

Ansible Target 2


Post OS provision with 2 vCPU, 2 GB Memory and Bridged network.

Controller

vim /etc/hostname

ansiblecontroller

vim /etc/hosts

127.0.0.1 localhost ansiblecontroller

::1            localhost ansiblecontroller

shutdown -r now

Target 1

vim /etc/hostname

target1

vim /etc/hosts

127.0.0.1 localhost target1

::1            localhost target1

shutdown -r now

Target 2

vim /etc/hostname

target2

vim /etc/hosts

127.0.0.1 localhost target2

::1            localhost target2

shutdown -r now

Controller

yum install epel-release

yum install ansible

ansible --version

Ansible Inventory

Done through SSH

Linux - SSH

Windows - Powershell Remoting

Default location of Inventory files -

/etc/ansible/hosts

Inventory Parameters

ansible_connection - ssh /winrm / localhost

ansible_port - 22/5986

ansible_user - root/administrator

ansible_ssh_pass - Password

Sample Inventory File -

web ansible_host=server1.example.com ansible_connection=ssh ansible_user=root

db ansible_host=server2.example.com ansible_connection=winrm ansible_user=administrator

mail ansible_host=server3.example.com ansible_connection=ssh ansible_ssh_pass=<Password>

web2 ansible_host=server4.example.com ansible_connection=winrm

localhost ansible_connection=localhost

Defining password is not good, so suggested to use passwordless ssh.

Stop and disable the Firewall service on the controller and target systems.

Examples -

pwd - /root

mkdir ansible-demos

cd ansible-demos

cat > inventory.txt

target1 ansible_host=192.168.1.24 ansible_ssh_pass=<password>

ansible target1 -m ping -i inventory.txt

Add the target2 now in inventory.txt

target2 ansible_host=192.168.1.25 ansible_ssh_pass=<password>

ansible target2 -m ping -I inventory.txt

This would fail

vim /etc/ansible/ansible.cfg

Uncomment the below line

host_key_checking=False

ansible target2 -m ping -I inventory.txt

YAML

Key value pair -

fruit: apple

vegetable: cucumber

Array -

fruits:

- orange

- apple

vegetables:

- cucumber

- carrot

Dictionary - 

Banana:

    Calories: 105

    Fat: 0.4g

Grapes:

    Calories: 62

    Fat: 0.3g

Key Value / Dictionary/Lists

Fruits:    

-    Banana:

        Calories: 105

        Fat: 0.4g

-    Grapes:

        Calories: 62

        Fat: 0.3g

Dictionaries are mainly used while representing properties of a particular item.
Lists are used for listing the items of same category. 
However, lists can have dictionaries defined in them.

The order for the dictionary for example calories and fat need to be in same order. 

Ansible Playbooks





Puppet

Puppet - Ruby Based declarative pull technology to manage IT configurations.

Founder - Luke Kenies

Deployment Types - Master-Client & Standalone

Puppet Master - Always Linux

Puppet Agent - Any OS including Windows.

Another Similar example - CHEF

Push based - Ansible, Saltstack

Port - 8140

Default polling - 1800 secs (30 mins)

Pre-requisites - 

1. Deployment Type

2. Persistent hostname

3. System Requirement - 2 vCPU and 1 GB RAM

4. Supported OS

5. Firewall port on Master - 8140 to be open

6. NTP to be used for time sync

Why Puppet - 

1. Declarative

2. Takes care of repetitive tasks

3. Increases productivity

4. Consistent Delivery

5. Simplicity

6. Scalable

Puppet is an example of Infrastructure as Code (IaC)

Idempotency - 

The results of puppet code will remain the same irrespective of the number of times the puppet runs on a particular node.

For Standalone config - 

Network - NAT -> Advanced -> Port Forwarding -> 

ssh tcp 2222 22

While connecting through putty 127.0.0.1 and port 2222.

Puppet Architecture - 

Puppet Master pulls the facts from Agents using the faster command and then prepares a catalog which is the drift between the expected and current config and then sends the catalog to Agents. Agent then applies the required changes if any and generates report to send back to the master.

Facts are the OS information like IP address, Kernel version others.

Building Blocks - 

1. Resources - File, Service, User, Router, Computer, Packages

2. Classes - Web Services (All resources)

3. Mannifests - Puppet DSL (Domain Specific Language) files. .pp files (Puppet programs). Declaration of Puppet classes.

4. Modules - Collection of files & directories. Reusable. Example - Mysql / Jenkins.

Types of Resources - 

1. Core / Build In

2. Defined

3. Custom

To check resources

puppet help

puppet --help

puppet help resource

puppet resource --types | grep -i user

Code Execution Process -

1. Create

2. Check - puppet parser validate <file-name>

3. Test - puppet apply --noop (Standalone)

              puppet agent -tv --noop (Master-Client)

4. Run - puppet apply  (Standalone)

              puppet agent -tv (Master-Client)

Post OS build config - 

1. Add entry for the host in /etc/hosts file.

2. hostnamectl set-hostname <hostname>

3. Disable firewall service

4. Install Puppet repo

rpm -Uvh http://yum.puppet.com/puppet-release-el-7.noarch.rpm

5. yum install puppet-agent (for Agents)

    yum install puppetserver (for Master)

6. ln -s /etc/puppetlabs/bin/puppet /usr/bin/puppet

or

export PATH = /etc/puppetlabs/bin:$PATH

Class - 

Syntax - 

Class <classname> {

    <Resource Declaration>

}

Manifests - 

To check manifest path - 

puppet config path | grep -I manifests

Default Manifest path - 

/etc/puppetlabs/code/environment/production/manifests

Main config file - site.pp

Puppet Master - Client Architecture - 

On Puppet being installed on the Agent, it sends a ssl certificate to Master. Once Master signs the certificate, the Agent can then only run puppet.

ssl certificate path - /etc/puppetlabs/puppet/ssl

Puppet Config file on Agent -

/etc/puppetlabs/puppet/puppet.conf

[main]

certname = <Agent name>

server = <Puppet Master name>

To list the certificates and sign from Master - 

puppet cert list 

puppet cert list --all

OR

puppetserver ca list

puppetserver ca --list --all

puppetserver ca sign <agent name>

To clean the certificate -

puppet cert clean <agent name>

To generate certificate

puppet cert generate

Autosign configuration -

/etc/puppetlabs/puppet/autosign.conf

*.example.com

To apply restart puppetserver

systemctl restart puppetserver

Node Definition -

This is used to declare something specific to a particular node or set of nodes.

node <node name> {

    <Resource declaration>

}

To avoid errors on other nodes but not apply puppet changes -

node <node name> {

    <Resource declaration>

}

node 'default' {

}

Multiple nodes can be defines as well -

node '<node name>','<node name 2>' {

    <Resource declaration>

}

Variables - 

class "<class name>" {

    $<variable name> = "<value>"

}

Facts - pre-defined system information

facter ipaddress

facter osfamily

facter os

facter os.release.full

Puppet Modules - Collection of puppet resources and classes.

Benefits - 

1. Sharable

2. Reusable

Directory Structure -

Module Name

    manifests

    files

    templates

    lib

    facts.d

    examples

    spec

    functions

    types


Puppet Roles and Profiles

Modules - jdk, php, tomcat, mysql,httpd

Profile - Webserver (php, http), DB Server (mysql)

Role - Webserver.dev(Webserver), Webserver.prod (Webserver)

Hiera - 

It is used to make custom changes on nodes to overwrite puppet config.

hiera.yml

---

    ntp: servers :

       - bool.server ....

Mcollective (MCO) - 

Runs jobs in parallel, run as push instead of pull. 

1. Performs quick Adhoc tasks from Master to Agents.

2. Vulnerability management. 

3. Inventory Collection. 

4. Helps in generate reports. 

However, making MCO work with open source puppet is tedious job.

Puppet Forge -

Search, Download, Install and Use pre-configured puppet modules.

puppet module generate <Module name>

Troubleshooting - 

1. If puppetserver don't start. Check the memory config on /etc/sysconfig/puppetserver and change it from 2G to 500M and try restart of the service. If it still not works, try restarting the server. 


 


Saturday, January 2, 2021

Setting date on a server 3 days in advance

 date --set="+3days"

Sort files based on size for a file-system

cd <file-system> 

cd /

du -sk * | sort -nr | head

or

find / -type f -exec du -Sh {} + | sort -rh | head 

[You can modify the path / to replace with the path you need]

Listing top CPU / Memory consuming processes

 CPU -

ps -eo pid,%cpu,comm,user | sort -rk 2 | head

Memory - 

ps -eo pid,pmem,rss,vsize,args,user | sort -rk 2| head

Increasing storage to a existing disk attached to a VM

Increase the disk size allocated to the VM and make sure the datastore has enough space.  


echo 1 > /sys/block/<device-name>/device/rescan [Device name can be for example sdc]
fdisk /dev/sdc
p
d
n
p
default
w
partprobe /dev/sdc
pvresize /dev/sdc1

Validate it with pvs/vgs.


Preserving SSH keys of a host

Generally when we are connecting to a replacement host from another server, for the first time it asks for yes / no option to add the host entry in the known_host as the fingerprint changes.

To retain the same while migrating to a new server the below process can be followed.  

ls -l /etc/ssh/*key* > ~/key_list

mkdir ~/serverkeys && cp -p /etc/ssh/*key* ~/serverkeys/

cp -p ~/serverkeys/*key* /etc/ssh

ls -l /etc/ssh/*key* | diff - ~/key_list

Test ssh connection to the new host. 

Puppet

 Checking puppet-managed files

cat $(puppet agent --configprint resourcefile) 

Checking if puppet-disabled on a host

cat `puppet agent --configprint agent_disabled_lockfile`

Java Config

 Checking Java versions available 

rpm -qa | grep -i java

Switching to a different version of Java - 

alternatives --config java

Checking Java Version - 

java --version

Installing a particular version of Java -

yum install <java-package-name> -y

Printer Configuration

Install Cups Service - 

yum install cups -y

Validating the package - 

rpm -qa | grep -i cups

Start Service - 

systemctl start cups / service cups start

Status of Service - 

systemctl status cups / service cups status

Listing all printers - 

lpstat -a

lpstat -a | grep -I <printer-name>

Raw printer configuration - 

lpadmin -p <printer-name> -E -v socket://<printer-name>:<port-number> -o printer-error-policy=retry-job 

lpadmin -p <printer-name> -m raw

Checking Printer Configuration - 

lpoptions -p <printer-name>

Configuring printer with Driver File

lpadmin -p  <printer-name> -v socket://<printer-name>:<port-number> -P /etc/cups/ppd/<printer-driver-filename>

/usr/sbin/cupsenable <printer-name>

/usr/sbin/cupsaccept <printer-name>

Removing a Printer - 

lpadmin -x <printer-name>

Printer log location - 

/var/log/cups

Checking if port open - 

nmap -p <port-number> <printer-name>

Checking if printer is reachable and DNS present - 

ping <printer-name> / ping <ip-address>

nslookup <printer-name>

Check the print jobs -

lpq -p <printer-name>

How to look for only the PID of the jobs in case clean-up required - 

lpq -p <printer-name> | awk '{print $3}'

Cancel any job stuck in print queue - 

cancel <PID>

DF Hung - Identify the mount point causing it

 strace df

un-mount (If required forcefully) and remount it. 

Install fuser

 yum install psmisc -y

which fuser

Friday, August 31, 2018

Disable SELinux on CentOS7

1. Check the current status -
# sestatus

2. Disable SELinux permanently -
# vi /etc/selinux/config
Change SELINUX=disabled

3. Reboot the server and then check the status.

4. Disable SELinux temporarily -
setenforce 0

However this change will be valid for the current runtime session only.

Monday, July 30, 2018

Working with Route Table

1. Checking route table
# ip route show

2.Adding static route
# ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0

3. Remove static route
# ip route del 10.10.20.0/24

4. To add persistent static routes
# vi /etc/sysconfig/network-scripts/route-eth0
10.10.20.0/24 via 192.168.50.100 dev eth0

5. To add a default gateway
# ip route add default via 192.168.50.100

Awk command examples

1. Listing all lines in a file
# awk '//{print}' filename

2. List lines with specific word from a file
# awk '/localhost/{print}' filename

3. Use of awk with (.) wild card
# awk 'l.c/{print}' filename

4. Use of awk with (*) wild card
# awk 'l*c/{print}' filename

5. Use of awk with a set of characters
# awk '/[ab9]/{print}' filename
# awk '/[pu]p/{print}' filename

6. Specifying numbers and characters in a range with awk
# awk '/[0-9]/{print}' filename
Similarly these can be used - [a-z][A-Z][a-zA-Z][a-zA-Z 0-9]

7. Use of Awk with meta character(^)
# awk '/^192/{print}' filename

8. Use of Awk with meta character ($)
# awk '/com$/{print}' filename

9. Use of Awk with escape character (/)
# awk '/\$/{print}' filename

10. Use of Awk to print the fields and columns.
# awk '//{print $1 $2 $3}' filename
# awk '//{print $1,$2,$3}' filename
# awk '//{printf "%-10s %s\n",$1,$2}' filename

Sed command examples

1. Viewing a range of lines from a file
#sed -n '5,10p' filename

2. Viewing an entire file except few lines
#sed '5,10d' filename

3. Viewing non-consecutive range of lines from a file
#sed -n -e '5,10p' -e '15,20p' filename

4. Replacing specific word in a file
# sed 's/this/that/g' filename

5. Replacing specific word ignoring character case from a file.
# sed 's/this/that/gi' filename

6. Replace multiple blank space with single blank space.
# sed 's/ *//g' filename
# ip route show | sed 's/  */ /g'

7. Replacing words in a range of lines in a file
# sed '5,10 s/this/that/g' filename

8. Viewing the configuration files without the comments and blank lines.
# sed '/^#\|^$\| *#/d' httpd.conf

9. Substitution of words using regular expression.
# sed 's/[Tt]his/that/g' filename

10. Viewing lines using a given pattern
# sed -n '/^Jul 1/ p' /var/log/secure

11. Inserting spaces in a file
# sed G filename
# sed "G;G" filename

12.  dos2unix using sed
# sed -i 's/\r//' filename

13. In-place editing and backup of original file
# sed -i'.orig' 's/this/that/g' filename

14. Switching pair of words
# sed 's/^\(.*\),\(.*\)$/\2\, \1/g' filename

15. Replacing word only if a separate match is found.
# sed '/services/ s/start/stop/g' filename

16. Performing 2 more substitution on a file
# sed -i 's/this/that/g;s/there/their/gi' filename

17. Combining sed and other commands.
# ip route show | sed -n '/src/p' | sed -e 's/  */ /g' | cut -d' ' -f9

Tuesday, July 24, 2018

Changing timezone

List all timezone's in Linux 6
ls -lrt /usr/share/zoneinfo

Changing timezone in Linux 6
mv /etc/localtime /root/localtime.old
ln -sf /usr/share/zoneinfo/America/Chicago /etc/localtime

List all timezone's in Linux 7
timedatectl list-timezones 

Changing timezone in Linux 7
timedatectl set-timezone America/Chicago

Saturday, April 8, 2017

Disable IPv6 on RHEL7

vi /etc/sysctl.d/ipv6.conf

# To disable for all interfaces
net.ipv6.conf.all.disable_ipv6 = 1

sysctl -p /etc/sysctl.d/ipv6.conf