Last active
December 5, 2020 15:09
-
-
Save KaiserKatze/513fc16c6a6ba6812028d0f3a0e2a7bb to your computer and use it in GitHub Desktop.
Build a virtual LAN with ip-netns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
# @see: https://superuser.com/questions/1348508/can-i-create-three-veth-interfaces-to-build-a-virtual-lan-in-linux | |
# @see: https://unix.stackexchange.com/questions/255484/how-can-i-bridge-two-interfaces-with-ip-iproute2 | |
ip -all netns del | |
ip netns add router | |
ip netns add net1 | |
ip netns add net2 | |
ip netns exec router ip l add name veth1r mtu 1500 type veth peer name veth1h | |
ip netns exec router ip l add name veth2r mtu 1500 type veth peer name veth2h | |
ip netns exec router ip l add name br0 mtu 1500 type bridge | |
ip netns exec router ip l set br0 up arp on multicast off | |
ip netns exec router ip l set veth1r master br0 | |
ip netns exec router ip l set veth2r master br0 | |
ip netns exec router ip l set veth1h netns net1 | |
ip netns exec router ip l set veth2h netns net2 | |
ip netns exec router ip a add 192.168.1.1/24 brd 192.168.1.255 dev br0 | |
ip netns exec net1 ip a add 192.168.1.101/24 brd 192.168.1.255 scope global dev veth1h valid_lft forever preferred_lft forever | |
ip netns exec net2 ip a add 192.168.1.102/24 brd 192.168.1.255 scope global dev veth2h valid_lft forever preferred_lft forever | |
ip netns exec router ip l set veth1r up arp on multicast off | |
ip netns exec router ip l set veth2r up arp on multicast off | |
ip netns exec net1 ip l set veth1h up arp on multicast off | |
ip netns exec net2 ip l set veth2h up arp on multicast off |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment