1

I would like to change network, but only for newly started process.

My idea is to modify somehow /proc filesystem for newly created process. How to do it in linux?

Example code in ruby

script.rb

conn = Tcp.dial('123.123.123.4', 3306)

and my wrapper around process starting:

p = Process.new('script.rb')

# I would like to  somehow cheat a proc system
# so process during connection to 123.(...) connects really to localhost
# a bit like
# sudo iptables -t nat -A OUTPUT -p all -d 123.123.123.4 -j DNAT --to-destination 127.0.0.1
# but for process
p.network(from: '123.123.123.4', to: :localhost)

p.start
Sławosz
  • 11,187
  • 15
  • 73
  • 106
  • 1
    You can run process inside separate *network namespace*: http://blog.hintcafe.com/post/78293519027/running-a-process-inside-a-network-namespace You can create new namespace programmatically using `unshare()` and `clone()`. Related: http://stackoverflow.com/questions/10730838/how-to-create-multiple-network-namespace-from-a-single-process-instance – gavv Sep 24 '15 at 16:57
  • 1
    As for modifying `/proc` for a single process, I suppose namespaces are the only mechanism that allows to to this. Note that, however, network namespace is something more than just substituting contents of several files in `/proc`; it's more like giving a separate network stack for a process. – gavv Sep 24 '15 at 17:01

0 Answers0