Software & AppsOperating SystemLinux

How To troubleshoot “connection refused” error on port 80 in Ubuntu server

Ubuntu 15

If you’re running a web server on Ubuntu, you may occasionally encounter a “connection refused” error when trying to access your site via port 80. This error means that your server is not accepting connections on that port. This can be due to a variety of reasons, including firewall settings, ISP restrictions, or other processes using the port. In this article, we’ll walk through some steps to troubleshoot and resolve this issue.

Checking for Other Processes

The first step in troubleshooting a “connection refused” error on port 80 is to check if any other processes are already using that port. You can do this by running the netstat -tlpn command in your terminal. This command displays a list of all the network connections on your server.

The -t option tells netstat to display TCP connections, -l tells it to display listening sockets (i.e., ports that are waiting for incoming connections), -p shows the PID and name of the program to which each socket belongs, and -n displays numerical addresses instead of trying to determine symbolic host, port or user names.

If you see any processes using port 80, you’ll need to stop them or configure them to use a different port.

Checking Firewall Settings

The next step is to check your firewall settings. If your firewall is blocking port 80, you won’t be able to establish a connection. On Ubuntu, you can use the ufw command to manage your firewall.

To check the status of your firewall, run sudo ufw status. If your firewall is active, you can temporarily disable it with sudo ufw disable to see if this resolves the issue. Remember to re-enable it afterwards with sudo ufw enable.

If you need to allow connections on port 80 through your firewall, you can do so with the command sudo ufw allow 80.

Checking with Your ISP or Network Administrator

In some cases, your ISP or network administrator may be blocking port 80. This is often the case with residential internet connections, as ISPs want to discourage home users from running web servers. If you suspect this may be the case, you’ll need to contact your ISP or network administrator to confirm and see if they can open up port 80 for you.

Resetting IPTables

If none of the above steps have resolved the issue, there may be a hidden or unknown rule in your iptables that is causing the problem. You can reset your iptables to their default state with the following commands:

sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -t nat -F
sudo iptables -t mangle -F
sudo iptables -F
sudo iptables -X

These commands will flush all the rules in your iptables, allowing all incoming, outgoing, and forwarded connections. Use these commands with caution, as they will remove any custom rules you have set up.

Conclusion

Troubleshooting a “connection refused” error on port 80 in Ubuntu server can be a complex process, as there are many potential causes. However, by methodically checking for other processes using the port, adjusting firewall settings, consulting with your ISP or network administrator, and resetting your iptables, you can identify and resolve the issue.

What does the “connection refused” error on port 80 mean?

The "connection refused" error on port 80 means that your server is not accepting connections on that port. This can be due to firewall settings, ISP restrictions, or other processes using the port.

How can I check if there are any other processes using port 80?

You can check for other processes using port 80 by running the netstat -tlpn command in your terminal. This command will display a list of all the network connections on your server, and you can look for any processes using port 80.

How can I check my firewall settings in Ubuntu?

To check your firewall settings in Ubuntu, you can use the ufw command. Running sudo ufw status will show you the status of your firewall. You can temporarily disable the firewall with sudo ufw disable and re-enable it with sudo ufw enable. To allow connections on port 80 through your firewall, use sudo ufw allow 80.

What should I do if my ISP or network administrator is blocking port 80?

If you suspect that your ISP or network administrator is blocking port 80, you should contact them to confirm and see if they can open up the port for you. Some ISPs block port 80 on residential internet connections to discourage users from running web servers.

How can I reset my iptables to resolve the issue?

If none of the previous steps have resolved the issue, you can reset your iptables to their default state. Use the following commands:

sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -t nat -F
sudo iptables -t mangle -F
sudo iptables -F
sudo iptables -X

These commands will flush all the rules in your iptables, allowing all incoming, outgoing, and forwarded connections. Note that this will remove any custom rules you have set up, so use them with caution.

Leave a Comment

Your email address will not be published. Required fields are marked *