LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 07-27-2016, 01:31 AM   #1
atux_null
Member
 
Registered: Mar 2015
Distribution: debian 12, ubuntu 22.04
Posts: 65

Rep: Reputation: Disabled
iptables to allow only ssh and vpn from outside world


hello everyone.i do have my a VPS (debian 7) with a public IP address and I would like to protect it. I would like to have access only to SSH (public/private keys), openVPN, services that are requested from the VPS itself, such as sending emails, DNS, access to Internet. All users that connect to the system through OpenVPN then have full access to it and to the Internet.
My current setup is:
Code:
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -F
iptables -X
iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 1194 -j ACCEPT
iptables -P INPUT DROP
iptables -A OUTPUT -p tcp -m tcp --sport 22 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --sport 1194 -j ACCEPT
iptables -P OUTPUT DROP
I would like to blacklist all IPs that attack me or try to scan me. Whoever has 3 failed ssh attempts then get blacklisted for 24 hours. Is it possible to help me please?
 
Old 07-27-2016, 05:27 PM   #2
andre@home
Member
 
Registered: Oct 2003
Distribution: 2x Debian 8.1 webdav servers
Posts: 93

Rep: Reputation: 44
For blocking people that attempt it 3x je could use failban
http://www.fail2ban.org/wiki/index.php/Main_Page

Ipset is another option.
https://www.google.nl/search?client=...UTF-8&oe=UTF-8


Ipset seems better than just iptables with a (big) list... that could increase your CPU loading stronlgy.
https://mattwilcox.net/web-developme...t-and-iptables

How to set up a firewall you like: look around there are so many examples with a configuration very likely you would like...

Like this one... which I use and quite easy to change...
https://goodworkaround.com/2011/7/26...your-iptables/

Last edited by andre@home; 07-27-2016 at 05:32 PM.
 
Old 07-30-2016, 11:40 AM   #3
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
I would suggest the following:

Code:
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -F
iptables -X
iptables -A INPUT -conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 22 -conntrack --ctstate NEW -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 1194 -conntrack --ctstate NEW -j ACCEPT
iptables -P INPUT DROP
iptables -A OUTPUT -conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -P OUTPUT DROP
Please keep in mind that only those two ports will be allowed and nothing more.

I agree that you might want to log this down even further to stop the brute force attacks. Look hard at Fail2ban and IPSET they are both very good programs.
 
Old 07-30-2016, 08:27 PM   #4
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Your script is accepting everything at first. Much better is to first DROP everything (drop policy), and then accept 22,1194 with conntrack ctstate.
 
Old 07-31-2016, 10:54 AM   #5
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Quote:
Originally Posted by AwesomeMachine View Post
Your script is accepting everything at first. Much better is to first DROP everything (drop policy), and then accept 22,1194 with conntrack ctstate.
Yes and No. While the policy allows everything the last rule in the chain is set to DROP. So the only time the policy comes into play is when packet has reached the end of the chain without an action being taken on it. Since the last rule is DROP the policy never comes into play.

I will agree it is best practice, it doesn't mean it has to be done this way.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux/fedora ssh permissions through vpn ssh session pjmonk Linux - Desktop 0 01-14-2016 03:44 PM
VPN iptables Sefyir Linux - Networking 8 03-29-2015 06:54 PM
iptables and VPN dellcom1800 Linux - Networking 3 06-05-2008 07:59 AM
LXer: Safenet Announces World’s First Full Mobility IPSec VPN Toolkit LXer Syndicated Linux News 0 12-25-2006 08:03 PM
vpn behind iptables kris2002 Linux - Networking 3 06-26-2005 10:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 04:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration