Score:0

How to isolate machine using iptables and cgroups in ubuntu

ao flag

I am trying to isolate a computer from the network. I am running the following commands in 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

Now performing these steps works in my local VM. Local VM settings as follows:

  • OS: Linux mint 21.1

The same doesn't work in another server running Ubuntu 20.04. It just blocks all traffic including firefox which was added as exception.

I am a novice with managing linux systems. So any pointers or even alternative approaches are welcome.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.