HowTo: UNIX / Linux Open TCP / UDP Ports

htt‮:sp‬//www.lautturi.com
HowTo: UNIX / Linux Open TCP / UDP Ports

To open a TCP or UDP port on a Unix or Linux system, you can use the iptables command to create a firewall rule that allows incoming traffic on the specified port.

Here is an example of how to open TCP port 80 (HTTP) using iptables:

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

This command will create a firewall rule that allows incoming traffic on TCP port 80. The -A option tells iptables to append the rule to the end of the list of rules, the -p option specifies the protocol (TCP), the --dport option specifies the destination port (80), and the -j option specifies the action to take (ACCEPT).

To open UDP port 53 (DNS), you can use the following command:

iptables -A INPUT -p udp --dport 53 -j ACCEPT

This command will create a firewall rule that allows incoming traffic on UDP port 53. The -p option specifies the protocol (UDP), and the rest of the options are the same as in the previous example.

Keep in mind that these firewall rules will only be applied temporarily. If you want to make the changes permanent, you will need to save the firewall rules using the iptables-save command. For example:

iptables-save > /etc/iptables/rules.v4

This will save the current firewall rules to the /etc/iptables/rules.v4 file, which will be applied automatically when the system is restarted.

It is also important to note that the iptables command is just one way to manage firewall rules on a Unix or Linux system. There are also other tools available, such as firewalld and ufw, that can be used to manage firewall rules.

Created Time:2017-10-29 22:08:45  Author:lautturi