微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用PHP更改服务器的IP地址

我需要能够使用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) ""

有没有办法解决这个权限问题或另一个工具,我可以用来做到这一点?

如何使用pipeparsing命令的输出

可以使用静态IP检测configuration的连接设备的networking和networking掩码吗?

所有接口的C / C ++ Linux MAC地址

通过增加额外的以太网接口来增加临时端口

将传出stream量绑定到eth0而不是eth0:1

如何获取NIC卡的逻辑名称,给出与其相关的IP地址?

在bash -c中设置variables

设置静态IP,如果没有从DHCP获取(脚本)

分析数字ifconfig标志

在VirtualBox 4.1.2的Android x86上没有networking

我有一个类似的问题,正在考虑以下解决方案:

1)PHP页面读取IP,网络掩码和网关,检查格式是否正确以及IP是否可行并将其写入文本文件

2)cronjob写在任何东西,寻找该文件,如果它在那里,它读取内容,解析它,并进行更改

这应该足够安全。

我明白了这一点。 答案是用usermod -a -G admin www-data添加www-data用户(或者你的服务器用户的名字)到管理员组。 如果你看看/etc/sudoers ,你会注意到这个组中的任何人都可以使用sudo -n <command>来执行sudo命令而不需要密码提示。 做了一个快速代码更改:

//if the ip has changed,bring down the network interface and bring it up with the new IP if($ipConf != $ip) { $ifdownSuccess = exec("sudo -n ifconfig eth0 down",$downRetvar); $ifupSuccess = exec("sudo -n ifconfig eth0 up ".$ip,$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); }

我现在在做生意 能够通过SSH连接新的IP地址,并通过新的IP查看网页。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐