Tuesday, September 1, 2009

How to make Ubuntu/Debian as a router

Here is your Ubuntu serve box with two interfaces,
Note: Your Internet is running using eth0.
Step1: Install DHCP Server

#apt-get install dhcp3-server

Step 2: Configure the DHCP server

Edit the /etc/dhcp3/dhcpd.conf file and add your domain, dns, ip range and other options.

option domain-name "oslohosting.com";
option domain-name-servers ns1.yourdns.com, xx.xx.xx.xx;
# Internal network
subnet netmask {
option broadcast-address;
option routers;
default-lease-time 600;
max-lease-time 7200;

Step 3: Configure the Internal interface (eth2) with static IP.
Edit the /etc/network/interfaces file and add following

iface eth2 inet static

Step 4: Restart network and verify the eth2 interface's IP.

#/etc/init.d/network restart

check ip by ifconfig eth2, it will have ip, if not please restart the interface/netwrok service, you can also restart your machine if it is not in production environment.

Step 5: Restart the DHCP server.

#/etc/init.d/dhcp3-server restart

If every thing is ok, it should run successfully,
Note: If your interface does not have any IP it might give error and does not restart, first configure you internal interface.

Step 6: Test the DHCP server.

connect the cable on interface eth2 and other side to your second pc, you will get the IP from 192.168.50.x range.
Open the syslog messeges with
#tail -f /var/log/syslog
of your debian box, it will also notify with leased ip and detail of requested machine.

Step 7: Enable forwarding
# cat /proc/sys/net/ipv4/ip_forward
# echo 1 > /proc/sys/net/ipv4/ip_forward

or open the file manually and uncomment

# nano /etc/sysctl.conf

net.ipv4.ip_forward = 1

Step 8: Add IPTABLES rule for NAT

Type following at command line

#iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Step 9: Final Testing

Your second Pc attached to LAN have internal ip, ping to www.google.com, it should get reply, if not review and trouble shoot carefully.

imran@imran-laptop:~$ ping www.google.com
PING www.l.google.com ( 56(84) bytes of data.
64 bytes from ew-in-f103.google.com ( icmp_seq=1 ttl=52 time=30.7 ms
64 bytes from ew-in-f103.google.com ( icmp_seq=2 ttl=52 time=30.2 ms
64 bytes from ew-in-f103.google.com ( icmp_seq=3 ttl=52 time=30.3 ms
--- www.l.google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 30.298/30.451/30.729/0.242 ms



Josh said...

Here are some easy 3 steps.

1. download the source from http://ftp.iptel.org/pub/ser/LATEST-IS-0.9.6/src/

2. upgrade your build utils by downloading the following packages needed packages for compiling all the modules:
libmysqlclient-dev for libmysqlclient
libpq-dev for libpq
libexpat1-dev for libexpat
libxml2-dev for libxml2
libradiusclient-ng-dev for libradiusclient (you can download the
package from http://apt.sip-router.org/debian/dists/unstable/main/binary-i386/libradiusclient-ng-dev_0.5.1-0.5_i386.deb ).

Since my system was quite updated i have just issued " apt-get install libpq-dev " on shell the as root on ser extracted folder issued make install. everythings were successfully compiled and installed.

i recommend u to do the following on section 2 of this link http://ftp.iptel.org/pub/ser/0.9.6/doc/INSTALL

3. then follow the installation of the sip User agent (client ) on http://www.en.voipforo.com/Telephones/sjphone-configuration.php

enjoy urself.


javieth said...

In addressing the router enables wireless networking connection, really amazing what Technology has changed these days. I like meeting new things. This is why i have come to this blog, I find it very interesting.This is like
costa rica investment opportunities really interesting too.

Anonymous said...

Muchas gracias, lo he probado paso a paso y todo ha salido genial!!
Buen trabajo ;))

Anonymous said...

Thanks a lot.

Lalit Sharma said...

Thanks for sharing this blog.This is very helpful and solving problems easily related to router problems. Good work. Please visit this link ----- Linksys Router Technical Support .