How do I configure the following iptables rules?
How can I apply this on my linode?
#Chain INPUT (policy ACCEPT)
#target prot opt source destination
#ACCEPT all -- anywhere anywhere
#ACCEPT tcp -- anywhere anywhere tcp dpt:6900 state NEW
#ACCEPT tcp -- anywhere anywhere tcp dpt:5121 state NEW
#ACCEPT tcp -- anywhere anywhere tcp dpt:6121 state NEW
#Chain FORWARD (policy ACCEPT)
#target prot opt source destination
#Chain OUTPUT (policy ACCEPT)
#target prot opt source destination
#ACCEPT all -- anywhere anywhere
Please note that i just need to know the exact command for my test purposes.
1 Reply
If you are looking for exactly those iptables rules, and nothing else, I'd recommend first flushing all your rules, and setting INPUT and OUTPUT to accept everything, as requested:
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
Next, you'll want to configure the rules for the specific ports 6900, 5121, and 6121:
iptables -I INPUT -p tcp --dport 6900 -j ACCEPT
iptables -I INPUT -p tcp --dport 5121 -j ACCEPT
iptables -I INPUT -p tcp --dport 6121 -j ACCEPT
Once you've created the rules, you'll need to Deploy the iptables rules.
As a side note, it seems odd to me that you are setting a default policy of accepting all connections, and than specifying specific ports to accept traffic through. You may want to consider changing your default policy.
As another aside, if you are using CentOS, then FirewallD is enabled by default. You'll want to either configure this using FirewallD or have it disabled. Our guide will walk you through this.