Friday, January 25, 2013

Creating Static Route in Linux

Static routes improves overall performance of your network.They are also useful in stub networks (i.e. there is only one link to the network). For example, each LAN (located at different offices) is connected VPN or lease line.
They are very helpfull in bandwidth saving also
So here we go :
Login in root :
to view routs:

root@sd-malanch.blogspot.com#  ip route show

Adding route in linux server


root@sd-malanch.blogspot.com# route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.01 dev eth1

root@sd-malanch.blogspot.com# /etc/init.d network restart





Connect with me on :

                            
                             

Thursday, June 30, 2011

Setting Up NAT Server in Linux




Here I have mentioned How to setup a NAT server in Linux in just few servers with the help  of iptable.
In my scenario I have tested with Red Hat enterprise Linux 6(Kernal 3.5) but I think I should work with most of linux kernels .
In my Environment there are two lan card on my linux system where I want to setup NAT server.

I am assuming a well configured linux system where iptable  and network connectivity is working with two NIC card and  IP address  configured are :

For eth0
IP=110.234.6.180/24 and gateway =110.234.6.170
(In most of practical scenario eth0 is given as public ip provided by your ISP)
For eth0
IP=192.168.0.251/24
Now login to terminal with superuser (root)
First you need to tell your kernel that you want to allow IP forwarding.
#echo 1 > /proc/sys/net/ipv4/ip_forward
 
Now  configure iptables to forward the packets from your internal network(192.168.0.0), on /dev/eth1, to your external network(110.234.6.180 i.e provided by your ISP) on /dev/eth0. You do this will the following commands:
 
# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
#  iptables -A FORWARD -i eth0 -o eth1 -m state   --state RELATED,ESTABLISHED -j ACCEPT
# iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT


Now now open /etc/sysctl.conf in your editor (in my case I am using vim)
#vim . /etc/sysctl.conf 
Change the line that says net.ipv4.ip_forward = 0to net.ipv4.ip_forward = 1

Now now edit  /etc/sysconfig/iptables-config in your editor (in my case I am using vim) make sure that:

IPTABLES_MODULES_UNLOAD, IPTABLES_SAVE_ON_STOP, IPTABLES_SAVE_ON_RESTART are all set to 'yes'.
Reboot machine and you are done.