May 6, 2012

Changing ip address of apache server using php

Question by apurv nerlekar

I am trying to create a settings page(for the clients) where in they can view the current up address,change the ip address etc. I have a php file to view the ip address

  echo $res;

This code works just fine and displays the expected result.
However the code to change the ip address of the server is not working properly.

 shell_exec("ifconfig eth0");

After running this code when i check the ipaddress on the terminal using ipaddr i don’t see any change in the ipaddress.
Pls point out where i am going wrong. I think its a problem of apache not being a super/root user. If that is the case i don’t know how to make apache run as a root user.

Answer by Starx

IP address are configured in Network Layer of an Network Protocol, not in application layer where PHP runs. Simply, PHP does not have access to it and cannot changed them.

Just imagine the vulnerabilities it could create if this was possible.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!