To open a port in iptables:-

IPTABLES:-
===================
To open a port in iptables:-

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

iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

We can go ahead and break this down:
-A tells the IP table to append a rule to the table.

INPUT designates this rule as part of the Input chain.

-m conntrack followed by the --cstate ESTABLISHED,RELATED guarantees that the result of this rule will only apply to current connections and those related to them are allowed

-j ACCEPT tells the packet to JUMP to accept and the connections are still in place.

Let’s assume that we want to block all incoming traffic, except for those coming in on 2 common ports: 22 for SSH and 80 for web traffic. We proceed by allowing all traffic on the designated ports with the following commands:

 iptables -A INPUT -p tcp --dport ssh -j ACCEPT
 iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --destination-port 6881:6999 -j ACCEPT 

In both of these commands, the -p option stands for the protocol with which the connection is being made, in this case tcp, while the --dport specifies the port through which the packet is being transmitted.



Comments

Popular Posts

Install and configure rsyslog Centralized logging server in CentOS

How to fix postfix/smtp Network is unreachable error

Could not join realm: Necessary packages are not installed: sssd-tools sssd libnss-sss libpam-sss adcli