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.

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 command:

sudo ufw allow 4081:4085

Conclusion

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

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

Related Articles

View Server PHP Environment with phpinfo.php

The phpinfo() function outputs a huge amount of information about the system you're using, such...

How to Change Root Password Using SSH

This article explains the method of changing the root password on a Linux Server using SSH....

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...