我使用nestat
将Ubuntu 20.04服务器配置为具有多个IPv6地址,如下所示:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: yes
dhcp6: no
addresses:
- "xxxx:xxxx:xxxx:xxxx::1/64"
- "xxxx:xxxx:xxxx:xxxx::2/64"
gateway6: "xxxx::1"
nameservers:
search: [xxxx.xxxx.com]
addresses:
- xxxx:xxxx::6
- xxxx:xxxx::7
我可以在ifconfig
的输出中看到这些地址,当我在同一服务器上使用ping6
对其进行ping操作时,它就可以工作。现在,我尝试使用localAddress
绑定到这些IPv6地址之一,并发送HTTP GET请求:
const http = require('http')
const options = {
host: "xxx.xxx.xxx.xxx",
port: 3000,
path: '/',
family: 6,
localAddress: 'xxxx:xxxx:xxxx:xxxx::1'
}
const req = http.get(options)
req.on('response', res => {
res.on('data', chunk => console.log)
})
这将导致以下错误:
Error: bind EINVAL xxxx:xxxx:xxxx:xxxx::1
我了解此错误可能意味着多种情况:
套接字已经绑定到一个地址,并且协议没有 支持绑定到新地址;或套接字已关闭。
我该怎么调试?
我解决了这个问题,答案很简单-我连接的服务器根本不支持IPv6。如果我将host
值替换为google.com,则一切正常。我希望该错误消息更具描述性。