如何在Linux中使用虚拟IP地址发送HTTP请求? [英] How to send HTTP request using virtual IP address in Linux?
问题描述
我使用CentOS-Linux,我想从eth0:0,eth0:1,eth0:2等虚拟IP地址发送HTTP请求,同时使用eth0。如何做到这一点?我实际上tring使一个流量生成器工具使用Python。我已经成功地发送多个并发HTTP请求,现在我的下一步是从多个IP地址发送这样的请求。我不知道如何实现这个任务。任何人都可以帮助我?
I am using CentOS-Linux and I want to send HTTP requests from virtual IP addresses like eth0:0,eth0:1,eth0:2,etc simultaneously with eth0. How to do this? I am actually tring to make one traffic generator tool using Python. I have been successful in sending multiple and concurrent HTTP requests and now my next step is to send such requests from multiple IP addresses. I dont know how to achieve this task. Can anyone help me?
推荐答案
2个选项:
- 使用curl:
curl --i<'interface ip using which you want to generate traffic'> destination
curl --i <'interface ip using which you want to generate traffic'> destination
例如对我来说,eth0的ip是10.91.56.3,eth0:1的ip是10.91.56.4所以,使用10.91.56.4(eth0:1) p>
eg for me, eth0's ip is 10.91.56.3 and eth0:1's ip is 10.91.56.4 so, to generate traffic using 10.91.56.4(eth0:1)
curl --i 10.91.56.4 http://10.91.55.3/filex.txt
- 回答@AKX 此处
- followed answer by @AKX here
写你的接口的ip而不是127.0.0.1
例如在我的情况下我是这样做的:
In above answer in 3rd class write your interface's ip instead of 127.0.0.1 eg in my case i did like this:
class BindableHTTPHandler(urllib2.HTTPHandler):
def http_open(self, req):
return self.do_open(BindableHTTPConnectionFactory('10.91.56.4'), req)
这篇关于如何在Linux中使用虚拟IP地址发送HTTP请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!