Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Saturday, 9 April 2016

Using Advanced Intrusion Detection Environment (AIDE) to monitor changes in Linux

System integrity is put at risk when configuration files are deleted or modified without authorization or careful supervision. How can a change to an important file or directory be detected  ? This problem is solved by using AIDE.
AIDE (Advanced Intrusion Detection Environment) is a file and directory integrity checker.It creates a database from the regular expression rules that it finds from the config file(s). Once this database is initialized it can be used to verify the integrity of the files. It has several message digest algorithms that are used to check the integrity of the file. All of the usual file attributes can also be checked for inconsistencies. I am going to demonstrate how AIDE can be used to monitor the changes in Linux.

To configure AIDE, you need to install the AIDE package into your server. install package using yum or rpm commands.
























Once the software  is installed, it needs to be configured. The /etc/aide.conf file is the primary configuration file for AIDE. it has 3 types of configuration directives: configuration lines, selection lines, and macro lines.

Configuration lines take the form, param=value. when param is not a build-in AIDE setting. then this is a group definition that list which changes to look for. For example , the following group definition can be found in the /etc/aide.conf  installed by default.

PERMS = p+i+u+g+acl+selinux

The line above defines a group called PERMS that looks for changes in the file permission(p) , inode (i) ,user ownership (u) , group ownership (g), ACLs (acl), or SELinux context (selinux).

Selection lines define which checks are performed on matched directories. The following lines are examples of selection lines:
/dir1 group
=/dir2 group
!/dir3 group

The first line performs the group of checks on /dir1 and all of the files and directories below it. The second line performs the group checks specified on /dir2. The equal sign specifies the check is to be done the directory only and does not recurse below it. The third line in the example above excludes /dir3 and all of the files below it from any checks.

The third type of directives are macro lines. They define variables and their definition has the following syntax
@@define VAR value

@@{VAR} is the reference to the macro defined above.

Now let us configure the AIDE to monitor change. for making it simple i just removed few lines from the aide.conf . I just want to monitor only the changes in /etc directory. That's my requirement for now.






























Execute the aide --init command to initialize the AIDE database. AIDE will scan the file system and record all of the current information about the files and directories specified in the /etc/aide.conf configuration file.










The above command create the database in a file called /var/lib/aide/aide.db.new.gz. This file has to be renamed to /var/lib/aide/aide.db.gz because this is where AIDE expects the database to be when performing file system checks.
It is recommended to copy /var/lib/aide/aide.db.gz to another system or location. as this is the reference file which is used to check the changes.






To check how the AIDE track and monitor the changes. lets change the permission of /etc/passwd file and check how AIDE check









Now lets check the changes using the following command. aide --check this will check the current permission in the system with the recorded permission in the  AIDE database file. You could see that AIDE found a differences between database and filesystem, and it also tell you what changes has been done and what was the original permission. Its pretty useful right, Now we dont have to break our heads or check with the similar system to know what the original permission associated with this file.







































That's all friends, Using this tool you could track all the changes in the Linux. and  Its pretty easy too.!
I will be coming up with few more interesting articles on Linux, till then stay tuned to Learn linux and don’t forget to add your valuable comments.

Tuesday, 23 December 2014

Configuring Network Teaming using nmcli in RHEL 7.0

Network teaming is a method for linking NICs together logically to allow fail-over or higher throughput. Teaming is a new implementation that does not affect the older bonding driver in linux kernel; it offers an alternate implementation.

RHEL7 support the standard channel bonding for backward compatibility ( for more information on channel bonding click here ). Network teaming provides better performance and is more extensive because of the modular design.

RHEL 7.0 implement network teaming with a small kernel driver and a small user space daemon called "teamd". The kernel handles network packets efficiently and teamd handles logic and interface processing. Software, called runners, implement load balancing  and active backup logic, such as round robin. the following runners are available to teamd.

broadcast    : A simple runner which transmits each packet from all ports.
roundrobin : A simple runner which transmits each packets in a round-robin fashion from each of its ports.
activebackup: This is a failover runner which watches for link changes and select an active port for data transfer.
loadbalance: This runner monitor traffic and uses a hash function to try to reach a perfect balance when selecting ports for packet transmission.
lacp  : Implement the 802.3ad Link Aggregation Control Protocol. can use the same transmit port selection possibilities as the loadbalance runner.

Now let me show you how to configure teaming in RHEL 7.0.
Decide which interfaces that you would like to configure a Team interface.
run ip link  command to check the available interface in the system.

Here i am using eno33554992 and eno50332216 NICs to create a team interface in activebackup mode.
Use nmcli command to create a connection for the network team interface,with the following syntax.

#nmcli con add type team con-name CNAME ifname INAME [config JSON]

Where CNAME will be the name used to refer the connection ,INAME will be the interface name and  JSON (JavaScript Object Notation) specifies the runner to be used. JSON has the following syntax:

'{"runner":{"name":"METHOD"}}'

where METHOD is one of the following: broadcast, activebackup, roundrobin, loadbalance or lacp.

Now let me create the team interface. here is the command i used to create the team interface.
 

run #nmcli con show command to verify the team configuration.

Now lets add the slave devices to the master team0. here is the syntax for adding the slave devices.

#nmcli con add type team-slave con-name CNAME ifname INAME master TEAM

Here i am adding eno33554992 and eno50332216 as slave devices for team0 interface.


Verify the connection configuration using  #nmcli con show again. now you could see the slave configuration.



All the above command will create the required configuration files under /etc/sysconfig/network-scripts/.
[root@foundation ~]# ll /etc/sysconfig/network-scripts/ifcfg-team0*
-rw-r--r--. 1 root root 333 Dec 24 03:30 /etc/sysconfig/network-scripts/ifcfg-team0
-rw-r--r--. 1 root root 312 Dec 24 03:37 /etc/sysconfig/network-scripts/ifcfg-team0-port1
-rw-r--r--. 1 root root 312 Dec 24 03:37 /etc/sysconfig/network-scripts/ifcfg-team0-port2
[root@foundation ~]#


Lets assign an IP address to this team0 interface and enable the connection now. Here is the command to perform the IP assignment.

#nmcli con mod team0 ipv4.addresses "192.168.1.24/24 192.168.1.1"
#nmcli con mod team0 ipv4.method manual
#nmcli con up team0




Verify the IP address information in #ip add show team0 command.



Now lets check the activebackup configuration functionality. using the teamdctl command.
# teamdctl team0 state 



Now lets disconnect the active port and check the state again. to confirm whether the active backup configuration is working as expected.
#nmcli dev dis eno50332216


disconnected the active port and now check the state again using #teamdctl team0 state





Yes its working as expected. !!  you could connect the disconnected connection back to team0 using the following command.
#nmcli dev con eno50332216


we have one more command called teamnl let me show you some options with teamnl command.
to check the ports in team0 run the following command.
# teamnl team0 ports


Display currently active port of team0.
# teamnl team0 getoption activeport

There are many options , i would recommend to use manpages to get more information on teamnl and teamdctl command.
Hope this article is useful to you .share your feedback if any .