Wednesday, May 21, 2014

Linux Problem Solution

How To Block Pings ICMP


first, ping your server and make sure you are getting ping replies. i am using widows xp, so i will open the DOS terminal and ping my ip: example:

C:\Users\MyPC>ping 192.168.0.2

Pinging 192.168.0.2 with 32 bytes of data:
Reply from 192.168.0.2: bytes=32 time<1ms TTL=12
Reply from 192.168.0.2: bytes=32 time<1ms TTL=12
Reply from 192.168.0.2: bytes=32 time<1ms TTL=12
Reply from 192.168.0.2: bytes=32 time<1ms TTL=12

Ping statistics for 192.168.0.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
then send this command to edit sysctl.conf
SHELL COMMAND:
# Vim  /etc/sysctl.conf
net.ipv4.icmp_echo_ignore_all = 1
#/etc/init.d/network  restart


web server problem with virtualhost


First time LAMP and domain setup on CentOs. Previous experience of this is in Ubuntu. Working on a dedicated server package of my local ISP. They installed default CentOs 6.2 and redirected my domain to the server. Pinging mydomain.com works fine to reach the server's IP.
I have successfully installed LAMP on the box using this howto explanation. All seems fine.
I have edited /etc/hosts:
127.0.0.1      mydomain.com
I have also edited the /etc/httpd/conf/httpd.conf and added the following at the end of the file, while keeping the rest default:
NameVirtualHost *:80

<VirtualHost *:80>
   DocumentRoot /var/www/html
   ServerName localhost
   <Directory /var/www/html>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>
</VirtualHost> <VirtualHost *:80> ServerName mydomain.com ServerAlias www.mydomain.com ServerAdmin myemailaddress@email.com DocumentRoot /var/www/html/mydomain.com <Directory "/var/www/html/mydomain.com"> Options Includes FollowSymLinks AllowOverride All allow from all </Directory> ErrorLog /var/www/logs/mydopmain.com.default.log </VirtualHost>
And i also ran
chmod -R apache:apache /var/www/html


How to Automatically Add the "www" Prefix to Your Domain Names in URLs

To redirect (say) example.com to www.example.com, add the following code to your .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
The above code causes the server to check that the domain name portion of the URL is example.com. If it is, the visitor will be sent to www.example.com instead. If you also own, say example.co.uk, example.de and/or some other domain, and want them to be redirected to www.example.com as well, you may prefer to use the following code instead:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

How to Remove the WWW Prefix from Your Domain Names Using

To redirect any URL starting with (say) www.example.com to example.com
add the following codeto your .htaccess file.


RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
The above rules checks if the domain name component in a URL contains www.example.com. If it does, the visitor is sent to example.com instead. To use the rule, change all instances of "example.com" to your actual domain name. For the line beginning with RewriteCond, add a backslash ("\") before each of the full stops (or "periods") in your domain name.

CentOS 5.2 yum repository error

 Iinitially there were two repo files in the /etc/yum.repos.d directory

# CentOS-Base.repo

#

# This file uses a new mirrorlist system developed by Lance Davis for CentOS.

# The mirror system uses the connecting IP address of the client and the

# update status of each mirror to pick mirrors that are updated to and

# geographically close to the client.  You should use this for CentOS updates

# unless you are manually picking other mirrors.

#

# If the mirrorlist= does not work for you, as a fall back you can try the 

# remarked out baseurl= line instead.

#

#



[base]

name=CentOS-$releasever - Base

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5



#released updates 

[updates]

name=CentOS-$releasever - Updates

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5



#packages used/produced in the build but not released

[addons]

name=CentOS-$releasever - Addons

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons

#baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5



#additional packages that may be useful

[extras]

name=CentOS-$releasever - Extras

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5



#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$releasever - Plus

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus

#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/

gpgcheck=1

enabled=0

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5


Apt-get GPG Error: Public Key Not Available in Ubuntu

Sometimes while updating your Ubuntu using terminal you get some error showing missing public key & thus failing to update.You can get the key using the command given below.Just replace the key with the key in error.
wget -q “http://keyserver.ubuntu.com:11371/pks/lookup?op=get&search=0x(4874D3686E80C6B7)” -O- | sudo apt-key add -
or
visit http://keyserver.ubuntu.com:11371/ to get the public key manually

How To Protect Web Page Directories With Passwords

You can password protect content in both the main and subdirectories of your DocumentRoot fairly easily. I know people who allow normal access to their regular Web pages, but require passwords for directories or pages that show MRTG or Webalizer data. This example shows how to password protect the /home/www directory.

1) Use Apache's htpasswd password utility to create username/password combinations independent of your system login password for Web page access. You have to specify the location of the password file, and if it doesn't yet exist, you have to include a -c, or create, switch on the command line. I recommend placing the file in your /etc/httpd/conf directory, away from the DocumentRoot tree where Web users could possibly view it. Here is an example for a first user named peter and a second named paul:
[root@bigboy tmp]# htpasswd -c /etc/httpd/conf/.htpasswd peter
New password:
Re-type new password:
Adding password for user peter
[root@bigboy tmp]#

[root@bigboy tmp]# htpasswd /etc/httpd/conf/.htpasswd paul
New password:
Re-type new password:
Adding password for user paul
[root@bigboy tmp]#
2) Make the .htpasswd file readable by all users.
[root@bigboy tmp]# chmod 644 /etc/httpd/conf/.htpasswd
3) Create a .htaccess file in the directory to which you want password control with these entries.
AuthUserFile /etc/httpd/conf/.htpasswd
AuthGroupFile /dev/null
AuthName EnterPassword
AuthType Basic
require user peter
Remember this password protects the directory and all its subdirectories. The AuthUserFile tells Apache to use the .htpasswd file. The require user statement tells Apache that only user peter in the .htpasswd file should have access. If you want all .htpasswd users to have access, replace this line with require valid-user. AuthType Basic instructs Apache to accept basic unencrypted passwords from the remote users' Web browser.
4) Set the correct file protections on your new .htaccess file in the directory /home/www.
[root@bigboy tmp]# chmod 644 /home/www/.htaccess
5) Make sure your /etc/httpd/conf/http.conf file has an AllowOverride statement in a <Directory> directive for any directory in the tree above /home/www. In this example below, all directories below /var/www/ require password authorization.
<Directory /home/www/*>
   AllowOverride AuthConfig
</Directory>
6) Make sure that you have a <VirtualHost> directive that defines access to /home/www or another directory higher up in the tree.
<VirtualHost *>
   ServerName 97.158.253.26
   DocumentRoot /home/www
</VirtualHost>
7) Restart Apache.
Try accessing the web site and you'll be prompted for a password.

0 comments: