Advertisement
teknoraver

netns

Mar 1st, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. # ip netns add router
  2. # ip netns add client1
  3. # ip netns add client2
  4. # ip link add name veth-router1 netns router type veth peer name veth-client netns client1
  5. # ip link add name veth-router2 netns router type veth peer name veth-client netns client2
  6. # ip -n router address add 192.168.1.1/24 dev veth-router1
  7. # ip -n router address add 192.168.2.1/24 dev veth-router2
  8. # ip -n client1 address add 192.168.1.2/24 dev veth-client
  9. # ip -n client2 address add 192.168.2.2/24 dev veth-client
  10. # ip -n router link set veth-router1 up
  11. # ip -n router link set veth-router2 up
  12. # ip -n client1 link set veth-client up
  13. # ip -n client2 link set veth-client up
  14. # ip -n router address
  15. 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000
  16. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  17. 2: veth-router1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
  18. link/ether 62:aa:de:e6:cb:ed brd ff:ff:ff:ff:ff:ff link-netnsid 0
  19. inet 192.168.1.1/24 scope global veth-router1
  20. valid_lft forever preferred_lft forever
  21. inet6 fe80::60aa:deff:fee6:cbed/64 scope link
  22. valid_lft forever preferred_lft forever
  23. 3: veth-router2@if2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
  24. link/ether 0a:6c:37:15:31:7f brd ff:ff:ff:ff:ff:ff link-netnsid 1
  25. inet 192.168.2.1/24 scope global veth-router2
  26. valid_lft forever preferred_lft forever
  27. inet6 fe80::86c:37ff:fe15:317f/64 scope link
  28. valid_lft forever preferred_lft forever
  29. # ip -n client1 address
  30. 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000
  31. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  32. 2: veth-client: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
  33. link/ether 32:ce:07:18:9c:40 brd ff:ff:ff:ff:ff:ff link-netnsid 0
  34. inet 192.168.1.2/24 scope global veth-client
  35. valid_lft forever preferred_lft forever
  36. inet6 fe80::30ce:7ff:fe18:9c40/64 scope link
  37. valid_lft forever preferred_lft forever
  38. # ip -n client2 address
  39. 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000
  40. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  41. 2: veth-client@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
  42. link/ether 66:7b:08:c7:c9:62 brd ff:ff:ff:ff:ff:ff link-netnsid 0
  43. inet 192.168.2.2/24 scope global veth-client
  44. valid_lft forever preferred_lft forever
  45. inet6 fe80::647b:8ff:fec7:c962/64 scope link
  46. valid_lft forever preferred_lft forever
  47. # ip -n client1 route add default via 192.168.1.1
  48. # ip -n client2 route add default via 192.168.2.1
  49. # ip netns exec client1 ping 192.168.2.2
  50. PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data.
  51. 64 bytes from 192.168.2.2: icmp_seq=1 ttl=63 time=0.043 ms
  52. 64 bytes from 192.168.2.2: icmp_seq=2 ttl=63 time=0.062 ms
  53. 64 bytes from 192.168.2.2: icmp_seq=3 ttl=63 time=0.064 ms
  54. 64 bytes from 192.168.2.2: icmp_seq=4 ttl=63 time=0.063 ms
  55. ^C
  56. --- 192.168.2.2 ping statistics ---
  57. 4 packets transmitted, 4 received, 0% packet loss, time 3098ms
  58. rtt min/avg/max/mdev = 0.043/0.058/0.064/0.008 ms
  59. # ip netns exec client1 ping 192.168.2.2 -q &
  60. [1] 6273
  61. # PING 192.168.2.2 (192.168.2.2) 56(84) bytes of data.
  62.  
  63. # ip netns exec router bash
  64. # tcpdump -ni any
  65. tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
  66. listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
  67. 01:24:32.851462 IP 192.168.1.2 > 192.168.2.2: ICMP echo request, id 6273, seq 19, length 64
  68. 01:24:32.851485 IP 192.168.1.2 > 192.168.2.2: ICMP echo request, id 6273, seq 19, length 64
  69. 01:24:32.851502 IP 192.168.2.2 > 192.168.1.2: ICMP echo reply, id 6273, seq 19, length 64
  70. 01:24:32.851507 IP 192.168.2.2 > 192.168.1.2: ICMP echo reply, id 6273, seq 19, length 64
  71. 01:24:33.875420 IP 192.168.1.2 > 192.168.2.2: ICMP echo request, id 6273, seq 20, length 64
  72. 01:24:33.875443 IP 192.168.1.2 > 192.168.2.2: ICMP echo request, id 6273, seq 20, length 64
  73. 01:24:33.875460 IP 192.168.2.2 > 192.168.1.2: ICMP echo reply, id 6273, seq 20, length 64
  74. 01:24:33.875465 IP 192.168.2.2 > 192.168.1.2: ICMP echo reply, id 6273, seq 20, length 64
  75. 01:24:34.899485 IP 192.168.1.2 > 192.168.2.2: ICMP echo request, id 6273, seq 21, length 64
  76. 01:24:34.899507 IP 192.168.1.2 > 192.168.2.2: ICMP echo request, id 6273, seq 21, length 64
  77. 01:24:34.899525 IP 192.168.2.2 > 192.168.1.2: ICMP echo reply, id 6273, seq 21, length 64
  78. 01:24:34.899529 IP 192.168.2.2 > 192.168.1.2: ICMP echo reply, id 6273, seq 21, length 64
  79. 01:24:35.923286 IP 192.168.1.2 > 192.168.2.2: ICMP echo request, id 6273, seq 22, length 64
  80. 01:24:35.923312 IP 192.168.1.2 > 192.168.2.2: ICMP echo request, id 6273, seq 22, length 64
  81. 01:24:35.923332 IP 192.168.2.2 > 192.168.1.2: ICMP echo reply, id 6273, seq 22, length 64
  82. 01:24:35.923338 IP 192.168.2.2 > 192.168.1.2: ICMP echo reply, id 6273, seq 22, length 64
  83. ^C
  84. 16 packets captured
  85. 16 packets received by filter
  86. 0 packets dropped by kernel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement