I'm new on CentOS. I have a CentOS 6.4 system having 2 NIC cards. I want to setup a gateway so I can get internet from public ip over 1st nic card (eth1) and forward the network over 2nd nic card (eth2) so it can be accessible to my local network. I made a DNS server in same system. my gateway system is able to ping to both DNS and google but my client systems are not.
I tried to set the iptables rules it works ping to local gateway but unable to ping to public DNS and www.google.com from client system..when I ping to google.com said that host is unreachable.
How can I implement this, please help me?
- public ip is(eth1) : x.x.x.x
- my local network is (eth2) : 192.168.x.x
I used this for setting up iptables:
iptables --table nat --append POSTROUTING --out-interface eth1 -j MASQUERADE iptables --append FORWARD --in-interface eth2 -j ACCEPT echo 1 > /proc/sys/net/ipv4/ip_forward
Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface local ip 0.0.0.0 255.255.255.0 U 0 0 0 eth2 public ip 0.0.0.0 255.255.255.0 U 0 0 0 eth1 0.0.0.0 my local gateway 0.0.0.0 UG 0 0 0 eth2
Chain PREROUTING (policy ACCEPT 9761 packets, 1239K bytes) pkts bytes target prot opt in out source destination Chain POSTROUTING (policy ACCEPT 14666 packets, 1001K bytes) pkts bytes target prot opt in out source destination 345 41722 MASQUERADE all -- * Auto_eth1 0.0.0.0/0 0.0.0.0/0 Chain OUTPUT (policy ACCEPT 15011 packets, 1043K bytes) pkts bytes target prot opt in out source destination
Please tell me what are changes I have to do in configuration.