0

By alternative it's not meant the program needs to be gui. Any method that allows a program to logs when something calls listen() and only allows selected programs to listen to the interface:port will works. I've seen opensnitch but it woeks with outbound connections only.

If such program doesn't exist can anyone point to how to create? Like using nftable rules. What I'm not looking for is to run a program in separate net namespace etc. The solution should work for all userland programs in general.

  • No. 1. "What I'm not looking for is to run a program in separate net namespace etc.". 2. I'm interested in allowing a progeam to listen on some interface. Not interested in outbound traffic. – flappybirdy Sep 05 '21 at 12:43
  • well, but what you describe reads a lot like a network namespace! in Linux, networking isn't "bound" to a process per se; the method of having network behave differently for different userland software is network namespaces, as far as I can tell. The problem with all Linux nftables/netfilter-based approaches is that packets don't have a property "comes from process XYZ" or "goes to process XYZ" internally. – Marcus Müller Sep 05 '21 at 14:14
  • All I asked is program x binds and calls listen to port y. The os (or something else) check a whitelist and allows it. If the program no longer listens to the port, the port is closed. If an unauthorized program tries to listen that port it fails silently ie that programs see no packets coming. This is what application firewall does. Without resorting to mach ports. – flappybirdy Sep 05 '21 at 14:29
  • sounds a bit like network namespaces, honestly! Linux is not mach; you can try to implement something similar with eBPF in the Linux kernel, but it would be less clean than starting things in a Linux network namespace – which again, possibly differently than the OS X equivalent, matches the description of "I want to control which software does something with my network" pretty well. – Marcus Müller Sep 05 '21 at 14:29
  • https://en.m.wikipedia.org/wiki/Application_firewall this. – flappybirdy Sep 05 '21 at 14:39
  • 1
    I know what an application firewall is. Linux doesn't think in applications. – Marcus Müller Sep 05 '21 at 14:40
  • you want to know when a program bind()s a socket, not when it listen()s on it. Believe me. 2. you can probably do it with seccomp, which is already used extensively on Android for all apps (together with other jailing facilities, like dropping caps, selinux and network namespaces).
  • –  Sep 05 '21 at 16:05