http://man7.org/linux/man-pages/man7/namespaces.7.html
sudo python3 test.py
pip3 install git+https://github.com/bt-sync/pynetsandbox
For first enable ip_forward
ing in the kernel.
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
Then:
main.py
from netsandbox import NetworkSandbox
with NetworkSandbox('10.1.0.0/16') as ns:
p = ns.spawn('ping 10.1.0.1 -c 3')
p.wait(timeout=10)
try:
ns = NetworkSandbox('10.2.0.0/16')
p = ns.spawn('ping 10.2.0.1 -c 3')
p.wait(timeout=10)
finally:
ns.release()
sudo python3 main.py
pylint --rcfile .pylintrc *.py netsandbox