普通用户在rhel5和rhel6版本下执行ifconfig区别
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了普通用户在rhel5和rhel6版本下执行ifconfig区别相关的知识,希望对你有一定的参考价值。
虽说现在rhel已经到7版本,5版本也已淘汰,但不可否认仍有相当一部分的系统仍使用5版本在坚挺的提供服务,所以有必要搞清楚一下一些基础知识。
1、首先看问题
在rhel5下直接执行ifconfig命令会提示命令无法找到,如:
[[email protected] ~]$ ifconfig -bash: ifconfig: command not found
而这样执行则可以,如:
[[email protected] ~]$ /sbin/ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:F1:35:E1 inet addr:192.168.209.133 Bcast:192.168.209.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8413 errors:0 dropped:0 overruns:0 frame:0 TX packets:7240 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:5215094 (4.9 MiB) TX bytes:1271295 (1.2 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:1635 errors:0 dropped:0 overruns:0 frame:0 TX packets:1635 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:4508168 (4.2 MiB) TX bytes:4508168 (4.2 MiB)
在rhel6版本下却没有这样的问题,如下:
[[email protected] ~]$ ifconfig eth1 Link encap:Ethernet HWaddr 00:0C:29:A7:4F:64 inet addr:192.168.209.142 Bcast:192.168.209.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fea7:4f64/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1608 errors:0 dropped:0 overruns:0 frame:0 TX packets:869 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:584674 (570.9 KiB) TX bytes:124717 (121.7 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) virbr0 Link encap:Ethernet HWaddr 52:54:00:62:53:D7 inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:11 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:2595 (2.5 KiB)
2、原因:区别在于,rhel5下的普通用户PATH变量不包括/sbin,而rhel6则包括,两者异同如下:
rhel5
[[email protected] ~]$ echo $PATH /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/reed/bin
rhel6
[[email protected] ~]$ echo $PATH /usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/reed/bin
3、解决办法
1)直接输入绝对路径命令即可,如/sbin/ifconfig
2)修改环境变量:
2.1)临时生效
[[email protected] ~]$ PATH=$PATH:/sbin [[email protected] ~]$ ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:F1:35:E1 inet addr:192.168.209.133 Bcast:192.168.209.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8935 errors:0 dropped:0 overruns:0 frame:0 TX packets:7552 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:5258006 (5.0 MiB) TX bytes:1319923 (1.2 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:1635 errors:0 dropped:0 overruns:0 frame:0 TX packets:1635 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:4508168 (4.2 MiB) TX bytes:4508168 (4.2 MiB)
2.2)永久生效,修改.bash_profile
[[email protected] ~]$ cat .bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:/sbin export PATH
以上仅仅是举例ifconfig命令,当然在5版本下的设计确实是这样,大家可以举一反三,多学习一下5和6的版本。
本文出自 “[[email protected]卢伟开~]#rm -rf /” 博客,请务必保留此出处http://luweikai.blog.51cto.com/1705672/1895449
以上是关于普通用户在rhel5和rhel6版本下执行ifconfig区别的主要内容,如果未能解决你的问题,请参考以下文章