Linux ifconfig查看本机IP提示command not found

本文转自:[url]http://blog.csdn.net/aigoleague/article/details/7996151[/url]


[size=x-small][color=green]问题:在red hat enterprise linux 5中查询IP地址时,输入ifconfig命令报错:“ifconfig: command not found”
原因:ifconfig命令所在路径/sbin未包含在系统环境变量PATH中[/color][/size]
[color=red][size=small]解决方法:
1. 直接输入:/sbin/ifconfig
2. 临时修改环境变量:在shell中输入
$export PATH = $PATH:/sbin
然后再输入ifconfig命令即可,但是这只是临时更改了shell中的PATH,如果关闭shell,则修改消失,下次还需要重复如上操作
3.永久修改PATH变量使之包含/sbin路径:
打开/etc/profile文件,在其中输入export PATH=$PATH:/sbin,保存并重启X即可,这样一来,PATH路径永久修改成功,以后任何时候只需书序ifconfig命令即可[/size][/color]

[color=green][size=x-small]下面的代码可以得到本机的ip地址
function getIP(){
exec("/sbin/ifconfig",$out,$stats);
//var_dump($out);
if(!empty($out))
{
if(isset($out[1]) && strstr($out[1],'addr:'))
{
$tmpArray = explode(":", $out[1]);
print_r($tmpArray);
$tmpIp = explode(" ", $tmpArray[1]);
print_r($tmpIp);
//if(preg_match ("/192\.168\.1\./", trim($tmpIp[0]))) //pattern根据需要修改
//{
return trim($tmpIp[0]);
//}
}
}
return '127.0.0.1';

}

$my_ip = getIP();

//列出php的内置变量
php -i[/size][/color]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值