2021-05-12 14:32:11
普通使用者在rhel5和rhel6版本下執行ifconfig區別
雖說現在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
相關文章