# Mininet 6 router_-on-a-stick Router on a stick 透過 單個 Trunk link 實現 2 個以上 Interface Connection 會用到 Vlan 的Concept  ``` apt install vlan ``` ## Configure Virtual Interface 實體介面 + Lable ID 這裡的10跟20 -> 是指 lable 標籤 判斷要送給哪個virtual interface ``` br1.cmd("vconfig add br1-eth4 10") br1.cmd("vconfig add br1-eth4 20") r1.cmd("vconfig add r1-eth0 10") r1.cmd("vconfig add r1-eth0 20") ``` ## Python Script ``` #! /usr/bin/env python from mininet.cli import CLI from mininet.net import Mininet from mininet.link import Link,TCLink,Intf if '__main__' == __name__: net = Mininet(link=TCLink) h1 = net.addHost('h1') h2 = net.addHost('h2') h3 = net.addHost('h3') h4 = net.addHost('h4') br1 = net.addHost('br1') r1 = net.addHost('r1') net.addLink(h1, br1) net.addLink(h2, br1) net.addLink(h3, br1) net.addLink(h4, br1) net.addLink(br1,r1) net.build() h1.cmd("ifconfig h1-eth0 0") h2.cmd("ifconfig h2-eth0 0") h3.cmd("ifconfig h3-eth0 0") h4.cmd("ifconfig h4-eth0 0") r1.cmd("ifconfig r1-eth0 0") br1.cmd("ifconfig br1-eth0 0") br1.cmd("ifconfig br1-eth1 0") br1.cmd("ifconfig br1-eth2 0") br1.cmd("ifconfig br1-eth3 0") br1.cmd("ifconfig br1-eth4 0") br1.cmd("vconfig add br1-eth4 10") br1.cmd("vconfig add br1-eth4 20") r1.cmd("vconfig add r1-eth0 10") r1.cmd("vconfig add r1-eth0 20") br1.cmd("brctl addbr mybr10") br1.cmd("brctl addbr mybr20") br1.cmd("brctl addif mybr10 br1-eth0") br1.cmd("brctl addif mybr10 br1-eth1") br1.cmd("brctl addif mybr10 br1-eth4.10") br1.cmd("brctl addif mybr20 br1-eth2") br1.cmd("brctl addif mybr20 br1-eth3") br1.cmd("brctl addif mybr20 br1-eth4.20") br1.cmd("ifconfig br1-eth4.10 up") br1.cmd("ifconfig br1-eth4.20 up") r1.cmd("ifconfig r1-eth0.10 up") r1.cmd("ifconfig r1-eth0.20 up") br1.cmd("ifconfig mybr10 up") br1.cmd("ifconfig mybr20 up") r1.cmd('ifconfig r1-eth0.10 192.168.10.254 netmask 255.255.255.0') r1.cmd('ifconfig r1-eth0.20 192.168.20.254 netmask 255.255.255.0') r1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward") h1.cmd("ip address add 192.168.10.1/24 dev h1-eth0") h1.cmd("ip route add default via 192.168.10.254") h2.cmd("ip address add 192.168.10.2/24 dev h2-eth0") h2.cmd("ip route add default via 192.168.10.254") h3.cmd("ip address add 192.168.20.1/24 dev h3-eth0") h3.cmd("ip route add default via 192.168.20.254") h4.cmd("ip address add 192.168.20.2/24 dev h4-eth0") h4.cmd("ip route add default via 192.168.20.254") CLI(net) net.stop() ``` R1 Interface setting  --- br1 Interface setting  ---  ``` br1.cmd("brctl addif mybr10 br1-eth0") br1.cmd("brctl addif mybr10 br1-eth1") br1.cmd("brctl addif mybr10 br1-eth4.10") br1.cmd("brctl addif mybr20 br1-eth2") br1.cmd("brctl addif mybr20 br1-eth3") br1.cmd("brctl addif mybr20 br1-eth4.20") ``` 802.1Q VLAN ICMP Request   --- ICMP Reply  
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up