I'm just starting out in Ubuntu/Linux, and have some trouble opening port 80 for incoming connections.

I ran the sudo ufw allow 80/tcp command, and when I run sudo ufw status the result looks like this:

Status: active

To                         Action      From
--                         ------      ----
22                         ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
22 (v6)                    ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)

However, I still get this error when trying to connect to the port with cURL.

Failed to connect to MY_IP_ADDRESS port 80: Connection refused

When I run this command netstat -ntlp | grep LISTEN to see what ports are open, I get this result:

(No info could be read for "-p": geteuid()=1000 but you should be root.)
tcp        0      0*               LISTEN      -               
tcp        0      0    *               LISTEN      -               
tcp6       0      0 :::22                   :::*                    LISTEN      -         

Which doesn't look that promising..

How do I open port 80 for incoming connections?

6 Answers 6


There is no program listening on port 80 so it's closed and you can't connect to it.

You can use

sudo python -m SimpleHTTPServer 80

For Python-3:

sudo python3 -m http.server 80

to start a simple web server listening on port 80, or install something like Apache (package apache2) if you want a full blown web server.

  • is it possible without sudo ?
    – John
    Sep 29, 2021 at 17:45

UFW is the Uncomplicated Firewall. It manages what ports on your computer can be opened for listening by an application. sudo ufw allow 80/tcp means allow TCP connections to port 80.

However, there is nothing actually listening in behind the port. To curl the port, there should be an application that will send a reply. This is typically called a server. As @Florian points out, you can use Python's SimpleHTTPServer to test it.

  • is this permanent? Nov 23, 2018 at 21:49
  • @Idemax About ufw, I don't know. About SimpleHTTPServer, it lasts for as long as you run it. Oct 21, 2021 at 7:18
  • Nope, not working ...
    – Berni
    Dec 16, 2022 at 12:18


sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT

Then to prevent it from losing the iptables configuration on restart, use:

sudo apt-get install iptables-persistent

well what worked for me was to use iptable

sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  • 4
    As a note this is not permanent. Will reset on reboot. Apr 16, 2017 at 22:31
  • @OliverDixon, yes correct
    – azerafati
    Apr 19, 2017 at 6:53

you can use sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT this accepts the port when it configures with the port to prevent from losing this terminal line of code you can use sudo apt-get install iptables-persistent The reason for sudo in the beggining of a command is to let it run as superuser the persistant uses it as a persistant connection to the port that is supplied. You can also use you can use Python's SimpleHTTPServer to test it! This was a great question! Thank You!


This works for me Just Allow the 80 from iptables

sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .