如何检测系统是否在UNIX shell脚本中启用了IPv6?

时间:2022-12-25 13:56:50

I have a shell script, that is being executed on various POSIX environments such as Linux, Mac OSX or even Cygwin. The script needs to reliably detect if given system has IPv6 enabled. E.g. I can use at least IPv6 local loopback (::1). So the question is: How to detect if system has ipv6 enabled in a UNIX shell in a POSIX compatible way?

我有一个shell脚本,它正在各种POSIX环境中执行,例如Linux,Mac OSX甚至Cygwin。该脚本需要可靠地检测给定系统是否启用了IPv6。例如。我至少可以使用IPv6本地环回(:: 1)。所以问题是:如何检测系统是否以兼容POSIX的方式在UNIX shell中启用了ipv6?

1 个解决方案

#1


8  

This can be tested by checking the existance of /proc/net/if_inet6 as follows:

这可以通过检查/ proc / net / if_inet6的存在来测试,如下所示:

test -f /proc/net/if_inet6 && echo "IPv6 supported" || echo "IPv6 not supported"

I've tested it on Ubuntu, Mint, Raspberry PI and Bash shell in Windows, and it works in all these environments.

我在Windows上的Ubuntu,Mint,Raspberry PI和Bash shell上进行了测试,它适用于所有这些环境。

#1


8  

This can be tested by checking the existance of /proc/net/if_inet6 as follows:

这可以通过检查/ proc / net / if_inet6的存在来测试,如下所示:

test -f /proc/net/if_inet6 && echo "IPv6 supported" || echo "IPv6 not supported"

I've tested it on Ubuntu, Mint, Raspberry PI and Bash shell in Windows, and it works in all these environments.

我在Windows上的Ubuntu,Mint,Raspberry PI和Bash shell上进行了测试,它适用于所有这些环境。