বৃহস্পতিবার, ২৩ সেপ্টেম্বর, ২০১০

Linux Server as a Gateway Server


Linux Router (CentOS) as a gateway

Network Diagram:







IP address of NIC :

Eth1: [WAN]

IP: 120.50.31.188

SM: 255.255.255.192

GW: 120.50.31.129

Eth0: [LAN]

IP: 192.168.100.1

SM: 255.255.255.0

Setup IP address:

#vi /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1

BOOTPROTO=none

ONBOOT=yes

NETMASK=255.255.255.192

IPADDR=120.50.31.188

GATEWAY=120.50.31.129

TYPE=Ethernet

#vi /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth0

BOOTPROTO=none

ONBOOT=yes

NETMASK=255.255.255.0

IPADDR=192.168.100.1

TYPE=Ethernet

And /etc/sysconfig/network will show:

NETWORKING=yes

HOSTNAME=Rubel

Setup DNS address:

nameserver 116.212.104.81
nameserver 116.212.104.82

Enable IP Forwarding:

#vi /etc/sysctl.conf

net.ipv4.ip_forward = 0 to net.ipv4.ip_forward = 1

Flush rules:

#iptables –F

#iptables –t nat –F

NAT enable:

#iptables –t nat –A POSTROUTING –o eth1 –j MASQUERADE

#iptables –A FORWARD –i eth0 –j ACCEPT

edit the file etc/sysconfig/iptables-config

IPTABLES_MODULES_UNLOAD, IPTABLES_SAVE_ON_STOP, and IPTABLES_SAVE_ON_RESTART all set to “yes

Save the Rules to /etc/sysconfig/iptables

#iptables-save

Restart iptables:

#service iptables restart

Restart Network:

#service network restart

Now Setup ip configuration on Client PC and ping the gateway 192.168.100.1 and ping www.google.com.