Simply run app as:
systemd-run --scope -p IPAddressDeny=any wine myapp.exe
The IPAddressDeny=…
allows to deny access to a set of IPv4 and IPv6 addresses. Special value any
disables access to all of them for all IP-based protocols, like TCP, UDP, ICMP, SCTP, etc.
Example of usage (note: for this demo I had to fix wine ping
, since it was timing out on me):
$ export WINEDEBUG=-all # remove debug prints for the demo
$ wine ping localhost # check that ping works
Pinging localhost [127.0.0.1] with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64
Reply from 127.0.0.1: bytes=32 time<1ms TTL=64
Reply from 127.0.0.1: bytes=32 time=1ms TTL=64
Ping statistics for 127.0.0.1
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms
$ systemd-run --scope -p IPAddressDeny=any wine ping localhost # well, not anymore
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ====
Authentication is required to manage system services or other units.
Multiple identities can be used for authentication:
1. constantine
2. archie
Choose identity to authenticate as (1-2): 1
Password:
==== AUTHENTICATION COMPLETE ====
Running scope as unit: run-u28936.scope
Pinging localhost [127.0.0.1] with 32 bytes of data:
PING: transmit failed. General failure.
PING: transmit failed. General failure.
PING: transmit failed. General failure.
PING: transmit failed. General failure.
Ping statistics for 127.0.0.1
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss)
For the rest of the answer I gonna copy text from my other similar answer on unix.se:
Note: this gonna ask you for a password but the app gets launched as your user. Do not allow this to delude you into thinking that the command needs sudo
, because that would cause the command to run under root, which hardly was your intention.
If you want to not enter the password (after all, you already own your resources, why would you need a password to limit them), you could use --user
option, however for this to work you gonna need cgroupsv2 support enabled, which right now requires to boot with systemd.unified_cgroup_hierarchy
kernel parameter.
http://askubuntu.com/questions/249826/how-to-disable-internet-connection-for-a-single-process/393013#393013
– escor Dec 19 '13 at 13:35