Feb 13 2008

Port forwarding

Category: LinuxBipin Balakrishnan @ 8:20 pm

Port forwarding (sometimes referred to as tunneling) is the act of forwarding a network port from one network node to another. This technique can allow an external user to reach a port on a private IP address (inside a LAN) from the outside via a NAT-enabled router.

Port forwarding allows remote computers (e.g. public machines on the Internet) to connect to a specific computer within a private LAN.

For example:

* forwarding ports 80 or 443 to run an HTTP webserver
* forwarding port 22 to allow Secure Shell access
* forwarding port 21 to allow FTP access

example:
Take vi editor copy and paste the script below. Replace “211.111.111.111″ ip with your Static ip and “192.168.0.22″ with your local ip. Portforwarding of http and ssh port is done here in the example.
save the script with a file name and give executing permission ie
chmod 777 <”filename”>
and execute it….

#!/bin/sh
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
/sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 -d 211.111.111.111 –dport 8181 -j DNAT –to 192.168.0.22:80
/sbin/iptables -A FORWARD -p tcp -i eth1 -d 192.168.0.22 –dport 80 -j ACCEPT

/sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 -d 211.111.111.111 –dport 2222 -j DNAT –to 192.168.0.22:22
/sbin/iptables -A FORWARD -p tcp -i eth1 -d 192.168.0.22 –dport 22 -j ACCEPT

Tags:


Feb 13 2008

Change default ssh port!!!

Category: LinuxBipin Balakrishnan @ 8:19 pm

Change your default ssh port and secure your network.As the default port of ssh is 22 anybody who want to attack your system will try first with it only.You can change the default port and give any other port you like say for example 2222.

edit the file “vim /etc/ssh/ssh_config”

Uncomment the line “# Port 22″

Give the port you want to set here.

Restart the ssh service

/etc/init.d/ssh restart

Login to this machine from remote machine by

ssh -p 2222 root@192.168.0.22

Tags:


Feb 13 2008

Share ubuntu Printer with Windows

Category: Ubuntu tips and TricksBipin Balakrishnan @ 8:17 pm

For sharing a local printer connected with Ubuntu os in the windows network we need to setup a samba server.For this first install samba in our server linux system.
apt-get install samba
apt-get install samba-common
apt-get install smbclient
apt-get install smbfs

edit the file smb.conf

sudo vim /etc/samba/smb.conf

[printers]
comment = All Printers
browseable = yes
path = /tmp
printable = yes
public = yes
writable = yes
create mode = 0700

# Windows clients look for this share name as a source of downloadable
# printer drivers
[print$]
comment = Printer Drivers
path = /var/lib/samba/printers
browseable = yes
read only = yes
guest ok = yes

To define SAMBA network users for your Ubuntu system, you may use the smbpasswd command.

smbpasswd -a bipin

where “bipin” is a user in the samba server

restart samba

sudo /etc/init.d/samba restart

Enjoy Printing!!!!!!

Tags:


Feb 13 2008

Ubuntu Networking Configuration

Category: Ubuntu tips and TricksBipin Balakrishnan @ 8:16 pm

Networking Configuration of Ubuntu is different from fedora or redhat because there is no “netconfig” command here.So we have to do it in some other way as follows.
Command: sudo vi /etc/network/interfaces

here we will get a page like this

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.33
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
# dns-* options are implemented by the resolvconf package, if installed

replace your own ip configuration here write and quite

issue sudo /etc/init.d/networking restart

Tags: , ,


Feb 13 2008

Install anything in Ubuntu!

Category: Ubuntu tips and TricksBipin Balakrishnan @ 2:10 pm

Having problem in installing anything in your Ubuntu OS.Take the terminal and issue
the two commands that you can use are:

sudo apt-get install PACKAGE and sudo aptitude install PACKAGE

eg: For installing webserver you have to issue

sudo apt-get install apache2

The sudo part of the command means you temporarily grant super-user/administrator rights to the command, provided you supply a correct user password

It’s also possible to search from the command-line like it is in Synaptic. Try this:

apt-cache search PACKAGE or aptitude search PACKAGE

To find several packages related to what we’re looking for, together with brief descriptions
apt-cache show PACKAGETo uninstall a package:

sudo apt-get remove PACKAGE and sudo aptitude remove PACKAGE

Removing configuration files as well:

sudo apt-get remove –purge PACKAGE and sudo aptitude purge PACKAGE or

sudo dpkg –purge remove PACKAGE

Tags:


Feb 13 2008

Setting timezone in Ubuntu

Category: Ubuntu tips and TricksBipin Balakrishnan @ 1:54 pm

to select and set the time zone.

command: tzconfig

(tzconfig copies the right time zone file from /usr/share/zoneinfo to /etc/localtime and puts the name of the timezone into /etc/timezone)

If your system does not have tzconfig, you may use something else.

tzselect

This will provide a set of different time zones to choose. If you would like to set the time to UTC, choose the option which says something like ‘none of the above’, or ‘none of these’ or something to this effect.

Or you can use

sudo dpkg-reconfigure tzdata

Tags:


Feb 13 2008

PHP mysql database connection with OOPs

Category: PHPBipin Balakrishnan @ 1:51 pm

create a class file first as this with file name createdb.php

<?php
class DB

{
var $con;
function getCon()
{
$hostname=”localhost”;
$username=”root”;
$password=””;

$con = mysql_connect($hostname,$username,$password);
if (!$con)
{
die(’Could not connect: ‘ . mysql_error());
}
mysql_select_db(”creditlimitIVR”, $con);
return $con;

}
?>

Include this file “createdb.php” in your program where you want to connect the database create a class and call the function as follows in the “main.php”

<?php
include_once(’createdb.php’);
$dbobject = new DB();
if (!$dbobject->getCon())
echo “Connection Failed”;
else
{
/* Do what you want */
}

}

Similarly u can add more functions in createdb.php for inserting, deleteing, selecting etc. And can call from the program like

function InsertCallInfo($number)
{

$date_time= date(’d-m-Y g:i a’);
$sql=”INSERT INTO `callerinfo` (`number`, `time`, `status`) VALUES (’$number’, ‘$date_time’, ‘ATTEMPTED’)”;
if (!mysql_query($sql))
die(’Error: ‘ . mysql_error());
}

I am calling it as $dbobject->InsertCallInfo($oneNo);
in the main.php program.
Add more and more functions and enjoy!!!!!

Tags:


Feb 13 2008

Web Service

Category: PHPBipin Balakrishnan @ 1:49 pm

A Web service (also Web Service) is defined by the W3C as “a software system designed to support interoperable Machine to Machine interaction over a network.” Web services are frequently just Web APIs that can be accessed over a network, such as the Internet, and executed on a remote system hosting the requested services.

The W3C Web service definition encompasses many different systems, but in common usage the term refers to clients and servers that communicate using XML messages that follow the SOAP standard. Common in both the field and the terminology is the assumption that there is also a machine readable description of the operations supported by the server written in the Web Services Description Language (WSDL).Once we write a webservice and host it in a server we can call it from any language likewise a function call.

The below is simple example that demonstrate a webservice written in PHP using the library “nusoap”.To download nusoap Click Here!
The client and server part here is written in PHP, you can use any language to to call the server functions.

program discreption: The client will sent two strings to the server and server append a new string and returns to the clinet.

copy and paste the code for the server

<?php

require_once(”nusoap/lib/nusoap.php”);

$server = new soap_server();

$server->configureWSDL(’Append’, ‘urn:Append’);

$server->register(’AppendString’,

array(’string_a’ =>’xsd:string’,’string_b’ =>’xsd:string’),

array(’return’=>’xsd:string’),

‘urn:Append’, // namespace

‘urn:Append#AppendString’, // soapaction

‘rpc’, // style

‘encoded’, // use

‘Testing webservice’ // documentation

);

function AppendString($string_a, $string_b)

{

$server_msg=”I am the message from the server”;

$msg=$string_a.$string_b.$server_msg;

return $msg;

}

$server->service($HTTP_RAW_POST_DATA);

?>

“http://localhost/server.php”
will show the namespace

copy and paste code for the client

<?php

require_once(”nusoap/lib/nusoap.php”);

$client=new soapclient1(’http://localhost/server.php?wsdl’, true);

$param=array(

’string_a’=>’I am the first string from the client…’,

’string_b’=>’and am the second string from the clinet….’,

);

$result =$client->call(’AppendString’, $param, ”, ”, false, true);

print_r ($result);

?>

Tags: , ,