Advertisement
teknoraver

nsgw

Mar 28th, 2018
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.50 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. #                          NETWORK LAYOUT
  4. #
  5. #               +-------------------------------------+
  6. #               |                 GW                  |
  7. #               |  +-------------+   +-------------+  |
  8. #               |  |   veth-c1   |   |   veth-c2   |  |
  9. #               |  | 192.168.1.1 |   | 192.168.2.1 |  |
  10. #               |  +-------------+   +-------------+  |
  11. #               +-----------|-------------|-----------+
  12. #                           |             |
  13. #   +-------------------+   |             |   +-------------------+
  14. #   |      client1      |   |             |   |      client2      |
  15. #   |  +-------------+  |   |             |   |  +-------------+  |
  16. #   |  |    veth0    |__|___/             \___|__|    veth0    |  |
  17. #   |  | 192.168.1.2 |  |                     |  | 192.168.2.2 |  |
  18. #   |  +-------------+  |                     |  +-------------+  |
  19. #   +-------------------+                     +-------------------+
  20. #
  21. #
  22. #     do an inter-ns ping with:
  23. #     # tcpdump -i veth-c1 icmp &
  24. #     # ip netns exec client1 ping -q 192.168.2.2
  25. #
  26. #     start a shell in a netns with:
  27. #     # ip netns exec client1 bash
  28. #
  29.  
  30. setupns() {
  31.     ip netns add client$1
  32.     ip -b - <<-EOF
  33.         link add name veth-c$1 type veth peer netns client$1
  34.         addr add 192.168.$1.1/24 dev veth-c$1
  35.         link set veth-c$1 up
  36.     EOF
  37.     ip -n client$1 -b - <<-EOF
  38.         addr add 192.168.$1.2/24 dev veth0
  39.         link set veth0 up
  40.         route add default via 192.168.$1.1
  41.     EOF
  42. }
  43.  
  44. setupns 1
  45. setupns 2
  46.  
  47. sysctl -qw net.ipv4.ip_forward=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement