Virtual Hosting allow web servers to host more than one website on a sing machine. This is how sharing hosting works. I become pretty handy as well while develloping different web project on the same machine and allows you to access to your local repository using addresses such as http://dev.mysite.com instead of http://localhost/~myuser/myproject/ :) .
This tutorial is based on a machine runnning ubuntu/linux but should be the same on any debian based distribution and almost the same on other distributions.

First of all, you need an apache server ready to run on your machine, if it is not yet install, open a terminal and type

$sudo apt-get install apache2-utils apache2-common

Once the server is installed, it is time to get into apache 2 configuration.
Let’s open apache’s main configuration file, name /etc/apache2/apache2.conf. A search for the word virtual bring us to the following line:

Include /etc/apache2/sites-enabled/[^.#]*

This mean that when starting apache, it will look for files in /etc/apache2/sites-enabled/.
Lets go there and see what is in.

$cd /etc/apache2/sites-enabled/

$ls -l

total 1

lrwxrwxrwx 1 root root 36 2005-12-27 01:42 000-default -> /etc/apache2/sites-available/default

Well, this only links to the file in directory /etc/apache2/sites-available/ . You might wonder what is the point in doing such. Well, this simply allows you, mainly when you are using your box as a web server, to:

     

  1. Have a simple main configuration file 
  2. Do be able to edit or create a new host by creating/editing a file from /etc/apache2/sites-available/ 
  3. In case your web server doesn’t restart because of misconfiguration, you can simply remove the link from the file in /etc/apache2/sites-enabled/ pointing to the malformed file in /etc/apache2/sites-available/ 

Now let say you want to be able to map the domain name dev.example.com to you local machine, using the code file in /home/myuser/public_html/example.com/.
While in /etc/apache2/sites-available, create a new file (let say example.com.conf)

$sudo vi example.com.conf

Now add the following lines:

<VirtualHost dev.example.com>
ServerAdmin webmaster@localhost
#We want to be able to access the web site using www.dev.example.com or dev.example.com
ServerAlias www.dev.example.com
DocumentRoot /home/myuser/public_html/example.com
#if using awstats
ScriptAlias /awstats/ /usr/lib/cgi-bin/
#we want specific log file for this server
CustomLog /var/log/apache2/example.com-access.log combined
</VirtualHost>

 

Note:People who don’t want to bother knowing how the site enabling system works might just jump to the end of the article to find debian built-in command syntax. If you want to know how it works, or do not use a debian based distro, carry on.

Now, we specified a new host to apache but it is not yet linked to the repertory where apache actually look for virtual hosts. Let go to:

$cd /etc/apache2/sites-enabled/

and create a link to the file we just created:

$sudo ln -s /etc/apache2/sites-available/example.com.conf example.com.conf

Now apache is almost ready to restart, but before doing so, we must inform our linux system that dev.example.com and www.dev.example.com are not to be looked for on the net, but on the local machine instead.
To do so, simply edit /etc/hosts and add the new host names at the end of the line beginning by 127.0.0.1, which is localhost.
In the end, your file should look like:

127.0.0.1 localhost.localdomain localhost dev.example.com www.dev.example.com

And now we are done, simply reload apache:

sudo /etc/init.d/apache2 reload

Open your web browser and enter the following address dev.example.com. Magic, it runs the same as when you were using http://localhost/~myuser/example.com but it is far more usefull when devellopping a web service and want to be able to develop applications on your machine just like it is where the real web site.

Edit: As you can see from the comments, many people pointed out that you can use a debian specific command (so if you are not using a debian based system, don’t expect to find that command :) ).
to enable a new virtual host simply type:

sudo a2ensite mysiteavailable-site

to disable a virtual host:

sudo a2dissite mysiteavailable-site

where mysiteavailable-site is the name of the virtual hos you want to enable/disable, so in out example: example.com.conf

Hope this helped.

Thanks to Author, orignal link http://www.debuntu.org/2006/02/22/7-virtual-hosting-using-apache-2

It happens sometimes that you get more than one connection to the internet. Also it might not be usefull in most of the cases, there are few cases when it get really usefull to be able to use the first connection for accessing the Internet and the second connection to access some specific networks or hosts.
Here I’m going to explain how to achieve this setting.

It happens sometimes that you get more than one connection to the internet, for instance, the place I work at, I get one connection using a private internet provider (which is real good), and another one using ADSL from our telecom network. The last one can be accessed using WIFI and allow us to run some specific programs (some dialers like software) which require a telecom connection.
Well, I could have made the choice of only using the wireless connection, but to be honest I rather download my software, packages, iso … at full speed.
So, get let right into the deal.
In this article, I will assume that the wireless connection uses DHCP to retrieve internet settings and is called wlan0, the second connection is called eth0 and is configured using static settings (ip address 193.164.0.4, netmask 255.255.255.0, dns 193.164.0.253 and gateway 193.164.0.254). I want to access internet using eth0 but for networks using IP adresses range 192.168.0.0/16 (192.168.*) and 192.169.0.0/24 (192.169.0.*), i want to use wlan0.

The file where everything happen is /etc/network/interfaces, people which want to know more about this file go read the man interfaces.
So edit /etc/network/interfaces

user@localhost:$ vi /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback

# This is a list of hotpluggable network interfaces.
# They will be activated automatically by the hotplug subsystem.

mapping hotplug
script grep
map eth0

#configuration of wlan0 with dhcp
iface wlan0 inet dhcp
#configuring wireless settingd
wireless-essid mywirelessnetwork
wireless-key XXXXXXXXXXXXXXXXX
#add the route for the wireless interface for specific adresses
up route add -net 192.168.0.0/16 gw mywirelessnetwork dev wlan0
up route add -net 193.169.0.0/24 gw mywirelessnetwork dev wlan0
#remove default gateway generated by dhcp
up route del default gw mywirelessnetwork
#starts automatically at boot up
auto wlan0

#configuring eth0 device with static settings
iface eth0 inet static
address 193.164.0.4
netmask 255.255.255.0
gateway 193.164.0.254
#force to use eth0 dns
dns-nameservers 193.164.0.253
#start automatically at boot up
auto eth0

Here you are. You might want to restart your network interfaces.

user@localhost$sudo /etc/init.d/networking restart

Now, you can connect to internet with two different connections :)

Thanks to Author, orignal link http://www.debuntu.org/2006/02/23/8-using-multiple-network-device-to-connect-to-the-internet

Most unix administrator might know wget, a HTTP, HTTPS and FTP client developped by the GNU project. Using that tool, you can easily download HTTP page but also packages… Basically anything you can access through your web browser or ftp client.

Uploading something through Internet is, too me, quite annoying in text mode because you need to log in, change path and put the file.

wput is here to resolve this.

wput is great, but before telling you anything read the following line:

WARNING: Mind that when uploading on a ftp server using wput, your password will be seing in clear text. I will explain more about this later on.

Well, let’s go through it. A basic use of wget is quite staightforward, for instance, if you want to get the index page of debuntu.org simply type:

tester@laptop:~$wget http://www.debuntu.org
–16:42:32– http://www.debuntu.org/
=> `index.html’
Resolving debuntu.org… XXX.XXX.XXX.XXX
Connecting to debuntu.org|XX.XXX.XXX.XXX|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: unspecified [text/html]
[ <=> ] 26,868 –.–K/s
16:42:33 (220.38 KB/s) – `index.html’ saved [26868]

This saved the homepage of debuntu.org in index.html, now if you want get saved the file with another name type:

tester@laptop:~$ wget http://www.debuntu.org -O debuntu-index.html
–16:45:11– http://www.debuntu.org/
=> `debuntu-index.html’
Resolving debuntu.org… XXX.XXX.XXX.XXX
Connecting to debuntu.org|XXX.XXX.XXX.XXX|:80… connected.
HTTP request sent, awaiting response…. 200 OK
Length: unspecified [text/html]
[ <=> ] 26,868 139.75K/s
16:45:11 (139.27 KB/s) – `debuntu-index.html’ saved [26868]

The -O switch allows you to define another name for saving the datas you download. In this case: debuntu-index.html.

There is a lot more options available but this will require pages and pages to go through it. People interested in getting it might simply check out the manpage.

Now, let’see how wput works. A basic use looks like this:

wput FILE URL

So, if I have an account on example.com with user chantra and password foobar and want to upload myfile.txt to /dir1/mydir onto that host, I have to type:

tester@laptop:~$wput myfile.txt ftp://chantra:foobar@example.com/dir1/mydir/

And there I go. But this is where the security issues are:

     

  1. Somebody typing:

    $ps -aux

    at the same time will see something like:

    tester 15295 11.0 0.1 1640 664 pts/0 D+ 16:58 0:00 wput myfile.txt ftp://chantra:foobar@example.com/dir1/mydir/

     

     

  2. this is recording in your ~/.bash_history so somebody gaining access to your account will be able to exploit this to access your remote account on example.com 

Therefore I would say that wput is really convenient but to use on your local machine only, not on a server where thousand user are connected (such places like university campus are to avoid ;) ).

Thanks to Author, orignal link http://www.debuntu.org/2006/04/07/21-wget-wput-or-how-to-easily-download-upload-over-internet

In this article I’m going to show you how you can use SSH Port Forwarding to access a service a firewall might be blocking.

As an example, I’m going to take the one from a campus blocking access to IRC servers usually running on port 6667, but letting the SSH port 22 unblocked.

The idea here is: because we can connect to a remote host on port 22, why not telling this machine to forward all the incoming traffic to the remote host we want to connect to in the first place.

So here is the configuration. We are using a computer in a campus which blocks external access to port 6667, but leaves port 22 opened.

We have a known host (let’say your home computer) with ssh port 22 opened.

Here is a graph representing the configuration:

ssh port forwarding

As you can see, we are going to use a longer path to connect to the IRC server by connecting to our home computer. Doing a Port Forwarding, we will create a tunnel between our local machine on port 1234 and the IRC server on port 6667. This way, we will be able to connect to the IRC network by simply connected on our local machine on port 1234.

Let’s get into the command line now. Firstly, we need to create the tunnel. To do so, connect to your home computer by SSH and forward your port 1234 on localhost to the IRC server (here irc.freenode.net) on port 6667.

tester@laptop:~$ssh myhomeuser@myhomenetwork.net -L 1234:irc.freenode.net:6667

Now, our tunnel is created (the purple connection on the graph) and port 1234 is open on localhost. The only thing left, is to connect to IRC using your favorite IRC client and provide it with the server located at localhost:1234.

In this example I’m going to connect to it using irssi, a text mode client for IRC network.

tester@laptop:~$ irssi -c localhost -p 1234

and here is what we get…

irssi connecting to irc.freenode.net through a tunnel on localhost port 1234

hey, hey, we are connected to freenode.net ;) .

Basically, you could use this trick to access any type of service. The only thing it require is to be able to connect to a remote machine outside of the firewalled network.

Thanks to Author, orignal link http://www.debuntu.org/2006/04/08/22-ssh-and-port-forwarding-or-how-to-get-through-a-firewall

How To: DPKG guide   July 1st, 2009

This tutorial will bring you through dpkg, the debian package manager. As I introduce apt, I will now introduce dpkg and show how to search which files are installed by a package, which packages are installed on your system ….

Search packages containing a file:

It happens quite often that you use binaries and want to know which package contains it. Let’s take the example of gaim, searching file containing bin/gaim will look like this:

$dpkg -S bin/gaim
gaim: /usr/bin/gaim
gaim: /usr/bin/gaim-send
gaim: /usr/bin/gaim-remote.py
gaim: /usr/bin/gaim-client-example
gaim: /usr/bin/gaim-send-async
gaim: /usr/bin/gaim-notifications-example.py

Getting installed package:

searching for packages intalled on your system which are named gaimsomething is achieved by triggering the following command:

$ dpkg –get-selections ‘gaim*’
gaim install
gaim-data install
gaim-dev install
gaim-xmms-remote purge

This actually give you the packages named like as well as their status (install|deinstall|purge), install stands for installed on your system ;) , deinstall means that the package has been removed but that the configuration files were kept, and purge means that the package was deinstalled plus all the configuration files coming along with.
Getting installed versions:

When a package is installed on your system, you might want to know which version it is. In the following example, the gaim version is 2.0.0.0beta3 and the debian revision 2ubuntu0, a brief summary of the package comes with as well as the package’state (ii,un,pn..):

$ dpkg -l ‘gaim*’
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name Version Description
+++-=========================-===================-===================================================
ii gaim 2.0.0beta3-2ubuntu0 multi-protocol instant messaging client un gaim-common (no description available)
ii gaim-data 2.0.0beta3-2ubuntu0 multi-protocol instant messaging client – data files
ii gaim-dev 2.0.0beta3-2ubuntu0 multi-protocol instant messaging client – development files
un gaim-gnome (no description available)
pn gaim-xmms-remote

Getting all files installed by a package:

Once a package is installed, you can get all the files installed by that package by trigerring the following command line:

$dpkg -l gaim

This can be pretty usefull to locate the configuration files of a software.

Getting the status of a package:

Finally, you can get the status of a package with the -s switch, this will output the state of the package along with the list of package it depends on, plus the description of the package.

$dpkg -s gaim

Hope this helps :) ,

Cheers

Thanks to Author, orignal link http://www.debuntu.org/2006/06/06/57-how-to-dpkg-guide