Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # NETWORK LAYOUT
- #
- # +-------------------------------------+
- # | GW |
- # | +-------------+ +-------------+ |
- # | | veth-c1 | | veth-c2 | |
- # | | 192.168.1.1 | | 192.168.2.1 | |
- # | +-------------+ +-------------+ |
- # +-----------|-------------|-----------+
- # | |
- # +-------------------+ | | +-------------------+
- # | client1 | | | | client2 |
- # | +-------------+ | | | | +-------------+ |
- # | | veth0 |__|___/ \___|__| veth0 | |
- # | | 192.168.1.2 | | | | 192.168.2.2 | |
- # | +-------------+ | | +-------------+ |
- # +-------------------+ +-------------------+
- #
- #
- # do an inter-ns ping with:
- # # tcpdump -i veth-c1 icmp &
- # # ip netns exec client1 ping -q 192.168.2.2
- #
- # start a shell in a netns with:
- # # ip netns exec client1 bash
- #
- setupns() {
- ip netns add client$1
- ip -b - <<-EOF
- link add name veth-c$1 type veth peer netns client$1
- addr add 192.168.$1.1/24 dev veth-c$1
- link set veth-c$1 up
- EOF
- ip -n client$1 -b - <<-EOF
- addr add 192.168.$1.2/24 dev veth0
- link set veth0 up
- route add default via 192.168.$1.1
- EOF
- }
- setupns 1
- setupns 2
- sysctl -qw net.ipv4.ip_forward=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement