Virtual server EC2 receives requests but can not access another host

0

I have a virtual machine in Amazon AWS with Ubuntu where I installed Apache2, PHP5 and MySql myself. Everything was running well, well configured, my site working very well on it.

Until suddenly the virtual machine has stopped accessing other hosts. This happens for any request. I discovered this when a PHP script came up with a connection timed out error when using the file_get_contents() function.

<?php echo file_get_contents('http://example.com'); ?>

I went to the server's command line, via SSH, and tried to ping an external host ping google.com and nothing. I tried to use apt-get to update the system apt-get update and it also does not connect.

That is, my EC2 server is not connecting to anything external.

The funny thing is that if I try to access the site, the server normally receives the request and returns the site to the browser. That is, the internet connection is in place.

Oto detail is that this access to file_get_contents() of PHP that I'm trying to do is also on the same site, not on an external site, and yet on timed out.

Here the result of the command netstat -lnp :

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      957/sshd        
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1098/mysqld     
tcp6       0      0 :::22                   :::*                    LISTEN      957/sshd        
tcp6       0      0 :::443                  :::*                    LISTEN      1145/apache2    
tcp6       0      0 :::80                   :::*                    LISTEN      1145/apache2    
udp        0      0 0.0.0.0:68              0.0.0.0:*                           560/dhclient    
udp        0      0 0.0.0.0:18032           0.0.0.0:*                           560/dhclient    
udp6       0      0 :::60689                :::*                                560/dhclient    
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name    Path
unix  2      [ ACC ]     STREAM     LISTENING     8236     785/dbus-daemon     /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     6500     1/init              @/com/ubuntu/upstart
unix  2      [ ACC ]     STREAM     LISTENING     8549     965/acpid           /var/run/acpid.socket
unix  2      [ ACC ]     SEQPACKET  LISTENING     6797     324/systemd-udevd   /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     8919     1098/mysqld         /var/run/mysqld/mysqld.sock

Here the result of eating iptables -L :

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 

What could be happening?

    
asked by anonymous 09.05.2014 / 13:49

1 answer

1

For those who had the same problem as me, I went deep to find out that the nameserver was set to amazon ip.

So I edited /etc/resolv.conf and put google nameservers

nameserver 8.8.8.8
nameserver 8.8.4.4

and it worked. I hope this helps someone.

    
09.05.2014 / 21:37