0

I have a simple configuration, containing a two CentOS VMs. First one (VM1) has INTERNET access through eth0 and an internal network with VM2 on eth1.

ping from VM1 to www.google.com -> works
ping from VM1 to VM2(172.16.73.34) -> works
ping from VM2 to VM1(712.16.73.33) -> works
ping from VM2 to eth0 on VM1 (192.167.0.101) -> works
ping from VM2 to www.google.com -> 'UNKOWN HOST'

I want to be able to access the internet from VM2.

VM1 configurations:
 default gateway: 192.168.0.1
 eth0:
    inet addr: 192.168.0.101
    mask: 255.255.255.0
 eth1:
    inet addr: 172.16.73.33
    mask: 255.255.255.224
 resolv.conf:
    nameserver: 213.154.124.1
    nameserver: 193.231.252.1

-

VM2 configurations:
 default gateway: 172.16.73.33
 eth1: 
    inet addr: 172.16.73.34
    mask: 255.255.255.224
 resolv.conf:
    nameserver: 213.154.124.1
    nameserver: 193.231.252.1

I've added some rules to IPTABLES following some tutorial:

/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -F INPUT 
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -F OUTPUT 
/sbin/iptables -P FORWARD DROP
/sbin/iptables -F FORWARD 
/sbin/iptables -t nat -F
/sbin/iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
/sbin/iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth1 -j MASQUERADE
/sbin/iptables-save > /etc/sysconfig/iptables
/sbin/service iptables restart

Also, in the /etc/sysctl.conf file, I have net.ipv4.ip_forwarding = 1.

What am I missing in order to be able to ping to www.google.com from VM2?

0

You are masquerading the wrong interface. It should be as follows.

/sbin/iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.