Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Open Ports in Linux Server Firewall

Learn how to open ports in linux server firewall with clear steps, practical context, and useful troubleshooting guidance.

Table of Contents

This updated guide examines How to Open Ports in Linux Server Firewall and organizes the essential facts, background, and practical takeaways in clear American English.

Method 1of 3:

Using Uncomplicated Firewall for Ubuntu

  1. How to Open Ports in Linux Server Firewall — contextual image 1 Log in to your server. If you're using Ubuntu on your desktop, pressCtrl+Alt+Tto open a terminal window.
  2. How to Open Ports in Linux Server Firewall — contextual image 2 Typesudo ufw status verboseand press↵Enter. If UFW is already running, you'll see a status message, as well as a list of any firewall rules (including opened ports) that already exist.[1]
    • If you see a message that says Status: inactive , typesudo ufw enableat the prompt and press↵Enterto start the firewall.
  3. How to Open Ports in Linux Server Firewall — contextual image 3 Usesudo ufw allow [port number]to open a port. For example, if you want to open the SSH port (22), you'd typekbdand press↵Enterto open the port. There's no need to restart the firewall, as the change will take effect immediately.[2]
    • If the port you're opening is for a service listed in/etc/services, you just type the service's name instead of the port number. Example:sudo ufw allow ssh.
    • To open a specific range of ports, use the syntaxsudo ufw allow 6000:6007/tcp, replacing6000:6007with the actual range. If the range is UDP ports, replacetcpwithudp.
    • To specify an IP address that can access the port, use this syntax:sudo ufw allow from 10.0.0.1 to any port 22. Replace10.0.0.1with the IP address, and22with the port you want to open to that address.
  4. How to Open Ports in Linux Server Firewall — contextual image 4 Delete firewall rules that aren't needed. Any ports that aren't specifically opened are blocked by default. If you open a port and decide you want to close it, use these steps:
    • Typesudo ufw status numberedand press↵Enter. This displays a list of all firewall rules, each beginning with a number to represent it in the list.
    • Identify the number at the beginning of rule you want to delete. For example, let's say you want to remove the rule that opens port 22, and that rule is listed on line 2.
    • Typesudo ufw delete 2and press↵Enterto remove the rule at line 2.

Method 2of 3:

Using ConfigServer Firewall

  1. How to Open Ports in Linux Server Firewall — contextual image 5 Log in to your server. If you're not logged in as the root user, you cansuto root to adjust your configuration.
  2. How to Open Ports in Linux Server Firewall — contextual image 6 Go to directory that contains your CSF config file. The file is calledcsf.conf, and it's saved to/etc/csf/csf.confby default.[3]To do this, typecd /etc/csfand press↵Enter.
  3. How to Open Ports in Linux Server Firewall — contextual image 7 Opencsf.confin a text editor. You can use any text editor you wish, such as vim or nano.
    • To open csf.conf in vim, typevim csf.configand press↵Enter.
  4. How to Open Ports in Linux Server Firewall — contextual image 8 Add an incoming port to theTCP_INlist. TCP ports. Once you have the file open, you will seeTCP_INandTCP_OUTsections. TheTCP_INsection lists open inbound TCP ports separated by commas. The ports are in numerical order to make things easy, but it's not required that the ports you stick to the order. You can add ports to the end of the sequence, just separate them with commas.
    • For example, let's say you want to open port 999, and the current open ports are20, 21, 22, 25, 53, 80, 110, 143, 443, 465, 587, 993, 995.
    • After adding port 999 to the list, it will look like this:20, 21, 22, 25, 53, 80, 110, 143, 443, 465, 587, 993, 995, 999.
    • To get into insertion/typing mode in vim, press theikey on the keyboard.
  5. How to Open Ports in Linux Server Firewall — contextual image 9 Allow outgoing TCP to theTCP_OUTlist. Just as you did with the incoming port, add any outbound TCP ports you'd like to open to theTCP_OUTlist.
  6. How to Open Ports in Linux Server Firewall — contextual image 10 Save your changes and exit the file. Follow these steps to save and exit the file:
    • Press theEsckey.
    • Type:wq!.
    • Press↵Enter.
  7. How to Open Ports in Linux Server Firewall — contextual image 11 Typeservice csf restartand press↵Enter. This restarts the firewall and opens the new ports.
    • To deny a port, re-open the file, delete the port, save the file, and then re-start the firewall.

Method 3of 3:

Using Advanced Policy Firewall

  1. How to Open Ports in Linux Server Firewall — contextual image 12 Log in to your server. If you're not logged in as the root user, you cansuto root to adjust your configuration.
  2. How to Open Ports in Linux Server Firewall — contextual image 13 Go to the directory that contains your APF config file. The file you're looking for is calledconf.apf, and it'll be in/etc/apfby default.[4]Typecd /etc/apfto enter that directory.
  3. How to Open Ports in Linux Server Firewall — contextual image 14 Openconf.apfin a text editor. You can use any text editor you wish, such as vim or nano.
    • To open conf.apf in vim, you'd typevim conf.apfand press↵Enter.
  4. How to Open Ports in Linux Server Firewall — contextual image 15 Add inbound ports to theIG_TCP_CPORTSlist. Once you have the file open, you will seeIG_TCP_CPORTSandEG_TCP_CPORTSsections. TheIG_TCP_CPORTSsection lists open inbound ports separated by commas. The ports are listed in numerical order to make things easy, but it's not required to stick with it. You can add ports to the end of the sequence, just separate them with commas.
    • For example, let's say you want to open port 999, and the current open ports are20, 21, 22, 25, 53, 80, 110, 143, 443, 465, 587, 993, 995.
    • After adding port 999 to theIG_TCP_CPORTSlist, it will look like this:20, 21, 22, 25, 53, 80, 110, 143, 443, 465, 587, 993, 995, 999.
    • To get into insertion/typing mode in vim, press theikey on the keyboard.
  5. How to Open Ports in Linux Server Firewall — contextual image 16 Allow outbound ports to theEG_TCP_CPORTSlist. Just as you did with the incoming port, add any outbound TCP ports you'd like to open to the theEG_TCP_CPORTSlist.
  6. How to Open Ports in Linux Server Firewall — contextual image 17 Save your changes and exit the file. Follow these steps to save and exit the file:
    • Press theEsckey.
    • Type:wq!.
    • Press↵Enter.
  7. How to Open Ports in Linux Server Firewall — contextual image 18 Typeservice apf -rand press↵Enter. This restarts the APF firewall and opens the new ports.
    • To deny a port, re-open the file, delete the port, save the file, and then re-start the firewall.

FAQ

What is How to Open Ports in Linux Server Firewall about?

It provides a structured overview of open, explains the main context, and highlights practical takeaways for readers.

Why does this topic matter?

Understanding the main concepts helps readers evaluate the issue, avoid common mistakes, and make better-informed decisions.

How should readers use this information?

Use the guidance as a practical starting point, confirm details that may have changed, and follow current product, safety, or security recommendations.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.