Preface
Centos7/RHEL 7 的 ifconfig, netstat, route 和 traceroute 都不見了,其實 Centos6 就已經有一些變革,只是 netstat 和 ifconfig 那時還保留著,所以沒發現. Centos7 和RHEL 7 最小安裝中竟然沒有我最常用的 ifconfig 和 netstat?
# ifconfig
-bash: ifconfig: command not found
很好,原來centos/rhel準備把這兩個指令作廢,那怎麼辦?一是安裝,二是改用別的指令。
安裝
yum 有提供一個尋找程式所屬套件的方法:
# yum provides ifconfig
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.unixheads.org
* epel: mirror.steadfast.net
* extras: mirrors.liquidweb.com
* updates: mirrors.advancedhosters.com
net-tools-2.0-0.22.20131004git.el7.x86_64 : Basic networking tools
Repo : @base
Matched from:
Filename : /usr/sbin/ifconfig
# yum whatprovides ifconfig
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.unixheads.org
* epel: mirror.steadfast.net
* extras: mirrors.liquidweb.com
* updates: mirrors.lga7.us.voxel.net
net-tools-2.0-0.22.20131004git.el7.x86_64 : Basic networking tools
Repo : @base
Matched from:
Filename : /usr/sbin/ifconfig
# yum install net-tools // 安裝 infconfig
# yum install traceroute // 安裝 traceroute
這樣裝完就有 ifconfig, netstat 和 route 以及 traceroute 和 traceroute6.
改用別的指令
其實 ifconfig 在 7 版中全部有新指令代替,所以可能要學習新的方法。
ifconfig 改用 ip addr
$ ip addr // 這個和 ifconfig 顯示的一樣
- 1: lo:
mtu 65536 qdisc noqueue state UNKNOWN- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
- inet 127.0.0.1/8 scope host lo
- valid_lft forever preferred_lft forever
- inet6 ::1/128 scope host
- valid_lft forever preferred_lft forever
- 2: ens192:
mtu 1500 qdisc pfifo_fast state UP qlen 1000- link/ether 00:50:56:ba:0b:07 brd ff:ff:ff:ff:ff:ff
- inet 163.17.xx.xx/25 brd 163.17.40.127 scope global ens192
- valid_lft forever preferred_lft forever
- inet6 2001:288:5400:0:250:56ff:feba:b07/64 scope global dynamic
- valid_lft 2591718sec preferred_lft 2591718sec
- inet6 fe80::250:56ff:feba:b07/64 scope link
- valid_lft forever preferred_lft forever
$ ip link // Show network device(s)
- 1: lo:
mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
- 2: ens192:
mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000- link/ether 00:50:56:ba:0b:07 brd ff:ff:ff:ff:ff:ff
// -s, -stats, -statistics: Output more information.
$ ip -s link
- 1: lo:
mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
- RX: bytes packets errors dropped overrun mcast
- 4400 45 0 0 0 0
- TX: bytes packets errors dropped carrier collsns
- 4400 45 0 0 0 0
- 2: ens192:
mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000- link/ether 00:50:56:ba:0b:07 brd ff:ff:ff:ff:ff:ff
- RX: bytes packets errors dropped overrun mcast
- 207938930 2541628 0 1809366 0 495
- TX: bytes packets errors dropped carrier collsns
- 788417 8512 0 0 0 0
netstat 改用 ss
netstat 是很重要的連線觀察工具,使用新的指令 ss 來取代,功能也是差不多:
// -l, --listening: Display only listening sockets (these are omitted by default).
// -t, --tcp: Display TCP sockets.
# ss -lt
// -u, --udp: Display UDP sockets.
- State Recv-Q Send-Q Local Address:Port Peer Address:Port
- LISTEN 0 128 *:ssh *:*
- LISTEN 0 128 127.0.0.1:postgres *:*
- LISTEN 0 100 127.0.0.1:smtp *:*
- LISTEN 0 128 :::ssh :::*
- LISTEN 0 128 ::1:postgres :::*
- LISTEN 0 100 ::1:smtp :::*
# ss -lu
- State Recv-Q Send-Q Local Address:Port Peer Address:Port
- UNCONN 0 0 *:bootpc *:*
- UNCONN 0 0 x.x.x.x:ntp *:*
- UNCONN 0 0 127.0.0.1:ntp *:*
- UNCONN 0 0 *:ntp *:*
- UNCONN 0 0 *:mdns *:*
- UNCONN 0 0 *:59433 *:*
- UNCONN 0 0 *:39254 *:*
- UNCONN 0 0 :::60817 :::*
- UNCONN 0 0 ::1:ntp :::*
- UNCONN 0 0 :::ntp :::*
traceroute/traceroute6 改成 tracepath
$ tracepath 168.95.1.1
- 1: 163.17.XX.XX 0.187ms pmtu 1500
- 1: 163.17.40.126 0.263ms
- 2: 163.17.38.250 0.555ms
- 3: br-NCHU-APTG.TANet.edu.tw 19.799ms
- 4: no reply
- 5: tchn-3302.hinet.net 1.395ms asymm 6
- 6: tchn-3011.hinet.net 15.089ms
- 7: 202-39-179-185.HINET-IP.hinet.net 1.533ms
- 8: 202-39-179-173.HINET-IP.hinet.net 4.435ms reached
- Resume: pmtu 1500 hops 8 back 248
route 改為 ip route
$ ip route show
192.168.91.0/24 dev eth0 proto kernel scope link src 192.168.91.128
169.254.0.0/16 dev eth0 scope link metric 1002
default via 192.168.91.2 dev eth0
介面開關
$ ip link set eth1 up # Or ip l set eth1 up
$ ip link set eth1 down # Or ip l set eth1 down
Supplement
* Linux 文章收集 - 10 Useful “IP” Commands to Configure Network Interfaces
沒有留言:
張貼留言