Saturday, December 19, 2015

SETTING UP A LAN NETWORK in LUBUNTU using Webmin

SETTING UP A LAN NETWORK

In this module, we have created a Local Area Network.

Toolkit Used:

Workstation Operating System
Lubuntu 15.04
External Network Interface Cards
Quantity
1
Manufacturer
TP-LINK
Model Number
TF-3200
Switches
Quantity
1
Manufacturer
D-LINK
Model Number
DES-10008A


Below are the steps followed while setting up a LAN.

1.    Install DHCP Server:

Installedisc-dhcp-server to maintain server setup and configuration.
$ sudo apt-get install isc-dhcp-server.

2.    Install webmin:

            Installed webmin to configure and maintain theDHCP server.
a.     Installed required dependencies:
$ sudo apt-get install perl libnet-ssleay-perl libauthen-pam-perl libpam-runtime openssllibio-pty-perl apt-show-versions python.
b.     Downloaded Webmin:
$ wget http://prdownloads.sourceforge.net/webadmin/webmin_1.770_all.deb
c.     Installed Webmin:
$ sudo dpkg --install webmin_1.770_all.deb


3.    Renaming Network Cards

In the current workstation, eth1 is connected to the MSIT LANand eth0 is the external NIC which is going to be used for setting up a LAN for IS specialization purposes. So, for the better understanding and avoidconfusion, we have renamed eth1 to WAN and eth0 to LAN.

$ sudo leafpad /etc/udev/rules.d/70-persistent-net.rules










4.    DHCP & LAN Configuration

             I.        Editing Network Interfaces:
Edited the network interfaces in order to configure the eth0
$ sudo leafpad /etc/network/interfaces




















           II.        Check IP Configuration
Check the IP Configuration  of both LAN and WAN after editing interfaces.
            $ sudo ifconfig


















          III.        Listen for DHCP request
Because there is more than one network card in our workstation, we need to select the network card (WAN) on which our server will be listen for DHCP request.
$ sudo leafpad /etc/default/isc-dhcp-server.

         IV.        Configure the DHCP server’s config file
Edit the dhcp.conf file in order to make changes according to our convenience.

$ sudo nano /etc/dhcp/dhcpd.conf










           V.        Enable IP Forwarding
Edit the sysctl.conf file to forward packets from WAN to LAN.
Uncomment IPV4 packet forwarding line.

$ sudo nano /etc/sysctl.conf










         VI.        Login to Webmin
After configuring all our requirements, login to webmin (https://localhost:10000/) using root account.























        VII.        Add Firewall Rules

a.   Enable MASQUERADE(NAT):

·         Select Networking in the left menu bar.
·         Select the Linux firewall from the Networking drop down menu.
·         Configure the Linux Firewall such that it should do the network address translation for WAN interface.
·         So, select “Do network address translation on external interface” for WAN.
·         Select the “Setup firewall” finally.
















b.   Save IP Table rules
After the above step, save the rules to iptables.up.rules file by clicking on ‘Apply changes’ in IP Tables.























c.   Observe IP Table Changes
Observe the changes made to the iptables.up.rules result in modification of /etc/network/interfaces file

$ sudo cat /etc/network/interfaces
















d.   Activate Network Interfaces
Make sure that both LAN and WAN is up and running. If in case anyone of the interfaces is down, activate it before proceeding.
















      VIII.        Listen to WAN Interface













         IX.        Start the DHCP Server

 
























5.   Results:

Three personal workstations are connected to the switch which is connected the DHCP Server. The DHCP server automatically allocates IP Addresses to them.

IP address
WorkStation Name
192.168.0.11
Kittu
192.168.0.12
H3M4
192.168.0.13
HR

Details can be observed in the screenshot.
            It is the result of system log file (/var/log/syslog).
           
            $ sudo tail -50 /var/log/syslog
           









Friday, July 24, 2015

How to return multiple values from a C function

#include
void fun(int ,int ,int *,int *,int *);
int main()
{
int a=30,b=20,sum,sub,pro;
fun(a,b,&sum,&sub,&pro);
print("%d %d %d\n",sum,sub,pro);
return 0;
}
void fun(int x,int y,int *s,int *su,int *mu)
{
*s=x+y;
*su=x-y;
*mu=x*y;
}

Ex: 2

#include

int main()
{
    int a=3,b=5;
    
    int *c=&a, *d=&b;
    
    int sum,avg;
     
     fun(c,d,&sum,&avg);
     
    printf("%d %d",sum,avg);
    getch();
    
}

int fun(int *a, int *b, int *s, int *avg)
{
    *s=*a+*b;
    *avg=(*a+*b)/2;
}


---------------------------------------

#include <stdio.h>
#include <conio.h>

/* This function returns an array of N even numbers */
int* getEvenNumbers(int N){
    /* Declaration of a static local integer array */
    static int evenNumberArray[100];
    int i, even = 2;
    
    for(i=0; i<N; i++){
        evenNumberArray[i] = even;
        even += 2;
    }
    /* Returning base address of evenNumberArray array*/
    return evenNumberArray;
}

int main(){
   int *array, counter;
   array = getEvenNumbers(10);
   printf("Even Numbers\n");
   for(counter=0; counter<10; counter++){
       printf("%d\n", array[counter]);
   }
   
   getch();
   return 0;




Wednesday, July 22, 2015

Can't create a workable moodledata directory in centos 7 for moodle

First, put all your web content data under /var/www/html/. However, Fedora does not allow Apache to write anything anywhere by default, unless you explicitly permit that. For that, proper file/directory permissions are required, but not enough. Fedora uses SELinux (Security Enhanced Linux) to provide more robust security, and it doesn't allow Apache to write anything by default too.
Now, for each file and/or directory which should be writable (for which you receive ... is not writableerrors) you should set unconfined_u:object_r:httpd_sys_rw_content_t:s0 SELinux label to tell SELinux that these files/directories are allowed to be modified by Apache. For example, to make/var/www/moodledata and /var/www/html/moodle/theme writable, you should run (you can use -R so that this lable is set recursively if these directories contain subdirectories which should be writable):
chcon -R unconfined_u:object_r:httpd_sys_rw_content_t:s0 /var/www/moodledata /var/www/html/moodle/theme
Now, you can run setenforce 1 and see if the webiste is working properly. This is the solution.
But, what about setenforce 0 command? This command changes SELinux mode into permissivemode. In this mode, SELinux doesn't prevent any activity and only generates error messages in system's audit logs. This is why you didn't receive error messages anymore. However, putting SELinux in permissive mode is NOT a proper solution to make things work, I used it to see if your problem is related to SELinux. And, setenforce changes SELinux mode temporarily (until next shutdown/reboot). setenforce 1changes the SELinux mode to the default one, which is enforcing mode in which SELinux does actually prevent un-allowed activities.
This is the workflow that I would suggest when setting up a new thing in Fedora:
  1. Put SELinux into Permissive mode (setenforce 0)
  2. Set up the system as you like and make sure that it works correctly as intended
  3. Put SELinux back to Enforcing mode (setenforce 1)
  4. See if your system is still working fine. If not, check for SELinux errors in system audit logs (/var/log/audit) and try to solve the errors appropriately (it usually involves changing file/directory SELinux lables, or changing SELinux boolean parameters). A more user friendly approach is to useSELinux Troubleshooter GUI application rather than inspecting audit logs. It shows SELinux related errors along with suggested solutions.
Notice that you can modify SELinux configuration file (/etc/selinux/config) to completely disable SELinux or permanently set it into Permissive mode, but please don't. While many will suggest it as a solution to SELinux related problems, it is more like removing the problem rather than a solution for itu. However, for a development system where security is not important, you might decide to do that (In that case, I would personally prefer using permissive mode rather than completely disabling SELinux, so that you can still know about SELinux permission erros). When you decided to deploy your web application to production servers, you should know how to properly configure SELinux so that your web application works correctly even when SELinux is in Enfrocing mode.

Monday, March 9, 2015

Re-enable graphical root-login on 12.04 LTS

sudo passwd root
sudo sh -c 'echo "greeter-show-manual-login=true" >> /etc/lightdm/lightdm.conf'
Root won't show up as a user, but "Login" will, which is how you manually log in with users not shown in the greeter.
Rebooted and then you should be able to login as root.


OR

First of all, you must set root 's password.
sudo passwd root
Enter new UNIX password:
Now you have root password. Now activate the root account:
sudo usermod -U root
Then you should allow lightdm, gdm or kdm to allow logging in as root.
To enable this:

In GDM

Edit /etc/gdm/custom.conf file and include AllowRoot=true.

In KDM

Edit /etc/kde4/kdm/kdmrc file and change AllowRootLogin=false for AllowRootLogin=true.

In LightDM

This procedure enables the "Other" menu, so you can type the username root and login. You must edit/etc/lightdm/lightdm.conf and add greeter-show-manual-login=true. Then reboot.
Others session managers have other methods to accomplish this.
As you have noticed I gave the instructions but by any circumstance you should not run the GUI as root. Murphy's Law says that it is likely that you mess up somehow and will be annoyed starting again.

I played around enough, how do I go back?

To disable root login just type:
sudo passwd -dl root