Limit linux server SSH connections from outside

Dear experts,

I found out that our mail server can be access from outside via ssh.

It does not know what is from outside and inside basically. A huge problem for me.

I need an idea on how to stop its outside access and keep only from LAN.

I take I need to begin IPTable work.. Anything else?

The Server is in a DMZ.

Thank you!
marceloNYCMiddle-Tier AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

   Good article is available here:

This shows you the IP tables and also has information on setting up access with Keys rather than having password protected accounts
Jan SpringerCommented:
Specifically, which distribution and which version?

You should also be running fail2ban with ssh connections.
marceloNYCMiddle-Tier AdministratorAuthor Commented:
more /etc/*-release
PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
NAME="Debian GNU/Linux"
VERSION="7 (wheezy)"
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

some basic things to consider,

First read about DMZ,

Limit from your firewall if you have one. (find your mail server IP and block it there to outside.)
Disable password login (also root login) on your ssh server and enable public key auth,
(create strong public/private key pair with password.)
Jan SpringerCommented:
Let's get a list of rules first so that we can insert:

iptables --list -n --line-numbers

Please make a list of all tcp and udp ports that need to be accessed and by what address.  If you only want examples instead of a complete set of rules, we can do that also.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
marceloNYCMiddle-Tier AdministratorAuthor Commented:
Some samples will be great.

Thank you!
Jan SpringerCommented:
That's no problem.

I need to know your input chain (you'll get that from an "iptables --list -n").

In CentOS land, it would look like this:

iptables -I INPUT 5 -s -p tcp -m tcp --dport 22 -j ACCEPT

This will insert this into line 5 of your iptables rules allowing the subnet ssh to the server on any interface.

Either only allow ssh by IP/subnet or install fail2ban.  I do both and both work well.

The important data point with these rules is that either iptables isn't running or you have the usual allow all to ssh.  So just inserting this rule without considering further rules could be problematic.
marceloNYCMiddle-Tier AdministratorAuthor Commented:
I like CentOS more but here they are all Debian and want nothing else... :(
Jan SpringerCommented:
I guess what I'm saying is that the default input chain is called "INPUT".

If you do an "iptables --list -n", we can get the accurate chain name.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Security

From novice to tech pro — start learning today.