snipt

Ctrl+h for KB shortcuts

Bash

Block all SSH Access except one IP

1
2
3
4
5
#create access for specific IP:
iptables -A INPUT -m state --state NEW,ESTABLISHED,RELATED --source x.x.x.x -p tcp --dport 22 -j ACCEPT

#block all others
iptables -A INPUT -m state --state NEW,ESTABLISHED,RELATED -p tcp --dport 22 -j DROP

Description

Block all SSH Access except one IP
https://snipt.net/embed/6d66619c16e7b97c1c7506a381a6bce0/
/raw/6d66619c16e7b97c1c7506a381a6bce0/
6d66619c16e7b97c1c7506a381a6bce0
bash
Bash
5
2019-06-25T15:31:55
True
False
False
Feb 27, 2013 at 01:35 PM
/api/public/snipt/56620/
block-all-ssh-access-except-one-ip
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">#create access for specific IP:</span> </span><span id="L-2"><a name="L-2"></a>iptables -A INPUT -m state --state NEW,ESTABLISHED,RELATED --source x.x.x.x -p tcp --dport <span class="m">22</span> -j ACCEPT </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c1">#block all others</span> </span><span id="L-5"><a name="L-5"></a>iptables -A INPUT -m state --state NEW,ESTABLISHED,RELATED -p tcp --dport <span class="m">22</span> -j DROP </span></pre></div> </td></tr></table>
iptables