Pages

Wednesday, January 12, 2011

Building a router with debian lenny

Make sure you have installed the operating system is Debian Lenny on your pc. 
After the PC in the next install is the IP address configuration on each PC lan Card, 
assumptions: 

Eth0 ==> 192.168.2.51 ==> connected to the Internet 
Eth1 ==> 192.168.10.1 ==> Local network connected 

Setting ip with the command: 

 # nano /etc/network/interfaces 

then edit the file with the following: 

auto eth0 
IFACE eth0 inet static 
address 192.168.2.13 
netmask 255.255.255.0 
network 192.168.2.0 
broadcast 192.168.2.255 
gateway 192.168.2.1 

auto eth1 
IFACE eth1 inet static 
address 192.168.10.1 
netmask 255.255.255.0 
network 192.168.10.0 
broadcast 192.168.10.255 

save by pressing ctrl + O and ctrl + X 

after that our DNS settings, here we use Google in a way their DNS 

#nano /etc/resolv.conf 
write 
    nameserver 8.8.8.8 
    nameserver 8.8.4.4 

save by pressing ctrl + O and ctrl + X 

after setting the IP and DNS then restart networknya way 
    # /etc/init.d/networking restart 

See the configuration 
    # Ifconfig 

If you have not come then we have to do eth-ups that we have been setting 
    # Ifup eth0 
    # Ifup eth1 

See the configuration 
    # Ifconfig 

then turn on ip forwarding in a way: 
# nano /etc/sysctl.conf 

Find the following line 
#net.ipv4.ip_forward = 1 

After that remove the fence so that it becomes 
net.ipv4.ip_forward = 1 

ipforward input with the command 
# echo 1> /proc/sys/net/ipv4/ip_forward 

Check whether the value ip_forward if the result of 1 means success 
# cat /proc/sys/net/ipv4/ip_forward 

Then enter the IPTABLES script with the command 
# iptables-t nat-A POSTROUTING-o eth0-j MASQUERADE 

NOTE: The above is eth eth0 is connected to the Internet 
Save IPTABLES with the command 
# iptables-save 

So PC ROUTER you are ready, but above IPTABLES configuration will be lost if we restart the PC (computer). So to prevent IPTABLES lost when the computer is restarted we must make for IPTABLES script is loaded automatically when the computer starts (boots). 
So how .. 

The trick is as follows: 
#nano /etc/rc.local 

Put the IPTABLES script before exit 0, so as follows: 
    echo 1> /proc/sys/net/ipv4/ip_forward 
    iptables-t nat-A POSTROUTING-o eth0-j MASQUERADE 
    exit 0 

save by pressing ctrl + O and ctrl + X 
after that, please restart / reboot your computer 
    #reboot 

Done ...

No comments:

Post a Comment