我有一个场景,其中有一个带有两个接口的服务器机器。每个接口都有自己的IP地址。服务器机器托管一个HTTP服务器,该服务器应该可以通过这两个接口访问。
重现这种情况的完整python脚本:
from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.net import Mininet
from mininet.topo import Topo
class TestTopology(Topo):
def __init__(self):
Topo.__init__(self)
host1_id = self.addHost('h1')
host2_id = self.addHost('h2')
server_id = self.addHost('server')
self.addLink(server_id, host1_id)
self.addLink(server_id, host2_id)
def configure_network(network):
server = network.get('server')
server.setIP('10.0.0.10', intf='server-eth0')
server.setMAC('00:00:00:00:00:10', intf='server-eth0')
server.setIP('10.0.0.11', intf='server-eth1')
server.setMAC('00:00:00:00:00:11', intf='server-eth1')
server.cmd("python -m SimpleHTTPServer 8080 &")
# Run 'sudo python *path_to_this_script*' in mininet VM.
if __name__ == '__main__':
setLogLevel('info')
net = Mininet(topo=TestTopology())
configure_network(net)
net.pingAll()
CLI(net)
SimpleHTTPServer默认监听0.0.0.0。
' pingAll'测试显示服务器可由h1访问(反之亦然),但h2不是这种情况。
当然,我也不能从h2 wget
开始。
如何配置服务器接口,以便服务器通过这两个接口响应ping
和wget
命令?
/etc/network/interfaces
包含一些配置,但它是关于一个不存在的eth0
接口,所以我认为它没有被使用。
注意:我已经了解到对于linux,一个特定的IP!=网络接口。服务器从h1响应ping 10.0.0.10和10.0.0.11,但我希望它能在两个物理接口上响应。
答案 0 :(得分:1)
您可以尝试从mininet.util
导入自定义就我而言,重新排序代码有效。
这是我的代码:
#!/usr/bin/python
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.node import CPULimitedHost, Host, Node
from mininet.node import OVSKernelSwitch, UserSwitch
from mininet.node import IVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink, Intf, Link
from mininet.util import makeNumeric, custom
from subprocess import call
def myNetwork():
link = custom(TCLink, bw=10)
net = Mininet( topo=None,
build=False,
ipBase='10.0.0.0/8')
info( '*** Adding controller\n' )
info( '*** Add switches\n')
s5 = net.addSwitch('s5', cls=OVSKernelSwitch, failMode='standalone')
s2 = net.addSwitch('s2', cls=OVSKernelSwitch, failMode='standalone')
s7 = net.addSwitch('s7', cls=OVSKernelSwitch, failMode='standalone')
s4 = net.addSwitch('s4', cls=OVSKernelSwitch, failMode='standalone')
r8 = net.addHost('r8', cls=Node, ip='0.0.0.0')
r8.cmd('sysctl -w net.ipv4.ip_forward=1')
r9 = net.addHost('r9', cls=Node, ip='0.0.0.0')
r9.cmd('sysctl -w net.ipv4.ip_forward=1')
r10 = net.addHost('r10', cls=Node, ip='0.0.0.0')
r10.cmd('sysctl -w net.ipv4.ip_forward=1')
info( '*** Add hosts\n')
h1 = net.addHost('h1', cls=Host, ip='192.168.2.1', defaultRoute=None)
h2 = net.addHost('h2', cls=Host, ip='192.168.3.1', defaultRoute=None)
info( '*** Add links\n')
net.addLink(s2, r9)
net.addLink(s4, r10)
net.addLink(r9, s5)
net.addLink(s7, r8)
net.addLink(r8, h2)
net.addLink(s5, h2)
net.addLink(s2, h1)
net.addLink(s4, h1)
net.addLink(r10, s7)
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches\n')
net.get('s5').start([])
net.get('s2').start([])
net.get('s7').start([])
net.get('s4').start([])
info( '*** Post configure switches and hosts\n')
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
myNetwork()
答案 1 :(得分:0)
我看到您正确配置了两个接口的IP地址,但是没有以太网链接连接其他主机上的第二个接口,这就是该接口上没有连接的原因。要正确配置,您必须:
我希望它有助于解决问题...