Tuesday 17 May 2011

Linux How To Mount Hard Disks And File Systems


Step One: Check the current had disk mount status:

command "df -h"

Sample Output:

"df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             6.0G  5.4G  231M  96% /
/dev/sda1             2.0G  268M  1.7G  14% /boot
tmpfs                 500M     0  500M   0% /dev/shm
"


Step Two: Check the hard disks attached to the server.

Command "fdisk -l"

Sample Output:

fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000b3989

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         261     2096451   83  Linux
/dev/sda2             262         522     2096482+  82  Linux swap / Solaris
/dev/sda3             523        1305     6289447+  83  Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x079f9b62

   Device Boot      Start         End      Blocks   Id  System

Disk /dev/sdc: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xe9614c39


Step Three: Find the unmounted hard disks from "fdisk -l"

Eg: "Disk /dev/sdb" and "Disk /dev/sdc"

Step Four: Format the disks to make linux filesystem.

Eg: "

fdisk /dev/sdb

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):
Using default value 1305

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


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

fdisk /dev/sdc

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):
Using default value 1305

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

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


Step Five: Check current "fdisk -l" status

Eg:
"fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000b3989

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         261     2096451   83  Linux
/dev/sda2             262         522     2096482+  82  Linux swap / Solaris
/dev/sda3             523        1305     6289447+  83  Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x079f9b62

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1305    10482381   83  Linux

Disk /dev/sdc: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xe9614c39

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        1305    10482381   83  Linux
"
You will find "/dev/sdb1               1        1305    10482381   83  Linux"
and "/dev/sdb1               1        1305    10482381   83  Linux" created.

Step Six: Use mkfs.ext3 command to build linux file system over "/dev/sdb1 and /dev/sdb1"

Eg:
"mkfs.ext3 /dev/sdb1
mke2fs 1.41.3 (12-Oct-2008)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
655360 inodes, 2620595 blocks
131029 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


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

mkfs.ext3 /dev/sdc1
mke2fs 1.41.3 (12-Oct-2008)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
655360 inodes, 2620595 blocks
131029 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
"

Step Seven: Make directory to mound the two hard disks.

Eg:
"mkdir /mnt/diskone"
"mkdir /mnt/disktwo"

Step Eight: Mount the hard disk to created folders

Commands:
"mount /dev/sdb1 /mnt/diskone/"
"mount /dev/sdc1 /mnt/disktwo/"

Step Nine: Check the mount status:

Command" "df -h"

Eg:
"df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             6.0G  5.4G  229M  97% /
/dev/sda1             2.0G  268M  1.7G  14% /boot
tmpfs                 500M     0  500M   0% /dev/shm
/dev/sdc1             9.9G  151M  9.2G   2% /mnt/disktwo
/dev/sdb1             9.9G  151M  9.2G   2% /mnt/diskone
"

Step Ten: Commnds to unmount hard disks:

Commands:
"umount /dev/sdb1"
"umount /dev/sdc1"

Eg: "df -h"

"df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             6.0G  5.4G  229M  97% /
/dev/sda1             2.0G  268M  1.7G  14% /boot
tmpfs                 500M     0  500M   0% /dev/shm
"

Saturday 14 May 2011

Linux Apache Directories With LDAP Authentication Setup.

                                     SETUP

Ldap Server              : domain.mycompany.com
Ldap Server Port       : 3268
Organizational Units   : WEBUSERS
Admin User               : webadmin@domain.mycompany.com
webadmin Password : password


Step 1: Copy your project to /var/www/html directory.

"cp -R myproject /var/www/html/projectone"

Step 2: Give the project permission for Apache User.

"chmod 755 /var/www/html/projectone/* -R"
"chown apache:apache /var/www/html/projectone/* -R"

Step 3: Edit httpd.conf and enable ldap modules.

edit "/etc/httpd/conf/httpd.conf"

Enable the lines:
"LoadModule ldap_module modules/mod_ldap.so"
"LoadModule authnz_ldap_module modules/mod_authnz_ldap.so"


Step 4: Create ldap authentication settings for projectone directory.

edit "/etc/httpd/conf/httpd.conf"

Add line:

<Location /projectone/>
  AuthType Basic
  AuthName "ProjectOne"
  AuthBasicProvider "ldap"
  AuthLDAPURL "
ldap://domain.mycompany.com:3268/DC=domain,DC=mycompany,DC=com?sAMAccountName?sub?(objectClass=user)"
  AuthLDAPBindDN      
webadmin@domain.mycompany.com
  AuthLDAPBindPassword password
  authzldapauthoritative Off
  require valid-user
  require ldap-group CN=WEBUSERS,CN=Users,DC=domain,DC=mycompany,DC=com
</Location>


Step 5: Restart Apache web server.

"service httpd restart"

Apache Ldap based directory access is ready.

Friday 13 May 2011

How To Setup A Linux Server: Linux Port Forwarding Using iptables.

How To Setup A Linux Server: Linux Port Forwarding Using iptables.

Linux Port Forwarding Using iptables.

Step 1: Setup a linux gateway server with public ip address.

Help: http://reddragon-linux.blogspot.com/2011/05/linux-internet-gateway-server-setup.html


Step 2: Find the service type which need the port forwading.

Eg: HTTP ( Port 80, TCP).

Public ip address : XXX.XXX.XXX.XXX
Local ip address : 192.168.1.2

/sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 -d XXX.XXX.XXX.XXX --dport 80 -j DNAT --to 192.168.1.2:80
/sbin/iptables -A FORWARD -p tcp -i eth0 -d 192.168.1.2 --dport 80 -j ACCEPT

Tuesday 10 May 2011

Linux Internet Gateway Server Setup

Setup Netwok Diagram.



Linux Server:

eth0 ( External Interface )
eth1 ( Internal Netwok Interface) ( 192.168.1.X series )

Step 1. Enable ip nat in linux kernel.

"echo '1' > /proc/sys/net/ipv4/ip_forward"

Step 2. Assign IP address to eth0 and eth1
-------------------------------------------------------
/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
ONBOOT=yes
IPADDR=xxx.xxx.xxx.xxx
NETMASK=255.255.255.xxx
GATEWAY=xxx.xxx.xxx.xxx
TYPE=Ethernet
BOOTPROTO=static
HWADDR=00:11:5B:F6:E2:5D
-------------------------------------------------------
-------------------------------------------------------
/etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
ONBOOT=yes
IPADDR=192.168.1.1
NETMASK=255.255.255.0
TYPE=Ethernet
BOOTPROTO=static
HWADDR=00:29:5X:FG:32:8S
-------------------------------------------------------

"service network restart"

Step 3. Set iptable commands.

"iptables -F"
"iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE"
"iptables --append FORWARD --in-interface eth1 -j ACCEPT"

Step 4. Add the above entries to /etc/rc.local file.

/etc/rc.local

/sbin/iptables -F 2>/dev/null
/sbin/iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE 2>/dev/null
/sbin/iptables --append FORWARD --in-interface eth1 -j ACCEPT 2>/dev/null

========================================================================




Saturday 7 May 2011

Linux Networking. How To Configure IP Address And Virtual Interface.

Step 1. Check the network interfaces avilable.

Command : "lspci | grep Ethernet"

Sample Output:

00:04.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ (rev 20)
00:05.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ (rev 20)

Step 2: Check if the linux kernel have identified and loaded the devices.

Command: "ifconfig -a"

Sample Output:

eth0      Link encap:Ethernet  HWaddr 77:03:8e:80:31:f5
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8585824 errors:0 dropped:86 overruns:0 frame:0
          TX packets:2926444 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1499815123 (1.3 GiB)  TX bytes:2165102153 (2.0 GiB)
          Interrupt:32 Base address:0x6000
eth1      Link encap:Ethernet  HWaddr 08:31:9D:4B:98:H6
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:509769 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:25435857 (24.2 MiB)  TX bytes:0 (0.0 b)
          Interrupt:36 Base address:0xa100
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1090579 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1090579 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:293214254 (279.6 MiB)  TX bytes:293214254 (279.6 MiB)
Here eth0 is first interface with ip 192.168.1.1 and eth1 the second interface with no ip addess. lo is the local loopback interface.

Step 3. Change/Assign ip address to interfaces.

Commands:
"cd /etc/sysconfig/network-scripts/"
Edit ifcfg-eth0

Sample File Content:
 ---------------------------------------
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.1
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Ethernet
GATEWAY=192.168.1.10
HWADDR=77:03:8e:80:31:f5
---------------------------------------
Save the file.

Step 4. Restart network service.

To update the new setting restart the network service.

Command: "service network restart"
Induvidual interfaces can be restarted using Commads: "ifdown ifcfg-eth0" and "ifup ifcfg-eth0".

Step 5. Creating a virtual interface.

Command: "cp ifcfg-eth0 ifcfg-eth0:1"
Edit ifcfg-eth0:1 file
---------------------------------------
DEVICE=eth0:1
BOOTPROTO=static
IPADDR=172.16.0.1
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Ethernet
HWADDR=77:03:8e:80:31:f5
 ---------------------------------------

Command: "ifup ifcfg-eth0:1"

You will have a new virtual interface eth0:1 up with ip address 172.16.0.1.

Thursday 5 May 2011

Linux Reset Root User Password

Step 1. Enter grub prompt while booting.

Step 2. If grub has password press "p" and enter the password or select and click "enter" to select the kernel you want to login.





Step 3. Select the line starting with "kernel" and press "e" to edit.




Step 4. Add the word "single" to the end of the line and click escape to save. Press "b" to boot with the modified grub entry.





Step 5. Linux will boot into the shell without any password prompt. Use the command "passwd root" to reset the root user password.



Restart and login with new root password.