Thursday, January 13, 2011

Configure Services in CentOs5/RHEL5

1) List All services
listservices
2)  List Running services at Runlevel 3
listservices34
3) Start service
startservices
4)      Stop service
stopservice
5)   Start service on different RunLevel
stopservice
6)  Restart services
restartservice
7)  Add services
addservice
8 ) Remove Services
deleteservice

Solaris and Linux Runlevel

Default Linux Run Level: Total 7 Run Level
RunLevel 0: Halt System - To shutdown the system
RunLevel 1: Single user mode
RunLevel 2: Basic multi user mode without NFS
RunLevel 3: Full multi user mode (text based)
RunLevel 4: unused
RunLevel 5: Multi user mode with Graphical User Interface
RunLevel 6: Reboot System

Default Solaris Run Level: Total 8 Run Level
RunLevel S: Single user state (useful for recovery)
RunLevel 0: Access Sun Firmware (ok> prompt)
RunLevel 1: System administrator mode
RunLevel 2: Multi-user w/o NFS
RunLevel 3: Multi-user with NFS
RunLevel 4: Unused
RunLevel 5: Completely shutdown the host (like performing a power-off)
RunLevel 6: Reboot but depend upon initdefault entry in /etc/inittab

Call to undefined function: mysql_connect()

Solutions:
Solution 1)   Remove php5-mysql with “apt-get remove php5-mysql”  and install it again or
Solution 2)   Check your php.ini file to ensure it’s including the mysql.so library (extension=mysql.so)  or
Solution 3)   Type “dpkg-reconfigure php5-mysql” (For ubuntu and debian users)

Tuesday, January 4, 2011

Vncserver configuration file to start GNOME


The configuration is kept in the file /home/userxx/.vnc/xstartup I edited this file so that I can start the server with gnome. My file looks exactly like below.
#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
gnome-session &
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
# xterm -geometry 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” &
twm &

Wednesday, December 30, 2009

Setup Subversion Server on Ubuntu 9.04

Step: 1 Installing the Subversion package

#apt-get install subversion

Step:2  Configure Subversion Directory

#mkdir –p  /home/svn/repository

Step 3 Configure Subversion group

#groupadd svn

#chgrp svn /home/svn/repository

#chmod g+rw /home/svn/repository

(you need to make sure that all new files and directories created in the repos directory (in other words, anything committed to the repositories) will also be owned by the group)

#chmod g+s /home/svn/repository

#usermod –a –G svn user1 (Assign users to svn group)

#usermod –a –G svn user2 (Assign users to svn group)

Step 4: Creating a New repository

#svnadmin create /home/svn/repository/test

Step 5: Checkout Repository

#svn checkout file:///home/svn/repository/test

Output: Checked out revision 0

Step 6: Add new files to Empty repository

#cd test

# echo 'Hello, World!' > hello.txt

#svn add hello.txt

Output : A         hello.txt

Step 7 : Commit files

#svn commit -m "Added a 'hello world' text file."

Output :

Adding         hello.txt

Transmitting file data .

Committed revision 1.

Accessing SVN repository

Step 1:  Configure Users for Access SVN repository.

#vi /home/svn/repository/conf/authz

(Add below entry)

[/]

User1 = rw

[/test]

User1 = rw

User2 = rw

(save file)

#vi /home/svn/repository/conf/passwd

(Add below entry)

User1=password1

User2=password2

(save file)

Step 2: Configure files for authentication

# rm –rf /home/svn/repository/test/conf/authz

# rm –rf /home/svn/repository/test/conf/passwd

#vi /home/svn/repository/conf/svnserve.conf

[general]

anon-access = none

password-db = /home/svn/repository/conf/passwd

realm = Team

Step 3: Start repository

#svnserve -d --foreground -r /home/svn/ repository

Step 4 : Test the Repository

#svn checkout svn://ipaddress/test --username user1

Step 5: Initialize the Script at Startup


#wget http://odyniec.net/articles/ubuntu-subversion-server/svnserve

#move svnserve /etc/init.d/

# chmod +x /etc/init.d/subserve

#update-rc.d svnserve defaults

Friday, October 23, 2009

Call to undefined function: mysql_connect()

Solutions:

Solution 1)   Remove php5-mysql with “apt-get remove php5-mysql”  and install it again or

Solution 2)   Check your php.ini file to ensure it’s including the mysql.so library (extension=mysql.so)  or

Solution 3)   Type “dpkg-reconfigure php5-mysql” (For ubuntu and debian users)

Tuesday, September 29, 2009

Solaris and Linux Runlevel

Default Linux Run Level: Total 7 Run Level

RunLevel 0: Halt System - To shutdown the system
RunLevel 1: Single user mode
RunLevel 2: Basic multi user mode without NFS
RunLevel 3: Full multi user mode (text based)
RunLevel 4: unused
RunLevel 5: Multi user mode with Graphical User Interface
RunLevel 6: Reboot System

Default Solaris Run Level: Total 8 Run Level

RunLevel S: Single user state (useful for recovery)

RunLevel 0: Access Sun Firmware (ok> prompt)

RunLevel 1: System administrator mode

RunLevel 2: Multi-user w/o NFS

RunLevel 3: Multi-user with NFS

RunLevel 4: Unused

RunLevel 5: Completely shutdown the host (like performing a power-off)

RunLevel 6: Reboot but depend upon initdefault entry in /etc/inittab

Update system

update

Configure Services in CentOs5/RHEL5

1) List All services

listservices

2)  List Running services at Runlevel 3

listservices34

3) Start service

startservices

4)      Stop service

stopservice

5)   Start service on different RunLevel

stopservice

6)  Restart services

restartservice

7)  Add services

addservice

8 ) Remove Services

deleteservice

Monday, September 28, 2009

CentOS5/RHEL5 User Administration

1) Add User

Useradd

2)      Delete user

Userdel

3)      Modify user

Usermod

4) Add Group

gpasswd



5) Delete group

groupdel

6) Modify group

groupmod

7) Add User to Group

Use useradd command to add new users to existing group (or create a new group and then add user). If group does not exist, create it. Syntax:

Syntax:

useradd -G {group-name1},{group-name2} username (for secondary group)

useradd -g {group-name} username (for primary group)

useradd1



Tuesday, September 15, 2009

Automated Installation of DenyHost on RedHat/Fedora

#Script
#!/bin/bash

# This script installs Deny Host on RedHat(RHEL) or Fedora.

################################################################################

# This script comes with no warranty or guarantee. Please review the script

# before you run it to ensure that it will not cause adverse effects on your

# system.

#

# If you have any questions or comments, please e-mail: sanjaydalal4u@gmail.com

################################################################################

sudo echo

if [ -f /etc/init.d/denyhosts ]; then

echo Removing existing init scripts

sudo /etc/init.d/denyhosts stop

sudo rm -rf /etc/init.d/denyhosts

sudo chkconfig --remove denyhosts

echo '*********************'

echo

fi

if [ -d /usr/share/denyhosts/ ]; then

echo Removing existing installation

sudo rm -rf /usr/share/denyhosts

echo '*********************'

echo

fi

echo Installing 'python' and dependencies.

sudo yum -y install python

echo '*********************'

echo

cd /root

echo Downloading DenyHost

wget http://downloads.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6.tar.gz?use_mirror=biznetnetworks

echo '*********************'

echo

echo Unpacking DenyHost

#!/bin/bash

# This script installs Deny Host on RedHat(RHEL) or Fedora.

################################################################################

# This script comes with no warranty or guarantee. Please review the script

# before you run it to ensure that it will not cause adverse effects on your

# system.

# If you have any questions or comments, please e-mail: sanjaydalal4u@gmail.com

################################################################################

sudo echo

if [ -f /etc/init.d/denyhosts ]; then

echo Removing existing init scripts

sudo /etc/init.d/denyhosts stop

sudo rm -rf /etc/init.d/denyhosts

sudo chkconfig --remove denyhosts

echo '*********************'

echo

fi

if [ -d /usr/share/denyhosts/ ]; then

echo Removing existing installation

sudo rm -rf /usr/share/denyhosts

echo '*********************'

echo

fi

echo Installing 'python' and dependencies.

sudo yum -y install python

echo '*********************'

echo

cd /root

echo Downloading DenyHost

wget http://downloads.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6.tar.gz?use_mirror=biznetnetworks

echo '*********************'

echo

echo Unpacking DenyHost

tar -xzf DenyHosts-2.6.tar.gz



cd /root/DenyHosts-2.6

echo '*********************'

echo


echo Installing DenyHost

sudo python setup.py install

echo '*********************'

echo


cd /usr/share/denyhosts


echo Configuring DenyHost

sudo cp denyhosts.cfg-dist denyhosts.cfg

sudo sed -i.bak 's/^\s*\(SECURE_LOG\s*=.*\)$/#\1/' denyhosts.cfg

sudo sed -i.bak 's/^\s*#\s*SECURE_LOG\s*=\s*\/var\/log\/secure/SECURE_LOG = \/var\/log\/secure/' denyhosts.cfg

sudo sed -i.bak 's/^\s*\(LOCK_FILE\s*=.*\)$/#\1/' denyhosts.cfg

sudo sed -i.bak 's/^\s*#\s*LOCK_FILE\s*=\s*\/var\/run\/denyhosts.pid/LOCK_FILE = \/var\/run\/denyhosts.pid/' denyhosts.cfg

sudo sed -i.bak 's/^\s*\(BLOCK_SERVICE\s*=.*\)$/#\1/' denyhosts.cfg

sudo sed -i.bak 's/^\s*#\s*BLOCK_SERVICE\s*=\s*ALL/BLOCK_SERVICE  = ALL/' denyhosts.cfg

echo '*********************'

echo


echo Configuring executable

sudo cp daemon-control-dist daemon-control

sudo sed -i.bak 's/^\(\s*DENYHOSTS_BIN\s*=\s\).*$/\1"\/usr\/bin\/denyhosts.py"/' daemon-control

sudo sed -i.bak 's/^\(\s*DENYHOSTS_LOCK\s*=\s\).*$/\1"\/var\/run\/denyhosts.pid"/' daemon-control

sudo sed -i.bak 's/^\(\s*DENYHOSTS_CFG\s*=\s\).*$/\1"\/usr\/share\/denyhosts\/denyhosts.cfg"/' daemon-control

sudo chown root daemon-control

sudo chmod 700 daemon-control

echo '*********************'

echo


echo Adding ddclient to rc scripts

cd /etc/init.d

sudo ln -s /usr/share/denyhosts/daemon-control denyhosts

sudo chkconfig --add denyhosts

sudo chkconfig --level 35 denyhosts on

echo '*********************'

echo


Friday, July 31, 2009

How to Open 7zip Files Under Ubuntu

Step 1 : Install application

#sudo apt-get install p7zip

Step 2 : Exectute this command

#p7zip -d filename.7z

Sunday, July 26, 2009

Setup SAMBA server on Ubuntu

Step 1: Installation

#apt-get install samba

Step 2: Configuration

Configuration file : /etc/samba/smb.conf
  • Edit below section

Workgroup = EXAMPLE

…………

Security = user
  • Create a new section at the bottom of the file /etc/samba/smb.conf

[Samba Share]

Comment= Samba  File Server Share

Path=/path to directory

Browsable = yes

Guest ok = yes

Read only = no

Create mask = 0755

Step 3: Create directory and change permissions

#mkdir /path to directoy

#chown  -R nobody:nobody /path to directory

Step 4 : Restart Samba service

#/etc/init.d/samba restart

Enjoy!!!!!!!!!!!!

Thursday, July 9, 2009

Open ports using IPTABLES

If you want your machine to respond to requests initiated from elsewhere on the internet you need to open the required ports. You need to know below details first:



1. Service name you want to open up
2. Is it a tcp or udp service?
3. Port number(s) uses by service?

Example:


To enable ssh access to your box from anywhere on for Class A networks, you could use something like



iptables -A allowed -p tcp --dport 22 -s 10.2.0.0/16 -j ACCEPT
iptables -A allowed -p udp --dport 22 -s 10.2.0.0/16 -j ACCEPT


iptables -A allowed -p tcp --dport 22 -s 10.8.0.0/16 -j ACCEPT
iptables -A allowed -p udp --dport 22 -s 10.8.0.0/16 -j ACCEPT

This allows both udp and tcp traffic from either of the two class A networks to access port 22 on your machine.

Work with tcpwrappers hosts.deny and hosts.allow

You can use tcpwrappers to Block user,ip,daemon from outside or your inside newwork. For allow use host.allow file and to block use host.deny file.


Step 1. Use your favorite editor like vi.



Step 2. Type vi /etc/hosts.deny
Step 3. At the bottom line just type “ALL:ALL:deny” to restricted all of daemon process
Step 4. Save it.
Step 5. Open “/etc/hosts.allow” with vi editor
Step 6. At the buttom line “ALL :(some ip that you allow):allow” to allow anything from my IP address
Step 7. Save it.

Thursday, July 2, 2009

Working with tar and tar Encryption

STEP 1 :  (Using the tar command on the directory /example)

Suppose you have a directory /stuff. To tar everything in stuff to create a “.tar” file.

# tar -cvf example.tar example

It will create example.tar file.

STEP 2 :  (Using the tar command to create a “.tar.gz” of /example)

# tar -czf example.tar.gz example

STEP 3 :  (List the files in the archive)

# tar -tzf example.tar.gz
or
# tar -tf example.tar

STEP 4 :   (ENCRYPTION)

# tar -zcvf – example | openssl des3 -salt -k secretpassword | dd of=example.des3

This will create example.des3…Please don’t forget the password you put in place of secretpassword.

If you want to do this interactively then

# dd if=example.des3 |openssl des3 -d -k secretpassword|tar zxf -

Wednesday, July 1, 2009

Multiple IP address on Single NIC (Redhat/Fedora)

We can setup two Ipaddress on single NIC.

Below i have mentioned for Redhat/Fedora/CentOs system.

STEP 1 : (Initial/First IP address)

#cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=static
BROADCAST=10.8.0.255
IPADDR=10.8.0.10
NETMASK=255.255.255.0
NETWORK=10.8.0.0
ONBOOT=yes

STEP 2 : (Second IP address)
#cat /etc/sysconfig/network-scripts/ifcfg-eth0:1

DEVICE=eth0:1
BOOTPROTO=static
BROADCAST=10.8.0.255
IPADDR=10.8.0.11
NETMASK=255.255.255.0
NETWORK=10.8.0.0
ONBOOT=yes

View Routing Table and Change your default Gateway

The netstat -nr command will provide the contents of the touting table.

# netstat -nr



Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

10.8.0.0        0.0.0.0         255.255.255.0   U         0 0          0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0

0.0.0.0         10.8.0.1        0.0.0.0         UG        0 0          0 eth0



Change Your Default Gateway

You will need to update your /etc/sysconfig/network file to reflect the change. This file is used to configure your default gateway

NETWORKING=yes
HOSTNAME=newhost
GATEWAY=10.8.0.2

Use of Netstat Commands

Netstat (network statistics) is a command-line tool that displays network connections (both incoming and outgoing), routing tables, and a number of network interface statistics. Netstat is a useful tool for checking your network configuration and activity.

Check tcp connection established on your machine using below command

1: netstat --tcp

% netstat --tcp --numeric
Active Internet connections (w/o servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State

tcp        0      0 nexubuntu:ldap          nexubuntu:38885         ESTABLISHED

tcp        0      0 nexubuntu:38885         nexubuntu:ldap          ESTABLISHED

tcp        0      0 nexubuntu:ssh           10.8.0.151:50776        ESTABLISHED

tcp        0      0 nexubuntu:microsoft-ds  nexubuntu:59000         ESTABLISHED

tcp        0      0 nexubuntu:38875         nexubuntu:ldap          ESTABLISHED

tcp        0      0 nexubuntu:ldap          nexubuntu:52342         ESTABLISHED

tcp        0      0 nexubuntu:ssh           10.8.0.151:50775        ESTABLISHED

tcp      244      0 nexubuntu:59004         nexubuntu:microsoft-ds  ESTABLISHED

tcp      244      0 nexubuntu:59000         nexubuntu:microsoft-ds  ESTABLISHED

tcp        0      0 nexubuntu:ldap          nexubuntu:38875         ESTABLISHED

tcp        0      0 nexubuntu:microsoft-ds  nexubuntu:59004         ESTABLISHED

tcp        0      0 nexubuntu:52343         nexubuntu:ldap          TIME_WAIT

tcp        0      0 nexubuntu:52342         nexubuntu:ldap          ESTABLISHED

tcp        0      0 nexubuntu:microsoft-ds  nexubuntu:58998         ESTABLISHED

tcp      244      0 nexubuntu:58998         nexubuntu:microsoft-ds  ESTABLISHED

If you want to see what (TCP) ports your machine is listening on, use netstat --tcp --listening. Another useful flag to add to this is --programs which indicates which process is listening on the specified port.

2: netstat --tcp --listening --programs

# sudo netstat --tcp --listening --programs
Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

tcp        0      0 *:nfs                   *:*                     LISTEN      -

tcp        0      0 *:ldap                  *:*                     LISTEN      2715/slapd

tcp        0      0 *:ftp                   *:*                     LISTEN      3302/vsftpd

tcp        0      0 *:ssh                   *:*                     LISTEN      4022/sshd

tcp        0      0 nexubuntu:postgresql    *:*                     LISTEN      2680/postgres

tcp        0      0 *:smtp                  *:*                     LISTEN      3259/master

tcp        0      0 *:58777                 *:*                     LISTEN      2098/rpc.statd

tcp        0      0 *:microsoft-ds          *:*                     LISTEN      3283/smbd

tcp6       0      0 [::]:ldap               [::]:*                  LISTEN      2715/slapd

tcp6       0      0 [::]:www                [::]:*                  LISTEN      3750/apache2

Uses netstat --route to display the routing table.

3: netstat --route

% netstat --route
Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

10.8.0.0        *               255.255.255.0   U         0 0          0 eth0

link-local      *               255.255.0.0     U         0 0          0 eth0

default         mygateway1.ar7  0.0.0.0         UG        0 0          0 eth0

Uses the --statistics flag to display networking statistics.

Using this flag by itself displays all IP, TCP, UDP, and ICMP connection statistics.

4: netstat --statistics --route

Network configuration for Debian

Ip from dhcp

#/etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

For a static IP

#/etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 10.8.0.100
netmask 255.255.255.0
gateway 10.8.0.1
broadcast 10.8.0.255

sanjay's shared items

My Blog List