我想更改网络,但仅适用于新启动的流程。
我的想法是为新创建的进程修改/proc
文件系统。如何在linux中做到这一点?
ruby中的示例代码
script.rb
conn = Tcp.dial('123.123.123.4', 3306)
和我的包装过程开始:
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