Tuesday, September 1, 2009

How to make Ubuntu/Debian as a router

Here is your Ubuntu serve box with two interfaces,
eth0-------------Internet
eth2-------------Internal
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 192.168.50.0 netmask 255.255.255.0 {
range 192.168.50.100 192.168.50.200;
option broadcast-address 192.168.50.255;
option routers 192.168.50.1;
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
address 192.168.50.1
netmask 255.255.255.0
network 192.168.50.0
broadcast 192.168.50.255
gateway 192.168.50.1

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

#/etc/init.d/network restart

check ip by ifconfig eth2, it will have 192.168.50.1 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
0
# 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 (74.125.77.103) 56(84) bytes of data.
64 bytes from ew-in-f103.google.com (74.125.77.103): icmp_seq=1 ttl=52 time=30.7 ms
64 bytes from ew-in-f103.google.com (74.125.77.103): icmp_seq=2 ttl=52 time=30.2 ms
64 bytes from ew-in-f103.google.com (74.125.77.103): icmp_seq=3 ttl=52 time=30.3 ms
^C
--- 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

Huraaaa!

6 comments:

  1. 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:
    Debian:
    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.

    jeu

    ReplyDelete
  2. 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.

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

    ReplyDelete
  4. Linksys LGS124 Ethernet Switch in UAE, 24-Port Unmanaged Ethernet Switch in UAE, Gigabit Ethernet Switch in UAE
    https://gccgamers.com/linksys-lgs124-24.html
    Linksys LGS124 in UAE, Safe Shopping Multiple Payment Options Express Delivery GCC Gamers Moneyback Guarantee.
    1633064013169-10

    ReplyDelete