How to Open Ports on Linux Server

This article will provide a guide for how to open ports on Linux server. This guide requires root-equivalent access.

Launch 100% SSD VPS from $2.49/mo!

How to Open Ports with iptables

All Linux distributions are packaged with iptables, a software firewall.

In our examples, we will demonstrate how to open ports for both inbound and outbound tcp and udp traffic on IPv4. For IPv6-related changes, use ip6tables.

To open ports 4081-4085 for inbound tcp traffic over IPv4, use the following command:

iptables -I INPUT -p tcp --dport 4081:4085 -j ACCEPT

To open ports 4081-4085 for inbound udp traffic over IPv4, use the following command:

iptables -I INPUT -p udp --dport 4081:4085 -j ACCEPT

To open ports 4081-4085 for outbound tcp traffic over IPv4, use the following command:

iptables -I OUTPUT -p tcp --sport 4081:4085 -j ACCEPT

To open ports 4081-4085 for outbound tcp traffic over IPv4, use the following command:

iptables -I OUTPUT -p udp --dport 4081:4085 -j ACCEPT

How to Open Ports with firewalld

To open ports 4081-4085 with firewalld, use the following commands:

firewall-cmd --zone=public --permanent --add-port=4081-4085/tcp
firewall-cmd --reload

How to Open Ports with UFW

To open ports 4081-4085 with Uncomplicated Firewall (UFW), use the following commands:

sudo ufw allow 4081:4085
sudo ufw enable

Launch 100% SSD VPS from $2.49/mo!

Conclusion

These examples have demonstrated how to open ports on Linux server using iptables.

  • iptables, firewall, waf, network, network configuration, linux server, linux, ufw, firewalld
  • 5 Users Found This Useful
Was this answer helpful?

Related Articles

How to Create Sudo User on CentOS

This article provides step-by-step setup guide for adding Sudo user to CentOS system. The sudo...

How to Use Sudo

This article provides a guide to using a Sudo user on CentOS server. From the command line,...

Set Server Time Zones with Timedatectl

This article provides a guide to setting the server time and server time zone settings using...

htaccess RewriteRule Examples

Here are some useful mod_rewrite RewriteRule redirect examples that you can use in your .htaccess...

Using htaccess File to Block IPs

If your webserver is Apache, you may block access to your website from specific IP addresses...