Tuesday, 9 December 2014

How to Install ClamAV and Configure Daily Scanning on Linux





This article will guide you through the installation of ClamAV on Linux based system. Once installed, we will also configure a daily scan on our Linux based server.
ClamAV is an open source (GPL) antivirus engine designed for detecting Trojans, viruses, malware and other malicious threats on Linux. In this article, we will only be configuring ClamAV to run scheduled/on-demand scans; not resident scans.

A. Install ClamAV

1. Install EPEL repo

Before we can do proceed, you must ensure that you have the EPEL yum repository enabled.

2. Install required ClamAV packages

1 yum install clamav clamd

3. Start the clamd service and set it to auto-start

1 /etc/init.d/clamd on
2 chkconfig clamd on
3 /etc/init.d/clamd start

4. Update ClamAV’s signatures

1 /usr/bin/freshclam
Note: ClamAV will update automatically, as part of /etc/cron.daily/freshclam.

B. Configure Daily Scan

In this example, we will configure a cronjob to scan the /home/ directory every day:

1. Create cron file:

1 vim /etc/cron.daily/manual_clamscan
Add the following to the file above. Be sure to change SCAN_DIR to the directory that you want to scan:
1 #!/bin/bash
2 SCAN_DIR="/home"
3 LOG_FILE="/var/log/clamav/manual_clamscan.log"
4 /usr/bin/clamscan -i -r $SCAN_DIR >> $LOG_FILE
Give our cron script executable permissions:
1 chmod +x /etc/cron.daily/manual_clamscan
You can even run the above script to ensure that it works correctly.
And you’re done! That should be the minimum required to
1. install ClamAV and 2. Perform a daily scan of a specific directory.

Sunday, 7 December 2014

Linux: Comparing packages on two servers and installing the difference.




Linux: Comparing packages on two servers and installing the difference.



I know this isn’t Oracle related but if you have a position in a small company like myself, chances are you are performing more than DBA duties.   We just recently hired a linux admin but he’s on vacation this week and there’s a new server to stage for a Portal environment.

In the past I have just run system-install-packages on an existing server and the new one and compare the packages.   Time consuming, error prone, etc.  Also, any patches not installed from the base system packages won’t be captured.

Given those reasons I decided to use the command line.   If you have done something similar in the past and have a better way of doing it feel free to leave a comment.

Step 1:  Get a list of RPM packages from both servers:


rpm -qa --qf "%{NAME}\n” | sort > rpms_newserver.txt



Do the same on the second server.    Since the packages may not have been installed in the same order, 
I pipe it to sort, otherwise I believe it would cause problems with the next step.



The rpms_newserver.txt document will have a listing of files, ex:

a2ps
acl
acpid
alacarte
.
.
.

zsh


Step 2: Put both package lists in the same directory on the new server and run the linux command diff to compare the files.

diff rpms_oldserver.txt rpms_newserver.txt | grep "<" > package_list.txt

The diff command compares two files and displays the differences.   To get a list of the lines missing from the rpms_newserver.txt file we grep for the less than arrow “<” and pipe it to a new file. 

Step 3: The package_list.txt document is in the same format as the files in step 1.   Next I used vi to insert the yum command into the file so it can be executed like a script.

Open the package_list.txt file with vi and type:

:1,$s/< /yum install -y /g

Save the document and now it looks like:

yum install -y a2ps
yum install -y alacarte
yum install -y alchemist



Step 4:

Execute the package_list.txt document:

sh package_list.txt

That’s it, once it finishes all the packages should be installed.

DHCP server Configuring in Solaris





A Dynamic Host Configuration Protocol (DHCP) server leases IP address to clients connected to the network and has DHCP client enabled on their network interface.
Before we can setup a start the DHCP server we need to install DHCP configuration packages. Detail information about installing packages in provided in recipe of chapter 1. But to save the time we can use the following command to install the packages.

 # pkg install SUNWdhcs


After installing these packages we can continue with the next step.
How to do it…
First thing to setup the DHCP server is creating the storage and initial settings for the DHCP server. Following command does the trick for us.

 # dhcpconfig -D -r SUNWfiles -p /fpool/dhcp_fs -a 192.168.2.254 -d domain.nme -h files -l 86400


In the above command we used several parameters and options, each one of these options are explained below.
  • The -D specifies that we are setting up a new instance of the DHCP service.
  • The -r SUNWfiles specifies the storage type. Here we are using plain-text storage while SUNWbinfiles and SUNWnisplus are available as well.
  • The -p /fpool/dhcp_fs specifies the absolute path to where the configuration files should be stored.
  • The -a 192.168.2.15 specifies the DNS server to use on the LAN. We can multiple comma separated addresses for DNS servers.
  • The -d domain.nme specifies the network domain name.
  • The -h files specifies where the host information should be stored. Other values are nisplus and dns.
  • The -l 86400 specifies the lease time in seconds.
Now that the initial configuration is created we should proceed to the next step and create a network.

 # dhcpconfig -N 192.168.2.0 -m 255.255.255.0  -t 192.168.2.1


Parameters we used in the above command are explained below.
  • The -N 192.168.2.0 specifies the network address.
  • The -m 255.255.255.0 specifies the network mask to use for the network
  • The -t 192.168.2.1 specifies the default gateway
All configurations that we created are stored in DHCP server configuration files. We can manage the configurations using the dhtadm command. For example to view all of the current DHCP server configuration assemblies we can use the following command.
 # dhtadm -P


This command’s output is similar to the following figure.

Each command we invoked previously is stored as a macro with a unique name in the DHCP configuration storage. Later on we will use these macros in subsequent commands.
Now we need to create a network of addresses to lease. Following command adds the addresses we want to lease.
 # pntadm -C 192.168.2.0


If we need to reserve an address for a specific host or a specific interface in a host we should add the required configuration to the system to ensure that our host or interface receives the designated IP address. For example:

 # pntadm -A 192.168.2.22 -f MANUAL -i 01001BFC92BC10 -m 192.168.2.0 -y 192.168.2.0

In the above command we have:
  • The -A 192.168.2.22 adds the IP address 192.168.2.22.
  • The -f MANUAL sets the flag MANUAL in order to only assign this IP address to the MAC address specified.
  • The -i 01001BFC92BC10 sets the MAC address for the host this entry assigned  to it.
  • The -m 192.168.2.0 specifies that this host is going to use the 192.168.2.0 macro.
  • The –y asks the command to verify that the macro entered actually exists.
  • The 192.168.2.0 Specifies the network the address is assigned to.
Finally we should restart the DHCP server in order for all the changes to take effect. Following command restarts the corresponding service.

  # svcadm restart dhcp-server


When we setup the DHCP service, we store the related configuration in the storage of our choice. When we start the service, it reads the configuration from the storage and wait dormant until it receives a request for leasing an IP address. The service checks the configuration and if an IP was available for lease, it leases the IP to the client.
Prior to leasing the IP, DHCP service checks all leasing conditions like leasing a specific IP address to a client to ensure that it leases the right address to a client, etc.
We can use the DHCP Manager GUI application to configure a DHCP server. The DHCP manager can migrate the DHCP storage from one format to another. To install the DHCP manager package we can use the following command.

 # pkg install SUNWdhcm

Now we can invoke the DHCP manager using the following command which opens the DHCP Manager welcome page shown in the following figure.

 # dhcpmgr