我需要能够使用PHP更改服务器的IP地址。我正在尝试使用ifconfig eth0 down作为www-data用户,以确保它能正常工作。到目前为止,我已经摆脱了/ var/run/network/ifstate文件的权限问题,但是现在我得到了一个权限被拒绝的行,其内容为SIOCSIFFLAGS: Permission denied。有没有解决的办法?如果不是,您如何更改网页中服务器的IP地址?使用PHP更改服务器的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) ""
是有解决权限问题的方式或其他工具,我可以用它来做到这一点?
+0
你不能使用sudo,只是让ifup/ifdown?这可以解决所有权限问题。 –
+0
我认为只有root可以降低网络接口......但我可能是错的。 –
+0
但是我如何从php exec()调用中使用'sudo'?它需要在以下行上输入密码... –