Debian / Ubuntu: Apache2 Change Default Port / IP Binding

Question: How do I change Apache 2 default port under Debian / Ubuntu Linux? I’ve couple of public IPv4 address assigned by my ISP, how do I force Apache2 to listen to a specific IP address? How do I change Apache2 IP address binding?

Answer: You can easily change the port and other settings using following directives:

Apache Listen Directive

The Listen directive instructs Apache to listen to more than one IP address or port; by default it responds to requests on all IP interfaces, but only on the port given by the Port directive. You can use this directive multiple times.

Task: Change Apache port

Open /etc/apache2/ports.conf file, enter:
# vi /etc/apache2/ports.conf
$ sudo vi /etc/apache2/ports.conf
To make the server accept connections on both port 8010, enter:
Listen 8010
To make the server accept connections on both port 80 and port 8010, use:
Listen 80
Listen 8010

Task: Accept connections on specific IP / interface port

You need to use network interfaces IP address. For example, to make the server accept connections on IP and port 80, enter:
To make the server accept connections on two specified interfaces and port numbers, enter:

Save and close the file. Restart Apache 2 webserver:
# /etc/init.d/apache2 restart
$ sudo /etc/init.d/apache2 restart

How do I verify port and IP binding working ?

Use netstat command to find out if Apache is listening on a specific port or not, use:
# netstat -tulpn
# netstat -tulpn | grep :80
# netstat -tulpn | grep :8010
# netstat -tulpn| grep

Sample output:

tcp        0      0  *               LISTEN     19306/apache2

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 12 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
12 comments… add one
  • Felipe Ferreira Nov 25, 2008 @ 18:16

    Great Post.
    Simple and easy to understand.
    But I was wondering how I could server multiple IPs,Ports.
    How would the Virtual Hosts file look like?
    Is it enough to change the
    NameVirtualHost ?


  • Goncorpius Oct 23, 2010 @ 11:46

    Plz , i change port apache ia 81 but in address on browser my type is

    localhst:81 or not search foulder content php www

    i edit port is 80 is ok

    why ?? plz

    • Cesar Dec 2, 2010 @ 15:38

      I’m with the same problem…

      • Khan Bhai Mar 16, 2012 @ 15:39

        my Apache server was not running but when i close all my start up programs like skype and utorrent then it work and apache server running.
        start up programs sometimes use the port of apache!

  • Melroy van den Ber Dec 13, 2010 @ 23:26

    They apparently forgot to say to change the following also:

    sudo nano /etc/apache2/ports.conf

    In file ports.conf, line 8.
    NameVirtualHost *:80

    Change to:
    NameVirtualHost *:8080

    sudo nano /etc/apache2/sites-available/default

    In file default, line 1.

    Change to:

    Eventually restart your apache2 server ;)

    sudo /etc/init.d/apache2 restart

    Good luck!

    Kind regards,
    Melroy van den Berg

    • ulysses Jan 2, 2012 @ 22:53

      oh thanks that helped alot

      • slavka Apr 18, 2013 @ 21:51

        Using specific ip and port but getting:
        no listening sockets available, shutting down
        Unable to open logs
        Action ‘start’ failed.
        The Apache error log may have more information.

  • praveen Jul 4, 2011 @ 9:38

    what is the difference between the port 80 and 8080?

  • gauchoproluanco Feb 22, 2012 @ 16:15

    Hi guys,

    Like always, brilliant, simple and easy!!!



  • LG Jun 11, 2012 @ 16:16

    Something important!!!!

    If you just change the port or add more ports here, you will likely also
    have to change the VirtualHost statement in


  • Peyman Aug 13, 2012 @ 7:31

    I get the following error:
    (99)Cannot assign requested address: make_sock: could not bind to address **.***.**.***:80
    what can I do?

  • Nisarg Pandya May 6, 2013 @ 20:53

    Hi Guys,

    Thank you very much for all the information and the comments.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum