0

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

 <?php
  $res=shell_exec("ifconfig");
  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.

 <?php
 shell_exec("ifconfig eth0 192.168.163.136");
 ?>

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.

2
  • possible duplicate of change ip address of server using PHP Commented May 6, 2012 at 9:38
  • Your Intentions are unclear wtf are you trying to do!?! Commented May 6, 2012 at 16:43

3 Answers 3

2

Your PHP script doesn't have enough privileges to change the interface address. You may want to write a Shellscript, give it the right privileges (e.g., change its owner to root, and set the suid bit), then run it from your PHP script. Yet, I advise against doing such thing

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

2 Comments

ok so can u give me more details on how to set the suid bit. Any link? Thanks
Sure. Check if this blog post helps. Also be sure to read the first link the author provides (Why suid shell scripts are a very bad idea). Another way would be giving sudo privileges to the user that runs your script, which is even an worse idea - it could do a lot of damage!
1

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.

5 Comments

Any code running on a server can change the IP address on the server provided it has given enough rights. Usually the PHP / Apache server doesn't have those, but can be given to them (although from a security standpoint not overly wise). Changing an IP address would however most probably break the current HTTP connection to the dropped IP.
OK i understand that it is not a wise move but still i would like to know how to get the rights for apache to run that particular script
@apurvnerlekar, You are not getting the point, if somehow you are able to change the IP, you will not be do anything, because the active connection will already be disconnected.
@apurvnerlekar, If you insist on doing this, there seems to be previous queustion asked with an working solution. Check here
I dont think I have said anything incorrect. Why the downvote?
0

Adding /srv/http before ifconfig worked. All it needed was the root owned location.

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.