In Ubuntu 17.04, I've been trying to use IP tables to block a processes' internet connection but allow localhost, particularly 127.0.0.1:5500 (a server the process creates).
Whilst the process can't access the internet, it also times out accessing 127.0.0.1:5500. Trying to ping 127.0.0.1 results in "ping: sendmsg: Operation not permitted"
.
I followed this below: https://ubuntuforums.org/showthread.php?t=1188099.
My IP tables file is:
#!/bin/bash
iptables -A OUTPUT -m owner --gid-owner no-internet -d 192.168.1.0/24 -j ACCEPT
iptables -A OUTPUT -m owner --gid-owner no-internet -d 127.0.0.0/8 -j ACCEPT
iptables -A OUTPUT -m owner --gid-owner no-internet -j DROP
Which I run with sudo -g no-internet <command>
, i.e. sudo -g no-internet firefox
.
Is there anything I'm doing wrong, or is this just not possible? Is there a better way of doing this?
iptables -n -L OUTPUT
would show the default policy. – Jeff Schaller May 28 '18 at 15:44iptables -n -L OUTPUT
both in the group and outside of the group returns the following: https://pastebin.com/raw/HTuS7VuQ. Appears that it's accepting localhost. @JeffSchaller – Trashay May 28 '18 at 15:57