Module 7
Module 7
SERVICES AND
SYS TEM UPDATES
Internet Access to
VM
• Open Virtualbox Manager
• Select the machine you cannot get internet on in the left
pane
• Click the Settings button in the top menu
• Click Network in the left pane in the settings window
• Switched to Bridged Adaptor in the Attached to drop-
down menu
• Hit OK to save your changes
• Start your VM
Network
Components
• IP
• Subnet mask
• Gateway
• Static vs.
DHCP
• Interface
• Interface
MAC.
Network Files and
Commands
• Interface Detection
• Assigning an IP address
• Interface configuration files
• /etc/nsswitch.conf
• /etc/hostname
• /etc/sysconfig/network
• /etc/sysconfig/network-scripts/
ifcfg-nic
• /etc/resolv.conf
• Network Commands
• ping
• ifconfig
• ifup or ifdown
• netstat
• tcpdump
NIC
Information
NIC = Network Interface
Card
Example:
ethtool enp0s3
Other NICs
lo = The loopback device is a special interface that your computer uses
to communicate
with itself. It is used mainly for diagnostics and troubleshooting, and to
connect to servers
running on the local machine
virb0 = The virbr0, or "Virtual Bridge 0" interface is used for NAT
(Network Address Translation). Virtual environments sometimes use
NIC Bonding
nic1
nic2
bond0
• # ifconfig
• # systemctl reboot
• # ip address show
System Updates and
Repos
•yum (CentOS), apt-get (other
Linux)
•rpm (Redhat Package
Manager)
Download Files or Apps
• Example of Windows browser
• Linux = wget
• Example in Linux:
wget http://website.com/filename
• Why???
Most of the servers in corporate
environment do NOT have internet
access
curl and ping
Commands
• Example of Windows browser
• Linux = curl
• Linux = ping
• Example in Linux:
curl http://website.com/filename
curl –O http://website.com/filename
ping www.google.com
FTP – File Transfer Protocol
• The File Transfer Protocol is a standard network protocol used for the
transfer of computer files between a client and server on a computer
network. FTP is built on a client-server model architecture using
separate control and data connections between the client and the
server. (Wikipedia)
Client = Server
A =B
FT
P
ftpd =
21
FTP – File Transfer Protocol
• Install and Configure FTP on the remote
• # Become root
server
• # rpm –qa | grep ftp
• # ping www.google.com
• # yum install vsftpd
• # vi /etc/vsftpd/vsftpd.conf (make a copy first)
• ## Uncomment ##
• ascii_upload_enable=YES
• ascii_download_enable=YES
Client = Server
ss =B
A
h sc
p
sshd =
22
SCP – Secure Copy
• SCP commands to transfer file to the remote server:
• This utility is mostly used to backup the files and directories from
one server to another
Client = Server
ss =B
A
h rsyn
c
2M 2M 2M sshd =
22
8M 8-2 = 6 8M
20M 20-8 = 12 20M
rsync – Remote Synchronization
• Basic syntax of rsync command
• # rsync options source destination
Example:
yum update –y
C REATE LOC A L REPOSITORY
FROM DV D
• What is local
repository?
Repos
Repos
Redhat or CentOS
Linux repository
Server
• Command
createrepo
Advance Package Management
• Installing packages
• Upgrading
• Deleting
• View package details
information
• Identify source or
location information
• Packages
configuration files
Rollback Updates and
Patches
• Virtual machine
• Physical machine
• Rollback an update
• Downgrading a system to minor version (ex: RHEL7.1 to RHEL7.0)
is not recommended as this might leave the system in undesired
or unstable state
nt
Client p Server
DNS = Domain Name
System
• Purpose?
Hostname to IP (A Record)
IP to (PTR Record)
Hostname (CNAME Record)
Hostname to
• FilesHostname
/etc/named.conf
/var/named
• Service
systemctl restart named
Download, Install and Configure DNS
• Create a snapshot of your virtual
machine
• Setup:
• Master DNS
• Secondary or Slave DNS
• Client
• File
/etc/ntp.conf
• Service
systemctl restart ntpd
• Command
ntpq
chronyd
• Purpose? = Time synchronization
• Package name = chronyd
• Configuration file = /etc/chronyd.conf
• Log file = /var/log/chrony
• Service = systemctl start/restart chronyd
• Program command = chronyd.
New System Utility Command (timedatectl)
• The timedatectl command is a new utility for RHEL/CentOS 7/8 based distributions, which comes as a
part of the systemd system and service manager
• It is a replacement for old traditional date command
• The timedatectl command shows/change date, time, and timezone
• It synchronizes the time with NTP server as well
• You can either use chronyd or ntpd and make the ntp setting in timedatectl as yes
• Or you can use systemd-timesyncd daemon to synchronize time which is a replacement for
ntpd and chronyd
Please note:
Redhat/CentOS does not provide this daemon in its standard repo. You will have to download it separately.
New System Utility Command (timedatectl)
Lab exercise:
• To check time status
• timedatectl
• To set date
• timedatectl set-time YYYY-MM-DD
• Files
/etc/mail/sendmail.mc
/etc/mail/sendmail.cf
/etc/mail
• Service
systemctl restart sendmail
• Command
mail –s “subject line” [email protected]
Sendma
il
• Sendmail is a program in Linux operating systems that
allows systems administrator to send email from the
Linux system
• Configuration file=
/etc/syslog.conf
• Service Client Server Client
Client
Linux OS Hardening
• User Account
• Remove un-wanted packages
• Stop un-used Services
• Check on Listening Ports
• Secure SSH Configuration
• Enable Firewall (iptables/firewalld)
• Enable SELinux
• Change Listening Services Port Numbers
• Keep your OS up to date (security
patching)
OpenLDAP
Installation
•What is OpenLDAP?
•OpenLDAP Service
• slapd
•Configuration Files
• /etc/openldap/slapd.d
Trace Network Traffic (traceroute)
• The traceroute command is used in Linux to map the journey
that a packet of information undertakes from its source to its
destination. One use for traceroute is to locate when data loss
occurs throughout a network, which could signify a node that's
down.
• Because each hop in the record reflects a new server or router
between the originating PC and the intended target, reviewing
the results of a traceroute scan also lets you identify slow points
that may adversely affect your network traffic.
• Example
# traceroute www.google.com
Configure and Secure SSH
• SSH
• SSH stands for secure shell
provides you with an interface to the Linux system. It takes in
your commands and translate them to kernel to manage
hardware
pwd
$ bash
csh ksh
Hardware
#
ls cp
Kernel
Shell
• Ope
n Utilities
SSH
Configure and Secure SSH
• SSH itself is secure, meaning communication through SSH is always encrypted, but there
should be some additional configuration can be done to make it more secure
• Following are the most common configuration an administrator should take to secure SSH
Become root
Edit your /etc/ssh/sshd_config file and add the following line:
ClientAliveInterval 600
ClientAliveCountMax 0
# systemctl restart sshd
The idle timeout interval you are setting is in seconds (600 secs = 10 minutes). Once the
interval has passed, the idle user will be automatically logged out
Configure and Secure SSH
Disabling root login should be one of the measures you should take when setting
up the system for the first time. It disable any user to login to the system with root
account
Become root
Edit your /etc/ssh/sshd_config file and replace PermitRootLogin yes to no
PermitRootLogin no
# systemctl restart sshd
Configure and Secure SSH
You need to prevent remote logins from accounts with empty passwords
for added security.
Become root
Edit your /etc/ssh/sshd_config file and remove # from the
following line
PermitEmptyPasswords no
# systemctl restart sshd
Configure and Secure SSH
To provide another layer of security, you should limit your SSH logins to only
certain
users who need remote access
Become root
Edit your /etc/ssh/sshd_config file and add
AllowUsers user1 user2
# systemctl restart sshd
Configure and Secure SSH
By default SSH port runs on 22. Most hackers looking for any open SSH servers
will look for port 22 and changing can make the system much more secure
Become root
Edit your /etc/ssh/sshd_config file and remove # from the following line
and change the port number
Port 22
# systemctl restart sshd
Configure and Secure SSH
Usernam
e?
Password
?
Generate Copy over the Keys
Keys from client to Usernam
server e?
Password
Client = MyFirstLinuxVM SS ?
Step 1 — Generate the H
Key # ssh-keygen
• Cockpit is the easy-to-use, integrated, glanceable, and open web-based interface for
your servers
• The application is available in most of the Linux distributions such as, CentOS, Redhat,
Ubuntu and Fedora
• It can monitor system resources, add or remove accounts, monitor system usage, shut
down the system and perform quite a few other tasks all through a very accessible
web connection
Install, Configure and Manage Cockpit
• Check for network connectivity
• ping www.google.com
• What is Firewall
• A wall that prevents the spread of fire
• When data moves in and out of a server its packet information is tested against the
firewall rules to see if it should be allowed or not
• In simple words, a firewall is like a watchman, a bouncer, or a shield that has a set
of rules given and based on that rule they decide who can enter and leave
SSH = 22
Connection established
B
A
ftp = 21
Connection refused
B
A
Firewall (iptables – tables, chains and targets) 1/4
• Before working with iptables make sure firewalld is not running and disable it
• service OR systemctl stop firewalld = To stop the service
• systemctl disable firewalld = To prevent from starting at boot time
• systemctl mask firewalld = To prevent it from running by other programs
• To flush iptables.
• iptables -F
Firewall (iptables – tables, chains and targets) 2/4
1. tables = table is something that allows you to process packets in specific ways. There
are 4 different types of tables, filter, mangle, nat and raw
2. chains = The chains are attached to tables, These chains allow you to inspect traffic
at various points. There are 3 main chains used in iptables
INPUT = incoming traffic
FORWARD = going to a router, from one device to another
OUTPUT = outgoing traffic
• chains allow you to filter traffic by adding rules to them
• Rule = if traffic is coming from 192.168.1.35 then go to defined target
3. targets = target decides the fate of a packet, such as allowing or rejecting it. There are
3 different type of targets
ACCEPT = connection accepted
REJECT = Send reject response
DROP = drop connection without sending any response
Firewall (iptables – tables, chains and targets) 3/4
Table
chains Targe
t
chain
Practical:
• After making all the changes save the iptables. Again make sure firewalld is not running
• iptables-save = The file is save in
/etc/sysconfig/iptables
• Firewalld works the same way as iptables but of course it has it own commands
• firewall-cmd
• It has a few pre-defined service rules that are very easy to turn on and off
• Services such as: NFS, NTP, HTTPD etc.
• Start firewalld
• systemctl start/enable firewalld
• All services are pre-defined by firewalld. What if you want to add a 3rd party service
• /usr/lib/firewalld/services/allservices.xml
• Simply cp any .xml file and change the service and port number
Version of XML
Service
Service
Port
Description
Firewall (firewalld – Practical Examples) 2/3
• To remove a service
• firewall-cmd --remove-service=http
• To add a port
• firewall-cmd --add-port=1110/tcp
• To remove a port
• firewall-cmd --remove-port=1110/tcp
Linux system comes fined tunned by default when you install, however there are a few
tweaks
that can be done based on system performance and application requirements
What is tuned?
• To listtuned-adm list.
available profiles
Tune System Performance 5/8
Nice value is a user-space and priority PR is the process's actual priority that use by Linux kernel.
In
Linux system priorities are 0 to 139 in which 0 to 99 for real time and 100 to 139 for users
• Process priority can be viewed through ps command as well with the right options
$ ps axo pid,comm,nice,cls --sort=-nice
Tune System Performance (nice/renince)
8/8
• The term container and the concept came from the shipping container
• These containers are shipped from city to city and country to country
• No matter which part of the world you go to, you will find these
containers with the exact same measurements… YOU KNOW WHY???
• Because around the world all docks, trucks, ships and warehouses are built
to easily transport and store them
Run
Containers What is a Container?
Now when we are talking about containers in IT we are fulfilling somewhat similar
purpose
In old days… Applicatio
Production Server n
Applicatio
n
Developer
• Then came the container technology which allowed developers or programmer to test and build
applications on any computer just by putting it in a container (bundled in with the software code, libraries
and configuration files) and then run on another computer regardless of its architecture
• You can move the application anywhere without moving its OS just like moving the actual physical
container anywhere that would fit on any dockyard, truck, ship or
• warehouse
An OS can run single or multiple containers at the same time
Run
Containers What is a Container?
Now when we are talking about containers in IT we are fulfilling somewhat similar
purpose
In old days… Please Note: Application
Production Server
Container technology is mostly used by developers or programmers
Application
• Then came the container technology which allowed developers or programmer to test and
As a system administrator your job is to install, configure and
build applications on any computer just by putting it in a container (bundled in with the software
manage them.
code, libraries and configuration files) and then run on another computer regardless of its
architecture
• You can move
container the application
anywhere that wouldanywhere
fit on anywithout moving
dockyard, truck,itsship
OS or
just like moving the actual
physical
• warehouse
An OS can run single or multiple containers at the same time
Run
Containers
What are the Container Software?
Red Hat provides a set of command-line tools that can operate without a container engine, these include:
• podman - for directly managing pods and container images (run, stop, start, ps, attach, etc.)
• buildah - for building, pushing, and signing container images
• skopeo - for copying, inspecting, deleting, and signing images
• runc - for providing container run and build features to podman and buildah
• crun - an optional runtime that can be configured and gives greater flexibility, control, and security for
rootless
containers.
Getting Familiar with podman Container Technology
When you hear about containers then you should know the following terms as well
• images – containers can be created through images and containers can be converted to images
• pods – Group of containers deployed together on the host. In the podman logo there are 3 seals grouped
together as a pod.
Run
Containers
Building, Running and Managing Containers
To install podman
• yum/dnf install podman –y
• yum install docker –y (For dockers)
Getting help
• podman -–help or man podman
• With the help of kickstart you can automate questions that are asked
during the installation. e.g.
• Language and time zone
• How the drives should be partitioned
• Which packages should be installed etc.
Kickstart (Automate Linux
Installation)
• Purpose?
Kickstart (Automate Linux
Installation)
• To use Kickstart, you must:
1. Choose a Kickstart server and create/edit a Kickstart file
2. Make the Kickstart file available on a network location
3. Make the installation source available
4. Make boot media available for client which will be used to begin the
installation
5. Start the Kickstart installation
1 4
3 Kickstar
5
t config
file
ISO
2
Kickstart server Client
ISO
• CentOS/Redhat 8
• There is no GUI available to edit the file
• Why changed?
• Most systems are virtual and templates can be used
• Automation software are in used such as Anisble.
Kickstart (Automate Linux
Installation)
• Step by step procedure for Kickstart
4. Start the kickstart file configurator and define parameters OR use the /root/anaconda-
ks.cfg
• system-config-kickstart (To start the configurator)
• We will use anaconda installation kickstart file and change the hostname only
5. Make sure httpd package is installed, if not then install the package and start the httpd service
• rpm –qa | grep http
• yum/dnf install httpd
• systemctl start httpd
• systemctl enable httpd.
Kickstart (Automate Linux
Installation)
6. Copy kickstart file to httpd directory and change the permissions
• cp /root/anaconda-ks.cfg /var/www/html
• chmod a+r /var/www/html/anaconda-ks.cfg
• systemctl stop|disable firewalld
• Check file through browser on another PC http://192.168.1.x/anaconda-ks.cfg
9. Hit Esc
10. boot: linux ks=http://192.168.1.x/anaconda-ks.cfg
For NFS boot: linux inst.ks=nfs:192.168.1.x:/rhel8
Where:
ksdevice = is the network adapter of the client
IP = IP you are assigning to the
client
netmask = Subnet mask for the client
gateway = Gateway IP address for the
client
DHCP
In this video I will show you how to setup DHCP server conceptually
because if you want to setup DHCP server on your Linux machine then
you will have to re-configure your router/modem in your home which can
route DHCP traffic to your new DHCP server.
Reconfiguring router/modem will make all your devices at home lose the
network connectivity
• Wait a second…
• Right now in our home how IPs are assigned to our devices?
• Answer The router or gateway given to you by your ISP provider
• How IPs are assigned in corporate world?
• Answer Dedicated routers run DHCP service to assign IPs on the network
DHCP
Step by steps instructions
• Pick a server to be your DHCP and take a snapshot