虽说现在rhel已经到7版本,5版本也已淘汰,但不可否认仍有相当一部分的系统仍使用5版本在坚挺的提供服务,所以有必要搞清楚一下一些基础知识。
1、首先看问题
在rhel5下直接执行ifconfig命令会提示命令无法找到,如:
[reed@localhost ~]$ ifconfig
-bash: ifconfig: command not found
而这样执行则可以,如:
[reed@localhost ~]$ /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版本下却没有这样的问题,如下:
[reed@reed ~]$ 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
[reed@localhost ~]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/reed/bin
rhel6
[reed@reed ~]$ 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)临时生效
[reed@localhost ~]$ PATH=$PATH:/sbin
[reed@localhost ~]$ 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
[reed@localhost ~]$ 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的版本。
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-02/140332.htm