过时的命令

过时的命令

过时的命令:arp ;ifconfig; route;netstat;mii-tool; nameif;iptunnel; ipmaddr
替代过时命令的新式命令:ip; ss;ethtool ;ifrename

1. ip

ip是iproute2工具包里面的一个命令行工具,用于配置网络接口以及路由表。
iproute2 正在逐步取代旧的 net-tools(ifconfig)。
关于新命令ip的常见用法,看下面这张图就够了。


IP.png

ip常用参数选项
-V:显示指令版本信息;
-s:输出更详细的信息;
-f:强制使用指定的协议族;
-4:指定使用的网络层协议是IPv4协议;
-6:指定使用的网络层协议是IPv6协议;
-0:输出信息每条记录输出一行,即使内容较多也不换行显示;
-r:显示主机时,不使用IP地址,而使用主机的域名。

2. ss

ss命令用来显示处于活动状态的套接字信息。ss命令可以用来获取socket统计信息,它可以显示和netstat类似的内容。但ss的优势在于它能够显示更多更详细的有关TCP和连接状态的信息,而且比netstat更快速更高效。

当服务器的socket连接数量变得非常大时,无论是使用netstat命令还是直接cat /proc/net/tcp,执行速度都会很慢。可能你不会有切身的感受,但请相信我,当服务器维持的连接达到上万个的时候,使用netstat等于浪费 生命,而用ss才是节省时间。

天下武功唯快不破。ss快的秘诀在于,它利用到了TCP协议栈中tcp_diag。tcp_diag是一个用于分析统计的模块,可以获得Linux 内核中第一手的信息,这就确保了ss的快捷高效。当然,如果你的系统中没有tcp_diag,ss也可以正常运行,只是效率会变得稍慢。

语法
ss (选项)

选项

-h:显示帮助信息;
-V:显示指令版本信息;
-n:不解析服务名称,以数字方式显示;
-a:显示所有的套接字;
-l:显示处于监听状态的套接字;
-o:显示计时器信息;
-m:显示套接字的内存使用情况;
-p:显示使用套接字的进程信息;
-i:显示内部的TCP信息;
-4:只显示ipv4的套接字;
-6:只显示ipv6的套接字;
-t:只显示tcp套接字;
-u:只显示udp套接字;
-d:只显示DCCP套接字;
-w:仅显示RAW套接字;
-x:仅显示UNIX域套接字。

显示ICP连接

root@newbie-unknown85882:~# ss -t -a
State      Recv-Q Send-Q                         Local Address:Port                                          Peer Address:Port                
LISTEN     0      511                                        *:8888                                                     *:*                    
LISTEN     0      100                                        *:6082                                                     *:*                    
LISTEN     0      5                                  127.0.0.1:4                                                        *:*                    
LISTEN     0      128                                127.0.0.1:8                                                        *:*                    
LISTEN     0      128                                        *:32200                                                    *:*                    
LISTEN     0      5                                  127.0.0.1:5901                                                     *:*                    
ESTAB      0      52                               10.83.3.102:32200                                           10.83.3.11:58406                
ESTAB      0      0                                10.83.3.102:51386                                          106.2.67.75:19920  

显示 Sockets 摘要

root@newbie-unknown85882:~# ss -s
Total: 115 (kernel 118)
TCP:   8 (estab 2, closed 0, orphaned 0, synrecv 0, timewait 0/0), ports 0

Transport Total     IP        IPv6
*         118       -         -        
RAW       1         1         0        
UDP       4         4         0        
TCP       8         8         0        
INET      13        13        0        
FRAG      0         0         0        

root@newbie-unknown85882:~# 

列出所有打开的网络连接端口

root@newbie-unknown85882:~# ss -l
Netid  State      Recv-Q Send-Q                      Local Address:Port                                       Peer Address:Port                
nl     UNCONN     0      0                                    rtnl:ntpd/623                                               *                     
nl     UNCONN     0      0                                    rtnl:kernel                                                 *                     
nl     UNCONN     0      0                                    rtnl:ntpd/623                                               *                     
nl     UNCONN     4352   0                                 tcpdiag:ss/22134                                               *                     
nl     UNCONN     768    0                                 
...
...               
tcp    LISTEN     0      128                                     *:32200                                                 *:*                    
tcp    LISTEN     0      5                               127.0.0.1:5901                                                  *:*                    
root@newbie-unknown85882:~# 

查看进程使用的socket

root@newbie-unknown85882:~# ss -pl
Netid  State      Recv-Q Send-Q                      Local Address:Port                                       Peer Address:Port                
nl     UNCONN     0      0                                    rtnl:ntpd/623                                               *                     
nl     UNCONN     0      0                                    rtnl:kernel                                                 *                     
nl     UNCONN     0      0                                    rtnl:ntpd/623                                               *                     
nl     UNCONN     4352   0                                 tcpdiag:ss/22157                                               *                     
nl     UNCONN     768    0                                 tcpdiag:kernel                                                 *                     
nl     UNCONN     0      0                                 
...
...
tcp    LISTEN     0      128                                     *:32200                                                 *:*                     users:(("sshd",pid=539,fd=3))
tcp    LISTEN     0      5                               127.0.0.1:5901                                                  *:*                     users:(("Xtigervnc",pid=3985,fd=7))

找出打开套接字/端口应用程序

root@newbie-unknown85882:~# ss -pl | grep 32200
tcp    LISTEN     0      128     *:32200                 *:*                     users:(("sshd",pid=539,fd=3))
root@newbie-unknown85882:~# 

显示所有UDP Sockets

root@newbie-unknown85882:~# ss -u -a
State      Recv-Q Send-Q                         Local Address:Port                                          Peer Address:Port                
UNCONN     0      0                                          *:bootpc                                                   *:*                    
UNCONN     0      0                                10.83.3.102:ntp                                                      *:*                    
UNCONN     0      0                                  127.0.0.1:ntp                                                      *:*                    
UNCONN     0      0                                          *:ntp                                                      *:*                    
root@newbie-unknown85882:~# 

3. ethtool

语法
ethtool (选项)

选项

-a 查看网卡中 接收模块RX、发送模块TX和Autonegotiate模块的状态:启动on 或 停用off。
-A 修改网卡中 接收模块RX、发送模块TX和Autonegotiate模块的状态:启动on 或 停用off。
-c display the Coalesce information of the specified ethernet card。
-C Change the Coalesce setting of the specified ethernet card。
-g Display the rx/tx ring parameter information of the specified ethernet card。
-G change the rx/tx ring setting of the specified ethernet card。
-i 显示网卡驱动的信息,如驱动的名称、版本等。
-d 显示register dump信息, 部分网卡驱动不支持该选项。
-e 显示EEPROM dump信息,部分网卡驱动不支持该选项。
-E 修改网卡EEPROM byte。
-k 显示网卡Offload参数的状态:on 或 off,包括rx-checksumming、tx-checksumming等。
-K 修改网卡Offload参数的状态。
-p 用于区别不同ethX对应网卡的物理位置,常用的方法是使网卡port上的led不断的闪;N指示了网卡闪的持续时间,以秒为单位。
-r 如果auto-negotiation模块的状态为on,则restarts auto-negotiation。
-S 显示NIC- and driver-specific 的统计参数,如网卡接收/发送的字节数、接收/发送的广播包个数等。
-t 让网卡执行自我检测,有两种模式:offline or online。
-s 修改网卡的部分配置,包括网卡速度、单工/全双工模式、mac地址等。

查看网卡速度

[root@localhost~]#ethtool eth0
Settings for eth0:
    Supported ports: [ TP ]
    Supported link modes:   10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Full 
    Supported pause frame use: No
    Supports auto-negotiation: Yes
    Advertised link modes:  10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Full 
    Advertised pause frame use: No
    Advertised auto-negotiation: Yes
    Speed: 1000Mb/s
    Duplex: Full
    Port: Twisted Pair
    PHYAD: 0
    Transceiver: internal
    Auto-negotiation: on
    MDI-X: Unknown
    Supports Wake-on: d
    Wake-on: d
    Current message level: 0x00000007 (7)
                   drv probe link
    Link detected: yes

查看网卡eth0采用了何种驱动

[root@localhost~]#ethtool -i eth0
driver: e1000
version: 7.3.21-k8-NAPI
firmware-version: 
bus-info: 0000:02:01.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no

查看网卡接收/发送数据的情况

[root@localhost~]#ethtool -S eth0
NIC statistics:
     rx_packets: 2098498
     tx_packets: 512
     rx_bytes: 339979810
     tx_bytes: 28161
     rx_broadcast: 0
     tx_broadcast: 0
     rx_multicast: 0
     tx_multicast: 0
     rx_errors: 0
     tx_errors: 0
     tx_dropped: 0
     multicast: 0
     collisions: 0
     rx_length_errors: 0
     rx_over_errors: 0
     rx_crc_errors: 0
     rx_frame_errors: 0
     rx_no_buffer_count: 0
     rx_missed_errors: 0
     tx_aborted_errors: 0
     tx_carrier_errors: 0
     tx_fifo_errors: 0
     tx_heartbeat_errors: 0
     tx_window_errors: 0
     tx_abort_late_coll: 0
     tx_deferred_ok: 0
     tx_single_coll_ok: 0
     tx_multi_coll_ok: 0
     tx_timeout_count: 0
     tx_restart_queue: 0
     rx_long_length_errors: 0
     rx_short_length_errors: 0
     rx_align_errors: 0
     tx_tcp_seg_good: 0
     tx_tcp_seg_failed: 0
     rx_flow_control_xon: 0
     rx_flow_control_xoff: 0
     tx_flow_control_xon: 0
     tx_flow_control_xoff: 0
     rx_long_byte_count: 339979810
     rx_csum_offload_good: 1720975
     rx_csum_offload_errors: 0
     alloc_rx_buff_failed: 0
     tx_smbus: 0
     rx_smbus: 0
     dropped_smbus: 0

4. ifrename

Name

ifrename - rename network interfaces based on various static criteria
Synopsis

ifrename [-c configfile] [-p] [-d] [-u] [-v] [-V] [-D]
ifrename [-c configfile] [-i interface] [-n newname]
Description


Ifrename is a tool allowing you to assign a consistent name to each of your network interface.
By default, interface names are dynamic, and each network interface is assigned the first available name (eth0, eth1...). The order network interfaces are created may vary. For built-in interfaces, the kernel boot time enumeration may vary. For removable interface, the user may plug them in any order.

Ifrename allow the user to decide what name a network interface will have. Ifrename can use a variety of selectors to specify how interface names match the network interfaces on the system, the most common selector is the interface MAC address.

Ifrename must be run before interfaces are brought up, which is why it's mostly useful in various scripts (init, hotplug) but is seldom used directly by the user. By default, ifrename renames all present system interfaces using mappings defined in /etc/iftab.

Parameters

-c configfile
Set the configuration file to be used (by default /etc/iftab). The configuration file define the mapping between selectors and interface names, and is described in iftab(5).
If configfile is "-", the configuration is read from stdin.
-p
Probe (load) kernel modules before renaming interfaces. By default ifrename only check interfaces already loaded, and doesn't auto-load the required kernel modules. This option enables smooth integration with system not loading modules before calling ifrename.
-d
Enable various Debian specific hacks. Combined with -p, only modules for interfaces specified in /etc/network/interface are loaded.
-i interface
Only rename the specified interface as opposed to all interfaces on the system. The new interface name is printed.
-n newname
When used with -i, specify the new name of the interface. The list of mappings from the configuration file is bypassed, the interface specified with -i is renamed directly to newname. The new name may be a wildcard containing a single '*'.
When used without -i, rename interfaces by using only mappings that would rename them to newname. The new name may not be a wildcard. This use of ifrename is discouraged, because inefficient (-n without -i). All the interfaces of the system need to be processed at each invocation, therefore in most case it is not faster than just letting ifrename renaming all of them (without both -n and -i).
-t
Enable name takeover support. This allow interface name swapping between two or more interfaces.
Takeover enable an interface to 'steal' the name of another interface. This works only with kernel 2.6.X and if the other interface is down. Consequently, this is not compatible with Hotplug. The other interface is assigned a random name, but may be renamed later with 'ifrename'.
The number of takeovers is limited to avoid circular loops, and therefore some complex multi-way name swapping situations may not be fully processed.
In any case, name swapping and the use of this feature is discouraged, and you are invited to choose unique and unambiguous names for your interfaces...
-u
Enable udev output mode. This enables proper integration of ifrename in the udev framework, udevd(8) will use ifrename to assign interface names present in /etc/iftab. In this mode the output of ifrename can be parsed directly by udevd(8) as an IMPORT action. This requires udev version 107 or later.
-D
Dry-run mode. Ifrename won't change any interface, it will only print new interface name, if applicable, and return.
In dry-run mode, interface name wildcards are not resolved. New interface name is printed, even if it is the same as the old name.
Be also aware that some selectors can only be read by root, for example those based on ethtool), and will fail silently if run by a normal user. In other words, dry-run mode under a standard user may not give the expected result.
-V
Verbose mode. Ifrename will display internal results of parsing its configuration file and querying the interfaces selectors. Combined with the dry-run option, this is a good way to debug complex configurations or trivial problems.

Files

/etc/iftab
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,937评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,503评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,712评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,668评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,677评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,601评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,975评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,637评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,881评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,621评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,710评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,387评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,971评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,947评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,189评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,805评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,449评论 2 342

推荐阅读更多精彩内容