Linux – Ping reply not getting to LAN machines but getting in Linux router Gateway

gatewaylinuxrouting

I have configured Ubuntu 12.04 as Gateway machine.its having two interfaces

 eth0 with ip  192.168.122.39(Static) and 

 eth1 connected to modem with ip address 192.168.2.3(through DHCP).

ip-forwarding is enabled in router box.

Client machine is configured as:

ip address 192.168.122.5 and gateway 192.168.122.39

Client machines can ping router box(192.168.122.39).but when pinged 8.8.8.8 reply is not reaching Client machines but in the tcpdump output on gateway i can see echo request for 8.8.8.8 but never echo reply.Is this because of 122.5 not forwarding request to 2.0 network.Can u please help me in fixing this.

edit:STEPS FOLLOWED

This machine is running as XEN HVM.

Router machine:two interfaces eth0:192.168.122.39(static ip)
eth1:192.168.2.3
on router

  iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE 

 iptables -A FORWARD -i eth0 -j ACCEPT

 iptables -A FORWARD -i eth1 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT

ptables -A FORWARD -i eth0 -o eth1 -j ACCEPT

On the client machine

 ping 8.8.8.8

on the gateway tcpdump result

tcpdump -v -i eth0

192.168.122.1 is the virtual bridge

tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes

14:17:26.352383 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
192.168.122.1 > google-public-dns-a.google.com: ICMP echo request, id 1541, seq 8395,
length 64

14:17:26.938156 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
192.168.122.1 > google-public-dns-a.google.com: ICMP echo request, id 1513, seq 10735, length 64

tracepath 8.8.8.8. from Client machine:

tracepath 8.8.8.8

1: 192.168.122.39 0.046ms
pmtu 1500

1: 192.168.122.5 0.259ms

1: 192.168.122.5 0.188ms

2: no reply

3: no reply

Best Answer

Your modem doesn't know how to reach 192.168.122.0/24 network. You have to do NAT on your router or you have to tell your modem that 192.168.122.0/24 should be routed through 192.168.2.3.

For NAT try with these rules:

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE   
iptables -A FORWARD -i eth0 -j ACCEPT
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT

Restart your firewall to flush old rules.

Related Topic