Virtual server EC2 receives requests but cannot access another host

Asked

Viewed 107 times

0

I have a virtual machine on Amazon AWS with Ubuntu where I installed Apache2, PHP5 and Mysql. It was all running well, well configured, my site working very well on it.

Until suddenly the virtual machine stopped accessing other hosts. This happens for any request. I discovered this when a PHP script started to give error Connection timed out when using the function file_get_contents().

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

I went to the server command line, via SSH, and tried to ping an external host ping google.com and nothing. I tried to use the apt-get to update the system apt-get update and 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 usually receives the request and returns the site to the browser. That is, the internet connection is existing.

Another detail is that, this access to file_get_contents() PHP that I am trying to do is also on the same site, not an external site, and yet 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 might be going on?

1 answer

1


For those who had the same problem as me, I went deep until I discovered that the nameserver was set to Amazon ip.

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

nameserver 8.8.8.8
nameserver 8.8.4.4

and it worked. I hope this helps someone.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.