Commit 343b00df authored by zhifan huang's avatar zhifan huang

v1

parent 78a1dac7
import subprocess
import time
app1 = subprocess.Popen("unshare -n", shell=True, stdin=subprocess.PIPE)
app2 = subprocess.Popen("unshare -n", shell=True, stdin=subprocess.PIPE)
print("pid, 1:{}, 2:{}".format(app1.pid, app2.pid))
subprocess.check_call(['ip', 'link', 'add', 'veth0', 'netns', str(app1.pid+2) ,'type', 'veth', 'peer', 'veth1'])
subprocess.check_call(['nsenter', '-t', str(app1.pid+2), '-n'] + ['ip', 'link', 'set', 'up', 'veth0'])
subprocess.check_call(['ip', 'link', 'set', 'up', 'veth1'])
subprocess.check_call(['nsenter', '-t', str(app1.pid+2), '-n'] + ['ip', 'addr', 'add', 'dev', 'veth0', '10.1.1.1/24'])
subprocess.check_call(['ip', 'addr', 'add', 'dev', 'veth1', '10.1.1.2/24'])
subprocess.check_call("ip addr", shell=True)
# subprocess.check_call(['nsenter', '-t', str(app1.pid), '-n','ip', 'route', 'add', '10.1.1.0/24', 'via', '10.1.1.1'])
# subprocess.check_call(['ip', 'route', 'add', '10.1.1.0/24', 'via', '10.1.1.2'])
subprocess.check_call("ping 10.1.1.1", shell=True)
print("good bye!")
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment