P
P
Printip2021-03-24 12:44:52
linux
Printip, 2021-03-24 12:44:52

Iptables how to block all ports for all ips except one?

Hello!
There is Ubuntu 18, you need to block all ports, all connections, from all ips except one.
Please tell me how to do it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ky0, 2021-03-24
@ky0

  1. Google how to set the default behavior in the INPUT chain.
  2. Google how to allow connections from a specific address.

R
Ragnar Black, 2021-04-01
@Ragnar1

The answer will be little more than just a set of two commands:
* allow all established (established) and related (related) connections
* allow connection via ssh (you don't want to lose connection with the server)
* allow connection from the source address you need
* install default policy DROP
is now in the form of commands:

iptables --append INPUT --match state --state ESTABLISHED,RELATED --jump ACCEPT
iptables --append INPUT --protocol tcp --dport 22 --jump ACCEPT
iptables --append INPUT --source WWW.ZZZ.YYY.XXX --jump ACCEPT 
iptables --policy INPUT DROP

(replace WWW.ZZZ.YYY.XXX with the address from which you want to allow connections)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question