iptablesとcgroupを使用してUbuntuからシステムを分離する方法

iptablesとcgroupを使用してUbuntuからシステムを分離する方法

コンピュータをネットワークから切断しようとしています。
Linux で次のコマンドを実行します。

#create net_cls folder for cgroup
mkdir /sys/fs/cgroup/net_cls

#mount the newly created folder 
mount -t cgroup -o net_cls none /sys/fs/cgroup/net_cls

#create new cgroup
cgcreate -g net_cls:/block_app

#add firefox process which is currently running to the group
cgclassify -g net_cls:/block_app $(pgrep firefox)`

#change read/write permissions for the file
chmod 777 /sys/fs/cgroup/net_cls/block_app/net_cls.classid

#assign group id 
echo 1 > /sys/fs/cgroup/net_cls/block_app/net_cls.classid

#add iptable entry to permit firefox process which was added to cgroup 
iptables -I OUTPUT -m cgroup --cgroup 1 -j ACCEPT

#drop all packets
iptables -A OUTPUT -j DROP

今、この手順を実行すると、私のローカル仮想マシンで動作します。
ローカル仮想マシンの設定は次のとおりです。

  • オペレーティングシステム:Linux Mint 21.1

Ubuntu 20.04を実行している他のサーバーでは機能しません。
例外として追加されたFirefoxを含むすべてのトラフィックをブロックします。

私はLinuxシステム管理が初めてです。したがって、どんなアドバイスや代替案も歓迎します。

ベストアンサー1

おすすめ記事