使用mininet构建一个简单的路由实验

Crq
Crq
管理员
1874
文章
0
粉丝
Linux教程评论90字数 237阅读0分47秒阅读模式

使用mininet构建一个简单的路由实验

网络拓扑结构如下:

使用mininet构建一个简单的路由实验

Mininet的拓扑定义代码:

from mininet.topo import Topo
class Router_Topo(Topo):
    def __init__(self):
        "Create P2P topology."
        # Initialize topology
        Topo.__init__(self)
        # Add hosts and switches
        H1 = self.addHost('h1')
        H2 = self.addHost('h2')
        H3 = self.addHost('h3')
        S1 = self.addSwitch('s1')
        S2 = self.addSwitch('s2')
        # Add links
        self.addLink(H1, S1)
        self.addLink(H2, S1)
        self.addLink(H2, S2)
        self.addLink(H3, S2)
topos = {
        'router': (lambda: Router_Topo())
}

利用上面的脚本生成网络拓扑:

sudo mn --custom /home/mininet/Router.py --topo router
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2 h2-eth1:s2-eth1
h3 h3-eth0:s2-eth2
s1 lo: s1-eth1:h1-eth0 s1-eth2:h2-eth0
s2 lo: s2-eth1:h2-eth1 s2-eth2:h3-eth0

为节点配置路由功能:

mininet> h1 ifconfig h1-eth0 192.168.12.1 netmask 255.255.255.0
mininet> h2 ifconfig h2-eth0 192.168.12.2 netmask 255.255.255.0
mininet> h2 ifconfig h2-eth1 192.168.23.2 netmask 255.255.255.0
mininet> h3 ifconfig h3-eth0 192.168.23.3 netmask 255.255.255.0
mininet> h1 route add default gw 192.168.12.2
mininet> h3 route add default gw 192.168.23.2
mininet> h2 sysctl net.ipv4.ip_forward=1

h1看ping通h3了:

mininet> h1 ping -c 1 192.168.23.3

weinxin
我的微信
微信号已复制
我的微信
这是我的微信扫一扫
 
Crq
  • 本文由 Crq 发表于2024年10月25日 11:22:10
  • 转载请注明:https://www.cncrq.com/11355.html
【技术快报】9.12-9.18 Linux教程

【技术快报】9.12-9.18

本期《linux就该这么学》的技术周报中,将为您推出Nginx源码安装及调优配置、国内三大云数据库测试对比、12个Linux进程管理命令介绍、怎样在Ubuntu中修改默认程序、在a...
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证