How do I configure my firewall to allow SSH traffic for new the Remote Console / Recovery Console?

Posted August 27, 2021 390 views
CentOSSecurityFirewallDigitalOcean Droplets

I installed the new droplet-agent on my CentOS 7 droplet, but attempts to connect using the Droplet Console timed out.

I reasoned it was my firewall (iptables) setup. When I disabled iptables, the Console connected, using IP address ARIN shows that CIDR belongs to Digital Ocean, so that makes sense.

How do I configure iptables to safely allow only legitimate SSH traffic for the Droplet Console?

Thanks in advance for your help!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi @aknash,

Well, I’ll recommend allowing only IP addresses that are needed and only on PORTS that are meant to be used by such IPs.

To allow incoming SSH connections from a specific IP address or subnet, specify the source. For example, if you want to allow the entire subnet, run these commands:

sudo iptables -A INPUT -p tcp -s --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT

The second command, which allows the outgoing traffic of established SSH connections, is only necessary if the OUTPUT policy is not set to ACCEPT.

  • Thanks!

    Yes, that’s my conclusion also: the console traffic is blocked because I have really tight firewall settings for SSH traffic. The DO subnet ( involved is very large, and I’m leery of opening up the system to it. Wouldn’t some of those IPs be assigned to other DO droplets? I don’t know… but if so, that presents a huge security risk.

    Opened a support ticket but haven’t yet rec’d a definitive answer.

    • Hi @aknash,

      Yes, you are correct in your assumptions. BEtter to not allow the whole range of IP Addresses just because of the reasons you mentioned.

      As soon as you receive an answer, can you post it here, I’m eager to see what will happen out of this case?