2

I want to enable/disable IPv4/IPv6 in Linux programmatically using C. Is this possible? If yes, kindly please let me know how to do this and any reference to sample program would also be very helpful.

1
  • Are you sure to want to disable IP on localhost ? Commented Oct 10, 2013 at 12:47

1 Answer 1

2

See here: https://unix.stackexchange.com/questions/66574/how-can-i-disable-ipv6-in-custom-built-embedded-setup

Unfortunately, the _sysctl(2) system call API is deprecated, so you are left with writing to files in /proc/ directly (which is easy enough from C, just a little funny smelling):

The important bits seem to be writing a textual value of 1 (text, not int) to at least the first of these two files, and possibly both:

/proc/sys/net/ipv6/conf/all/disable_ipv6
/proc/sys/net/ipv6/conf/default/disable_ipv6

As for IPv4, it's less clear to me. Do you really need to disable IPv4 while leaving IPv6 running?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.