2017年12月10日 星期日

[Linux 文章收集] Centos7 的 ifconfig 和 netstat

Source From Here 
Preface 
Centos7/RHEL 7 的 ifconfignetstatroute 和 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

這樣裝完就有 ifconfignetstat 和 route 以及 traceroute 和 traceroute6

改用別的指令 
其實 ifconfig 在 7 版中全部有新指令代替,所以可能要學習新的方法。 

ifconfig 改用 ip addr 
$ ip addr // 這個和 ifconfig 顯示的一樣
  1. 1: lo: mtu 65536 qdisc noqueue state UNKNOWN  
  2.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
  3.     inet 127.0.0.1/8 scope host lo  
  4.        valid_lft forever preferred_lft forever  
  5.     inet6 ::1/128 scope host  
  6.        valid_lft forever preferred_lft forever  
  7. 2: ens192: mtu 1500 qdisc pfifo_fast state UP qlen 1000  
  8.     link/ether 00:50:56:ba:0b:07 brd ff:ff:ff:ff:ff:ff  
  9.     inet 163.17.xx.xx/25 brd 163.17.40.127 scope global ens192  
  10.        valid_lft forever preferred_lft forever  
  11.     inet6 2001:288:5400:0:250:56ff:feba:b07/64 scope global dynamic  
  12.        valid_lft 2591718sec preferred_lft 2591718sec  
  13.     inet6 fe80::250:56ff:feba:b07/64 scope link  
  14.        valid_lft forever preferred_lft forever  

$ ip link // Show network device(s)
  1. 1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT  
  2.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
  3. 2: ens192: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000  
  4.     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. 1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT  
  2.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
  3.     RX: bytes  packets  errors  dropped overrun mcast  
  4.     4400       45       0       0       0       0  
  5.     TX: bytes  packets  errors  dropped carrier collsns  
  6.     4400       45       0       0       0       0  
  7. 2: ens192: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000  
  8.     link/ether 00:50:56:ba:0b:07 brd ff:ff:ff:ff:ff:ff  
  9.     RX: bytes  packets  errors  dropped overrun mcast  
  10.     207938930  2541628  0       1809366 0       495  
  11.     TX: bytes  packets  errors  dropped carrier collsns  
  12.     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
  1. State       Recv-Q Send-Q Local Address:Port                 Peer Address:Port           
  2. LISTEN      0      128           *:ssh                         *:*  
  3. LISTEN      0      128    127.0.0.1:postgres                    *:*  
  4. LISTEN      0      100    127.0.0.1:smtp                        *:*  
  5. LISTEN      0      128          :::ssh                        :::*  
  6. LISTEN      0      128         ::1:postgres                   :::*  
  7. LISTEN      0      100         ::1:smtp                       :::*  
// -u, --udp: Display UDP sockets.
# ss -lu
  1. State       Recv-Q Send-Q Local Address:Port                 Peer Address:Port           
  2. UNCONN      0      0             *:bootpc                      *:*  
  3. UNCONN      0      0      x.x.x.x:ntp                         *:*                     
  4. UNCONN      0      0      127.0.0.1:ntp                         *:*  
  5. UNCONN      0      0             *:ntp                         *:*  
  6. UNCONN      0      0             *:mdns                        *:*  
  7. UNCONN      0      0             *:59433                       *:*  
  8. UNCONN      0      0             *:39254                       *:*  
  9. UNCONN      0      0            :::60817                      :::*  
  10. UNCONN      0      0           ::1:ntp                        :::*  
  11. UNCONN      0      0            :::ntp                        :::*  

traceroute/traceroute6 改成 tracepath 
$ tracepath 168.95.1.1
  1. 1:  163.17.XX.XX                                          0.187ms pmtu 1500  
  2. 1:  163.17.40.126                                         0.263ms  
  3. 2:  163.17.38.250                                         0.555ms  
  4. 3:  br-NCHU-APTG.TANet.edu.tw                            19.799ms  
  5. 4:  no reply  
  6. 5:  tchn-3302.hinet.net                                   1.395ms asymm  6  
  7. 6:  tchn-3011.hinet.net                                  15.089ms  
  8. 7:  202-39-179-185.HINET-IP.hinet.net                     1.533ms  
  9. 8:  202-39-179-173.HINET-IP.hinet.net                     4.435ms reached  
  10.     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

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...