我需要能够使用 PHP 更改服务器的 IP 地址。我正在尝试以用户身份使用ifconfig eth0 down
以www-data
确保它能够正常工作。到目前为止,我已经摆脱了 /var/run/network/ifstate 文件的权限问题,但现在我得到了一条权限被拒绝的行,内容为SIOCSIFFLAGS: Permission denied
. 有没有解决的办法?如果不是,如何更改网页中服务器的 IP 地址?
php代码:
//if the ip has changed, bring down the network interface and bring it up with the new IP
if($ipConf != $ip) {
$ifdownSuccess = exec("ifconfig eth0 down", $downOutput, $downRetvar);
$ifupSuccess = exec("ifconfig eth0 up ".$ip, $upOutput, $upRetvar);
//TODO: check for ifupSucess and revert to old ip if the command failed
var_dump($downOutput);
var_dump($downRetvar);
var_dump($ifdownSuccess);
var_dump($upOutput);
var_dump($upRetvar);
var_dump($ifupSuccess);
}
返回:
array(0) { } int(127) string(0) "" array(0) { } int(127) string(0) ""
有没有办法解决这个权限问题或我可以使用其他工具来做到这一点?