python 如何指定 Django 测试服务器应该监听哪个 eth 接口?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1188205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to specify which eth interface Django test server should listen on?
提问by Achimnol
As the title says, in a multiple ethernet interfaces with multiple IP environment, the default Django test server is not attached to the network that I can access from my PC. Is there any way to specify the interface which Django test server should use?
正如标题所说,在具有多个 IP 环境的多个以太网接口中,默认的 Django 测试服务器未连接到我可以从我的 PC 访问的网络。有什么方法可以指定 Django 测试服务器应该使用的接口吗?
-- Added --
- 添加 -
The network configuration is here. I'm connecting to the machine via 143.248.x.y address from my PC. (My PC is also in 143.248.a.b network.) But I cannot find this address. Normal apache works very well as well as other custom daemons running on other ports.
网络配置在这里。我正在通过 PC 上的 143.248.xy 地址连接到机器。(我的电脑也在 143.248.ab 网络中。)但是我找不到这个地址。普通的 apache 以及在其他端口上运行的其他自定义守护程序都可以很好地工作。
The one who configured this machine is not me, so I don't know much details of the network...
配置这台机器的不是我,所以我对网络的了解不多......
eth0 Link encap:Ethernet HWaddr 00:15:17:88:97:78
inet addr:192.168.6.100 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::215:17ff:fe88:9778/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:441917680 errors:0 dropped:0 overruns:0 frame:0
TX packets:357190979 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:191664873035 (178.5 GB) TX bytes:324846526526 (302.5 GB)
eth1 Link encap:Ethernet HWaddr 00:15:17:88:97:79
inet addr:172.10.1.100 Bcast:172.10.1.255 Mask:255.255.255.0
inet6 addr: fe80::215:17ff:fe88:9779/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1113794891 errors:0 dropped:97 overruns:0 frame:0
TX packets:699821135 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:843942929141 (785.9 GB) TX bytes:838436421169 (780.8 GB)
Base address:0x2000 Memory:b8800000-b8820000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1085510396 errors:0 dropped:0 overruns:0 frame:0
TX packets:1085510396 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:422100792153 (393.1 GB) TX bytes:422100792153 (393.1 GB)
peth0 Link encap:Ethernet HWaddr 00:15:17:88:97:78
inet6 addr: fe80::215:17ff:fe88:9778/64 Scope:Link
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:441918386 errors:0 dropped:742 overruns:0 frame:0
TX packets:515286699 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:199626686230 (185.9 GB) TX bytes:337365591758 (314.1 GB)
Base address:0x2020 Memory:b8820000-b8840000
veth0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
veth1 Link encap:Ethernet HWaddr 00:00:00:00:00:00
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
veth2 Link encap:Ethernet HWaddr 00:00:00:00:00:00
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
veth3 Link encap:Ethernet HWaddr 00:00:00:00:00:00
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
vif0.0 Link encap:Ethernet HWaddr fe:ff:ff:ff:ff:ff
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
vif0.1 Link encap:Ethernet HWaddr fe:ff:ff:ff:ff:ff
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
vif0.2 Link encap:Ethernet HWaddr fe:ff:ff:ff:ff:ff
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
vif0.3 Link encap:Ethernet HWaddr fe:ff:ff:ff:ff:ff
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
-- Added (2) --
-- 添加 (2) --
Finally I used w3m (a text-mode web browser which runs on terminal) to connect from localhost. :P
最后,我使用 w3m(在终端上运行的文本模式 Web 浏览器)从本地主机连接。:P
回答by grw
I think the OP is referring to having multiple interfaces configured on the test machine.
我认为 OP 是指在测试机器上配置了多个接口。
You can specify the IP address that Django will bind to as follows:
您可以指定 Django 将绑定到的 IP 地址,如下所示:
# python manage.py runserver 0.0.0.0:8000
This would bind Django to all interfaces on port 8000. You can pass any active IP address in place of 0.0.0.0, so simply use the IP address of the interface you want to bind to.
这会将 Django 绑定到端口 8000 上的所有接口。您可以传递任何活动 IP 地址来代替 0.0.0.0,因此只需使用要绑定到的接口的 IP 地址。
Hope this helps.
希望这可以帮助。
回答by Luper Rouch
Yes, if the IP of your interface is for example 192.168.1.2 and you want to run on port 8080, start the development server like this:
是的,如果您的接口的 IP 是例如 192.168.1.2 并且您想在端口 8080 上运行,请像这样启动开发服务器:
./manage.py runserver 192.168.1.2:8080
回答by Tamás Szelei
No. It's not how it works. The interface has an IP address, you have a network with the test server and your PC. You should connect to that IP (possibly with an alternative port that you specified), and that's all. If you only have these two devices in the network, it is most likely that both of them should have static IP addresses. (or, if there is not mutual network, you cannot connect to each other).
不,这不是它的工作原理。接口有一个 IP 地址,你有一个网络与测试服务器和你的 PC。您应该连接到该 IP(可能使用您指定的替代端口),仅此而已。如果网络中只有这两个设备,则它们很可能都应该具有静态 IP 地址。(或者,如果没有相互网络,则无法相互连接)。