Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if system has IPv6 enabled in a UNIX shell script?

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?

like image 927
Ales Teska Avatar asked Oct 11 '16 17:10

Ales Teska


1 Answers

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

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.

like image 165
Bouke Avatar answered Oct 13 '22 07:10

Bouke