iptables and ssh

Hugo Rodrigues

I'm running Arch Linux and I have a running SSH daemon to access my machine when I'm out side my LAN. I can do the connection, but iptables keeps blocking SSH Daemon, so I can only connect if I turn off the firewall. I'm running SSH on port 5000.

My iptables rules

*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -p icmp -j ACCEPT 
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 
-A INPUT -i lo -j ACCEPT 
-A INPUT -p tcp -j REJECT --reject-with tcp-reset 
-A INPUT -p udp -j REJECT --reject-with icmp-port-unreachable 
-A INPUT -j REJECT --reject-with icmp-proto-unreachable 

# SSH
-A INPUT -p tcp --dport 22 -j REJECT --reject-with icmp-host-unreachable
-A INPUT -p tcp --dport 5000 -j ACCEPT

# VNC
-A INPUT -p tcp --dport 5001 -j REJECT --reject-with icmp-host-unreachable
-A INPUT -p tcp -i lo -s 127.0.0.1/32 -d 127.0.0.1/32 --dport 5001 -j ACCEPT

# HTTP/HTTPS
-A INPUT -p tcp --dport 80 -j REJECT --reject-with icmp-host-unreachable
-A INPUT -p tcp --dport 8080 -j REJECT --reject-with icmp-host-unreachable
-A INPUT -p tcp --dport 443 -j REJECT --reject-with icmp-host-unreachable

-A INPUT -p tcp -i lo -s 127.0.0.1/32 -d 127.0.0.1/32 --dport 80 -j ACCEPT
Thomas Weinbrenner

You have to reorder the iptables rules.

You can't connect to your sshd because the rules are checked in line for line. And you already told iptables -A INPUT -p tcp -j REJECT --reject-with tcp-reset = reject ALL tcp traffic. Even you later tell him to accept connections to port 5000 it doesn't matter - you already rejected those connections.

So when you write iptables rules, think about the order: first insert those things you want to allow, then reject the rest.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

ssh tunnel/forwarding & iptables

iptables not blocking ssh bruteforce?

Use iptables to block ssh

IPTables ssh port redirect

Config iptables ssh over VPN

Is Iptables blocking outgoing ssh connections?

Linux iptables ssh port forwarding (martian rejection)

IPTables rule to allow incoming SSH connections

How to create SSH reverse tunnel with iptables forwarding?

Best practises: Applying iptables firewall rules for SSH

iptables: All SSH connections for range of DPT

IPTABLES forward all ports except ssh

iptables unable to block local ssh connection

How to allow only ssh and internet access with iptables?

Configuring iptables to port forward ssh connection to a server

iptables: How to allow SSH through debian router?

iptables Couldn't load target `SSH'

Why is iptables -F kicking me out of my ssh session?

In the iptables i have a rule for ssh, why doesn't it work?

iptables is preventing ssh to aws ec2 instance

How can I allow SSH and SMTP only using IPTables?

IPtables : Limit number of new ssh connections per minute

IPtables : Limit number of new ssh connections per minute

iptables rule that allows to connect to ssh from the outside with mac validation

Trying to use iptables to block all traffic except for SSH and RDP

How to Block SSH Brute Force via Iptables and How does it work?

SSH password login: iptables Log/Drops listsDST=18.9.2.13/18.7.33.13

How to redirect all traffic except SSH to one local port with iptables

No SSH access after accidentally denied ssh in ufw/iptables on Snappy Ubuntu Core

TOP Ranking

HotTag

Archive