ufwでIPアドレスをブロックする方法

この記事では、UFWを使用して特定のIPアドレスをブロックする方法について説明しています。

UFW(Uncomplicated Firewall)は、Ubuntu Linux用の標準的なiptablesファイアウォールユーティリティです。 少数の単純なコマンドで構成されるコマンドラインインターフェイスを使用します。 UFWは、基本的なIPv4またはIPv6ファイアウォールを作成してサーバーを保護する便利な方法です。



ufwを介して特定のIPアドレスをブロックする


構文:

sudo ufw deny from {ip-address-here} to any 

192.168.1.5のすべてのパケットをブロックまたは閉じるには、次を入力します。

 sudo ufw deny from 192.168.1.5 to any 

ルールを含むファイアウォールのステータスを表示します。 最近追加されたルールを確認するには、次を入力します。

 $ sudo ufw status numbered 

または

 $ sudo ufw status 



ufwを介して特定のIPおよびポート番号をブロックする


構文:

 ufw deny from {ip-address-here} to any port {port-number-here} 

ポート80の「スパム」IPアドレス202.54.1.5をブロックまたは閉じるには、次のように入力します。

 sudo ufw deny from 202.54.1.5 to any port 80 

次のコマンドを使用して再度確認します。

 $ sudo ufw status numbered 

結果:



ufwを使用して特定のIP、ポート、およびプロトコル番号を閉じる



構文:

 sudo ufw deny proto {tcp|udp} from {ip-address-here} to any port {port-number-here} 

たとえば、悪意のあるIPアドレス202.54.1.1 tcpポート22をブロックするには、次のように入力します。

 $ sudo ufw deny proto tcp from 202.54.1.1 to any port 22 $ sudo ufw status numbered 

ufwを介したサブネットロック。 構文は同じです:

 $ sudo ufw deny proto tcp from sub/net to any port 22 $ sudo ufw deny proto tcp from 202.54.1.0/24 to any port 22 

ブロックを解除してIPアドレスのロックを解除する方法



構文:

 $ sudo ufw status numbered $ sudo ufw delete NUM 

ルール#4を削除するには、次を入力します。

 $ sudo ufw delete 4 

結果:

  deny from 202.54.1.5 to any port 80 Proceed with operation (y|n)? y Rule deleted 

ヒント: UFWはIPアドレスをブロックしていません

不要なブロッキングに関する不要な問題を回避するには、/ etc / ufw / before.rulesファイルを変更し、「#End required lines」の後に「Block an IP Address」セクションを追加する必要があります。

 $ sudo vi /etc/ufw/before.rules 

 # End required lines 

スパムまたはハッカーをブロックするためのルールを追加します。



ファイルを保存して閉じます。 そして-ファイアウォールをリロードします:

 $ sudo ufw reload 

Source: https://habr.com/ru/post/J230201/


All Articles