0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MinecraftServerで特定のIPアドレスを遮断する方法

Last updated at Posted at 2025-02-12

最近、ふとマイクラ鯖のコンソールを見ると見慣れない、IPからの接続があると気づいた。

さいわい、ホワイトリストを導入していたので、ワールドに入ることはできない様子。

そもそも、Mod鯖なのにバニラ接続を何度も試みている様子。 (参加する意思は無さそう...)

その後も海外から何度もマイクラ鯖にログインしようと何度もアクセスしてきていて、それが嫌になったので対策をすることにした...

環境

  • ProxmoxVE 8.2.4 下のVM
  • Debian 12.6.0-amd64-netinst.iso

作業内容

1. IPアドレスの特定

ログを見たところ海外からアクセスしてくるIPは2つあった
image.png

1個目: 45.135.xxx.xxx
2個目:199.58.xxx.xxx

2. 特定IPアドレスの拒否

以下のufwコマンドでIPアドレスの拒否を試みた

root@debian:~# ufw deny from 45.135.xxx.xxx to any
root@debian:~# ufw deny from 199.58.xxx.xxx to any

しかし、これだとうまくいいかないことに気づいた

というのも、ufwのルールには優先順位があり、これらルールの順位が一番上に来ていないようだ

以下のufw status numberedで優先順位を確認してみる

root@debian:~# ufw status numbered

Status: active

     To                         Action      From
     --                         ------      ----
[ 1] 22/tcp                     ALLOW IN    192.168.1.0/24
[ 2] 25565/tcp                  ALLOW IN    Anywhere
[ 3] Anywhere                   DENY IN     45.135.xxx.xxx
[ 4] Anywhere                   DENY IN     199.58.xxx.xxx
[ 5] 25565/tcp (v6)             ALLOW IN    Anywhere (v6)

こんな感じで真ん中に来ていた...

これでは意味がないのでufw deleteとかでルールを消しておく

insertを用いて優先順位を一番上に指定して再度ルールを追加します

root@debian:~# ufw insert 1 deny from 45.135.xxx.xxx to any
root@debian:~# ufw insert 1 deny from 199.58.xxx.xxx to any

再度ufw status numberedで優先順位を確認してみる

root@debian:~# ufw status numbered

Status: active

     To                         Action      From
     --                         ------      ----
[ 1] Anywhere                   DENY IN     45.135.194.65
[ 2] Anywhere                   DENY IN     199.58.83.10
[ 3] 22/tcp                     ALLOW IN    192.168.1.0/24
[ 4] 25565/tcp                  ALLOW IN    Anywhere
[ 5] 25565/tcp (v6)             ALLOW IN    Anywhere (v6)

優先順位上部に特定IPを拒否するルールが追加されていることが分かります

最後にufw reloadを行って設定を再読み込みさせる

root@debian:~# ufw reload
Firewall reloaded

実験

試しにスマホのIPを拒否した状態でテザリングを介してマイクラ鯖に接続してみたところ...

Screenshot_2025-02-13_032153.png

無事に拒否されました!!!(?)

おわりに

これで前よりかは安心してマイクラマルチが楽しめます。

おまけ

このようなIPアドレスの制限はサーバー側ではなくルータやスイッチなどで行うべきだと思っているので、いつかやってみたいです...

引用

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?