我有两个网络接口wlan0
,usb0
在运行 Ubuntu 的 RaspberryPi 上。它们都连接到互联网。
我正在编写一个python脚本来在上运行一个web服务器wlan0
。当一个请求发送到我的pi时,我会向发送另一个请求usb0
,响应数据将发送回原始请求的来源。
当我尝试通过 发送测试请求时wlan0
,它确实按预期工作。但当我尝试使用 时usb0
,它不起作用
ifconfig
输出:
eth0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether dc:a6:32:46:16:87 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 120 bytes 9012 (9.0 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 120 bytes 9012 (9.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.42.208 netmask 255.255.255.0 broadcast 192.168.42.255
inet6 fe80::54e4:31ff:fe59:90d9 prefixlen 64 scopeid 0x20<link>
ether 56:e4:31:59:90:d9 txqueuelen 1000 (Ethernet)
RX packets 8 bytes 1428 (1.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12 bytes 2008 (2.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.195 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::dea6:32ff:fe46:1688 prefixlen 64 scopeid 0x20<link>
inet6 2402:800:6116:a8ae:dea6:32ff:fe46:1688 prefixlen 64 scopeid 0x0<global>
ether dc:a6:32:46:16:88 txqueuelen 1000 (Ethernet)
RX packets 464 bytes 57446 (57.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 394 bytes 65085 (65.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
路由表:
default via 192.168.1.1 dev wlan0
default via 192.168.1.1 dev wlan0 proto dhcp src 192.168.1.195 metric 600
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.195
192.168.1.1 dev wlan0 proto dhcp scope link src 192.168.1.195 metric 600
192.168.42.0/24 dev usb0 proto kernel scope link src 192.168.42.208
broadcast 127.0.0.0 dev lo table local proto kernel scope link src 127.0.0.1
local 127.0.0.0/8 dev lo table local proto kernel scope host src 127.0.0.1
local 127.0.0.1 dev lo table local proto kernel scope host src 127.0.0.1
broadcast 127.255.255.255 dev lo table local proto kernel scope link src 127.0.0.1
broadcast 192.168.1.0 dev wlan0 table local proto kernel scope link src 192.168.1.195
local 192.168.1.195 dev wlan0 table local proto kernel scope host src 192.168.1.195
broadcast 192.168.1.255 dev wlan0 table local proto kernel scope link src 192.168.1.195
broadcast 192.168.42.0 dev usb0 table local proto kernel scope link src 192.168.42.208
local 192.168.42.208 dev usb0 table local proto kernel scope host src 192.168.42.208
broadcast 192.168.42.255 dev usb0 table local proto kernel scope link src 192.168.42.208
::1 dev lo proto kernel metric 256 pref medium
2402:800:6116:a8ae::/64 dev wlan0 proto ra metric 600 expires 86355sec pref medium
fe80::/64 dev wlan0 proto kernel metric 256 pref medium
fe80::/64 dev usb0 proto kernel metric 256 pref medium
default via fe80::1 dev wlan0 proto ra metric 600 expires 1755sec pref low
local ::1 dev lo table local proto kernel metric 0 pref medium
local 2402:800:6116:a8ae:dea6:32ff:fe46:1688 dev wlan0 table local proto kernel metric 0 pref medium
local fe80::54e4:31ff:fe59:90d9 dev usb0 table local proto kernel metric 0 pref medium
local fe80::dea6:32ff:fe46:1688 dev wlan0 table local proto kernel metric 0 pref medium
ff00::/8 dev wlan0 table local metric 256 pref medium
ff00::/8 dev usb0 table local metric 256 pref medium
抱歉,如果我问了一个愚蠢的问题,我完全是网络方面的新手......
答案1
所以我以某种方式找到了答案。您需要以 curl 身份运行root
或CAP_NET_RAW
向二进制文件添加功能/usr/bin/curl
才能使其正常工作。
就我而言,我只需要以 root 权限运行我的 python 脚本,它现在就可以运行了。