如何停用從 IPv6 到 IPv4 的 IP 轉發

如何停用從 IPv6 到 IPv4 的 IP 轉發

我的網路卡上有 IPv4 和 ipv6 位址,當我使用curl 傳送請求時,我只想使用對應的 IPv4 或 IPv6,而不需要後備,例如,當發生 IPv6 到 IPv4 時。

curl --interface XXXX: c020: XXXX: e601: XXXX: 596c: XXXX: db97 http://ip4only.me/api/

curl: (45) bind failed with error 22: Invalid argument

curl -x http: // [2603: XXXX: 8003: e601: XXXX: 596c: XXXX: db97]: 8080 http://ip4only.me/api/

IPv4,130.XX.XXX.81

如果網站僅接受 IPv4 位址(與 --interface 變體一樣),我希望收到錯誤。

IPv4 轉送已關閉。

ubuntu @ app-1: ~ $ sudo grep -r ip_forward / etc
/etc/ufw/sysctl.conf:#net/ipv4/ip_forward=1
/etc/sysctl.conf:#net.ipv4.ip_forward=1

顯然,當我使用連接埠發送它時,無論如何都會發生轉送。

答案1

-4您可以使用和選項覆寫所使用的 IP 協定棧-6,分別將其限制為 IPv4 或 IPv6。考慮:

$ curl -6 http://ip4only.me/api/
curl: (6) Could not resolve host: ip4only.me

$ curl -4 http://ip4only.me/api/
IPv4,198.51.100.84,Remaining fields reserved for future use,,,

相關內容