Linux Unit 3
Linux Unit 3
com
0
Acuity Educare
LINUX SYSTEM
ADMINISTRATION
SEM : V
SEM V: UNIT 3
• Red Hat Enterprise Linux provides services on the Internet. That means that unauthorizedusers
will try to attack our server and try to get access. To prevent this, we need to install a firewall.
• Netfilter is the default firewall in Linux. To configure Netfilter on Red Hat Enterprise Linux, you can
use the system-config-firewall graphical tool or iptables in command line Interface.
• There are two main configuration files for netfilter firewall that are stored in the directory
/etc/sysconfig.
• In the file iptables, you’ll find all the rules that you’ve added to the firewall.
• In the file iptables-config, the configuration of the firewall is stored
1. From the GNOME graphical interface, select System Administration Firewall or system-config-
firewall from shell.
2. From the list of trusted services, select DNS, FTP, SSH, and WWW, and click Apply to save the
configuration.
3. Close system-config-firewall, and open a shell prompt.
4. Display the current status of the iptables service in the runlevels on your server.
# chkconfig | grep iptables
7. If service is not enabled for the current session then start it.
# service iptables start
Page 1 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
• The major benefit of using masquerading is that with just one public IP address, you can connectmany
devices on the private network to the Internet.
• To enable masquerading, you need to select the public interface. Once this interface is masqueraded, all
packets are rewritten with the IP address of the publicinterface as the source address.
To trace the packet back to its original sender, the NAT router maintains a NAT table. A port address is used
to trace every connection in this NATtable.
• We can also use port forwarding in combination with masquerading. This means you assign a port on
the public interface of the NAT router and forward everything thatcomes in on that portto a specific
host and port on the private network.
• We can use thisapproach if one of the computers on the private network is not directlyreachable from
theInternet.
3. Click Port, and in the Port and Protocol window that opens, select User Defined.
4. Enter port 3333, and click OK.
Page 2 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
5. In the destination part of the Port Forwarding window, select Forward To Another Port. Enterthe IP
address that is used by HTTP Server machine, and from the Port list, select port 80.Click OK to
save the configuration. Next click Apply to apply the configuration to the firewall.
6. On the host computer, type # iptables -L -v and verify that you see a line with the IP address
192.168.1.1as its destination in the Forward chain. This is the packet forwarding rule.
• Interface On a server with multiple network cards, it makes sense to apply rules to specific interfaces
only. However, if you’re configuring your firewall on a server withone network card only, you can omit
the interface specification.
• IP Addresses In a rule, you can allow or deny access to specific IP addresses or IP networkaddresses.
• Protocol Most rules allow or deny access to specific ports. These ports are always connected to the UDP
or TCP protocol. Therefore, if you want to state a specific port, you alsoneed to indicate the protocol
that is to be used.
• Target The target is a mandatory component in a rule. A target specifies what needs to be done with a
matching packet. Different targets can be used, of which ACCEPT,DROP, REJECT, and LOG are the most
important.
Apart from these common elements found in rules, you need to specify the purpose of the rule. If viewed
generically, there are two options: either you can set a policy or you can add a ruleto a chain.
A policydefines the default behavior. If no specific rule is found in the chain that matches an incoming
packet, the policy is applied. It is always good practice to define a policy that deniesall access.
If you use -A to append a rule, it is entered at the last position in the chain. However, if you use
Page 4 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
-I to insert a rule, you can specify where exactly in the chain you want to insert it.
Use the command iptables -t nat -L to verify that the rule is in effect:#/sbin/iptables -L -t nat
1. iptables Logging
2. Limit module
1. iptables Logging
• If you need to know exactly what is happening in your firewall, the LOG target can be used butmake
sure it doesn’t log too much, otherwise during a ping flood attack your log files will be flooded with
useless information.
1. Determine on which line in the INPUT chain SSH traffic is allowed. For example line 4.
# iptables -L -v --line-numbers
3. Open an SSH session and run some commands, such as ls and who.
4. Use less /var/log/messages, and use G to go to the end of the file. Check log lines added tothe log
file.
Page 5 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
• When using logging, numerous lines are written to the log files. On an active system, the number
of lines logged can be so high that your log files will suffer a denial-of-service attack,and nothing
further will be readable.
• To protect yourself against this, you can use the limit module. This module allows you to jumpto a
target if a certain number of packets have been matched within a specific period of time.
• For example, if you want to limitthe number of packets logged to one per second for all SSHtraffic,
use the following line:
# iptables -I INPUT 3 -p tcp --dport 22 -m limit --limit 1/s -j LOG
• Network Address Translation (NAT) is a common technique that can be used on routers to allow
computers on the private network go out with one registered IP address on the public network.
• We can use NAT for three purposes:
I. To change the source IP address to the IP address of the firewall before it is sent to the Internet, you
need the MASQUERADE target.
II. To change the source IP address of a specific host to the IP address of the firewall before it is sent
to the Internet, you need the SNAT target.
To redirect traffic that is sent to a specific IP address and port on the public IP address to anIP address and
port on the private network, you need the DNAT target
(1) A packet targeted at IP address 1.2.3.4:80 comes on the NAT router. This packet has to besent tothe
web server that listens at IP address 10.0.0.10 on the internal network.
(2) The packet is processed by the firewall. To make sure DNAT is used to send the packet to the web
server,use this command: iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE. Youalso need to
enable routing (echo 1 > /proc/sys/net/ipv4/ip_forward) and set the policy for the routing chain to ALLOW:
iptables -P FORWARD ALLOW.
(3) Because of the rule in the PREROUTING chain of the NAT table, here the packet can be
delivered to the web server.
Page 6 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
(4) The web server sends back the answer. However, the source address of the web server isused in
the answer, and this address is unknown on the Internet.
(5) Thus, a masquerading rule must be defined.
The masquerading rule makes sure that the source IP address is changed to the source IPaddressof the
NAT router, which allows nodes on the Internet to send the packet back tothe appropriate destination.
I. PREROUTING
II. POSTROUTING
III. OUTPUT
• In PR EROUTING, packets are processed before the routing decision is made. This chain istypically
used for incoming packets where the destination address has to be rewritten, whichhappens in
DNAT.
• In SNAT and MASQUERADE, the source IP address must be rewritten, and that needs tobe done
after the routing process has been applied. Therefore, the SNAT and MASQUERADE rules are
added to the POSTROUTING chain.
•
To enable any kind of Network Address Translation, host must be configured for packet
forwarding. By default, the Linux kernel doesn’t allow packet forwarding. To make sure thatyour
computer can do packet forwarding, check that the /etc/sysctl.conf file contains the following
line:
net.ipv4.ip_forward = 1
Steps to Configure NAT:
1. one router machine Use iptables -F, iptables -P INPUT ALLOW, iptables –P OUTPUT ALLOW,
and iptables -P FORWARD ALLOW. Next use service iptables save to save thisconfiguration.
2. Repeat step 1 on the host computer, and use service httpd stopthen chkconfighttpd
off to make sure the web server is stopped on the host computer.
3. On the host computer, enable routing by opening /etc/sysctl.conf with an editor.
Make sure it includes the line net.ipv.ip_forward = 1, and use sysctl -p to thesysctl service tomake
the change effective.
masquerading.
6. On another computer connected to the same network as your RHEL host, test thatyou canreach
the HTTP port on the host.
After verifying that this works, restart both the host computer and the virtualmachine to clear theNAT
configuration
Q. What is SSL ?
• For many services on servers additional security is required. By applying this security, we can make
sure that traffic to the server isencrypted and the identity of the server is guaranteed. To achieve this
level of security,we can use SSL (Secure Socket Layer).
1. When the connection to the server is first initialized, the server sends its public key(PKI)certificate.
This contains the public key of the server, and it is signed with theprivate key of the certificate
authority (CA).
2. The client use public key of CA to verify that the PKI certificate can be trusted.
3. Now that the connection is trusted, a symmetric session key is generated by the client and sentto
server. The data traffic is encrypted with this session key for performance reasons.
4. Because public/private key encryption is one-way encryption, only the server is capableof
decrypting the traffic by using its private key
Page 8 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
o crl: A certificate revocation list (CRL) is a list of certificates that are invalid. If you need to revoke
certificates, copy them to this directory.
Page 9 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
2. Execute genkey command with servername. This command automatically places the resultingPKI
certificate and private key in the correct directories, which are /etc/pki/tls/private and
/etc/pki/tls/certs.
3. Select the key size you want to use. The default key size is set to 1024. If you need a highersecurity
level, you canselect a bigger key size, but by doing that you will slow your system.
4. Move the mouse and type some command to help system generate some random bits that are
necessary to produce the key.
5. Once the key is generated, genkey asks whether you want to create a certificate signingrequest. For
self-signed certificate click No.
• If you click yes then after creating the certificate signing request, send this request to the CA. Once you
receive the signed certificate back, you can copy it to the /etc/pki/tls/certs directory and tell your
application to use the signed certificate.
6. Set a passphrase for the private key. It is a good idea to protect your private keys with a passphrase, so
select Yes and set a passphrase that is difficult to guess. The longer the passphrase, the harder itgets to
guess its value af ter a private key has become compromised.
Page 10 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
After you enter the appropriate identification, the public and private keys are written to the appropriate
directories and are ready for use
Q. What is GNU Privacy Guard? Give steps for creating and exchanging GPG keys.
• PKI certificates and SSL are primarily used with web servers; another way to protect files is byusing
GNU Privacy Guard (GPG).
• GPG is commonly used in email communication,and it is also used to encrypt and decrypt filesso that
they can be securelytransported.
Step 1: Create two users named linda and lisa, and give them the password.
Step 2: Log in to the graphical interface as user linda, and create a GPG pair. Accept all default values,
and assign the password password12 to theprivate key. When the gen-key program tellsyou to generate
entropy, use ls -R / acouple of times to get you through the procedure faster. gpg --gen-key
Step 3: Repeat step 2 for user lisa, and use the same parameters.
Step 4: As linda, expor t public key (key transfer) to the /tmp directory.
Page 11 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
Step 6: As lisa, show that the key has been impor ted correctly.
gpg --list-keys
Q. How to Encrypt Files with GPG?
# su - linda
cp /etc/hosts ~
Step 3: List the keys currently imported in Linda’s environment, and note the exact name of theuser
lisa.
gpg –listkeys
Step 4: Encrypt the file hosts, when the user account is requested, enter the exact name of user lisa as
you found it in the previous step of this exercise. Nextpress Enter on an empty line to complete the
encryption procedure.
gpg -e hosts
Step 5: Copy the gpg file to the tmp directory where lisa can seeand read it.
cp ~/hosts.gpg /tmp
Step 6: Use exit to log out as linda, and become user lisa.
Page 12 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
exit
su – lisa
gpg -d /tmp/hosts.gpg’
Q. Why is it required to sign GPG file or RPM? Which commands are used for Signing?
• The purpose of signing is to provide proof that something has actually been transmitted by the
intended sender.
• To sign data, the user’s private key is used. The signing process adds a digital signature to a
message or file. If the receiver of the message has the public key of the sender in their GPG ring,
this can automatically prove that the message actually comes from the intended sender.
• The procedure of signing is used in email communications and to sign RPM files.
• If we’ve received a file that is signed with GPG, you can use gpg -d to open it.
If we have the public key of the sender on your system, it will automatically be opened. If you don’t
have the public key, that means you cannot verify the signature of the file, but you still areable to open
it.
• Network File System (NFS), is the most common method for providing file sharing services onLinux
networks.
• It is a distributed file system that enables local access to remote disks and file systems.
• NFS uses standard client/server architecture.
• The server has physical disks with shared file systems and several daemons that make the shared file
systems avialble on network. This process is normally referred to as exportinga file system.
• NFS clients mount the exported file systems, called NFS mounts.
NFS advantages
Page 13 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
NFSv4 offers the option to make a pseudo-root mount, which allows users to mount everything to
which they have access by issuing one mount only.
NFS disadvantages
1. Performance
• As a distributed, network-based file system, NFS is sensitive to network congestion. Heavy
network traffic slows down NFS performance. Similarly, heavy disk activity on the NFS server
badly affects NFS’s performance.
3. Security
• NFS design assumes a trusted network.
• Data is sent over network using RPC, remote procedure calls in plain text.
The export options determine the characteristics of the exported file system.
Option Description
Ro Exports the file system read-only, disabling any operation thatchanges the
file system
Page 14 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
sync Forces the server to perform a disk write before the request is
considered complete
async Allows the server to cache disk writes to improve performance
Secure Requires client requests to originate from a secure (privileged) port,that is,
one numbered less than 1024
root_squash Maps all requests from a UID or GID of 0 to the UID or GID of the
anonymous user (-2 in Red Hat Linux)
no_root_squash Disables root_squash
all_squash Maps all requests from all UIDs or GIDs to the UID or GID of the
anonymous user
no_all_squash Disables all_squash
anonuid=uid Sets the UID of the anonymous account to uid, default uid of
anonymous user is -2
anongid=gid Sets the GID of the anonymous account to gid, default gid of
anonymous user is -2
1. /usr/local *.example.com(ro)
• line permits all hosts with a name of the format somehost. example.com to mount
/usr/local.
2. /home 192.168.0.0/255.255.255.0(rw)
• permits any host with an IP address in the range 192.168.0.0 to 192.168.0.255 to mount
/home
3. /var/tmp 192.168.0.1(rw)
# mkdir /data
Step 2: Make sure incoming users have permissions on the shared directory.
Page 15 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
Step 3: Use vi editor to open the file /etc/exports, and inser t the following line of code to share the
# vi /etc/exports
/data *(rw,no_root_squash)
# chkconfig nfs on
# showmount -e localhost
Step 7: After creating the NFS share, make sure it is accessible through the firewall. Allow NFSaccess
by opening port 2049 in the firewall.
Step 1: Display names of directories that are shared by the NFS server.
# showmount -e nfsServer
Step 2: Mount the share on the local /mnt directory. (Temporary Mount)
Or
Step 2: Mount the NFS share in /etc/fstab (Permanent Mount/ persistent mount)#
mkdir /data
Page 16 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
# vi /etc/fstab
• Where,
_netdev = This option ensures that your system waits until the network is up before making thismount
# mount
OR
Step 2: Open /etc/auto.master with vi editor, and include the following line:# vi
/etc/auto.master
/data /etc/auto.data
# vi /etc/auto.data
Step 5: Next use # cd /data and enter the # ls command. You’ll see no subdirectories.
Page 17 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
Now use # cd files to activate the /data subdirectory files. You are in the /data/filesdirectory now, and
you’ll see the contents of the /data share on the NFS server.
NFS protocol is native to linux system Smb protocol add the SMB/CIFS (server message
block/common internet file system) file sharing
protocol to linux and unix which is native to windows.
NFS uses its own protocol called "NFS" Samba uses the SMB protocol which is
which is not commonly available for PCs considered "standard" for PCs
NFS by default trusts all client machines Samba's SMB protocol allows the server machineto
completely. once an NFS server configured to handle authentication i.e client machine must provide
accept connections from a client machine the username and password to connect to samba server.
client does not require
(server side authentication)
any further server-side authentication. (no
server side authentication)
Share filesystem between linux machines Share filessystem between Linux and
windows/linux machines.
NFS has four versions, the newest NFSv4 Samba has multiple versions, the latest of which
includes a stateful protocol allows file and print sharing between multiple
computers
NFS is faster than samba Samba is slower than NFS.
• Samba service can be used for file sharing, printers sharing and windows domain services.
Page 18 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
Step 1: Create a directory on the Linux file system and grant the appropriate permissions to thisdirectory.
# mkdir /sambafiles
[sambafiles]
Step 5: Create a Samba account, which makes the Samba server accessible for the Samba users.
# useradd lucky
• Don’t set the password, because Samba users don’t need a password on the Linux system.
# smbpasswd -a lucky
Step 6: (re)start the Samba service and make sure that it starts on every server boots.
Page 19 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
# chkconfig smb on
Using share makes it easier to create anonymous shares that do not require authentication.
• When using this option, use theguest only parameter in the share.
• Never use it for shares that contain valuable data.
2. security = user
• This is the default security option, where a user must log in to the share before getting access.
3. security = domain
• This option works if your Samba server has been added to a Windowsdomain.
4. security = server
• This option uses an external server (such as another Samba server) to handle Samba
authentication requests. It is best to avoid using this, because it isn’t verysecure.
5. security = ads
This option makes Samba a member in a Windows Active Directorydomain. It makes it easier to access
resources in the AD domain or to set up access for AD users to resources in Samba
• On the Windows computer, double-click My Network Places icon from the desktop. In the network
places window we must see the listing for Redhat computer. Double-click the icon andwe see the
share we made available.
• We are prompted for username and password. Once provided, we can share file between Linuxand
Windows computers.
Page 20 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
1. There are some tools that we can use to access Samba shares on Linux likeNautilus, toconnect
to a Samba share.
2. To list the Samba shares that are offered by a specific server, you can use # smbclient –L
• This shows the names of all shares that are offered, and it also provides an option to log intothe
Samba server.
3. We can mount the Samba share into the local file system using mount command.
4. Mounting a Samba Share Using /etc/fstab
• When putting a Samba share in /etc/fstab, we’ll also need to include the usernameandpassword
required to gain access to the share.
• Add a credentials file and specify a user and password for every Samba user.
• Keep this file in a secure place that’snot accessible to all users.
Step 1: On the client computer, use # smbclient -L //yoursambaserver to list the Samba shareson your
Samba server.
• user=lisa
• password=secret
• user=lucky
• password=word
• Samba and NFS are used in localnetwork environments. FTP is a good solution for offering fileaccess
over the Internet.
• On Red Hat Enterprise Linux, vsftpd is the preferred FTP server.
• Deploying vsftpd to offer access to shared files is easy.
• The configuration file /etc/vsftpd.conf contains many settings.
Page 21 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622
TRAINING -> CERTIFICATION -> PLACEMENT BSC IT : SEM - V : LINUX – U3
Page 22 of 22
YouTube - Abhay More | Telegram - abhay_more
607A, 6th floor, Ecstasy business park, city of joy, JSD road, mulund (W) | 8591065589/022-25600622