简体   繁体   中英

Changing ip address of apache server using php

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.

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 (eg, change its owner to root, and set the suid bit), then run it from your PHP script. Yet, I advise against doing such thing

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM