当前位置:网站首页>ifconfig与ip命令的比较
ifconfig与ip命令的比较
2022-08-11 02:15:00 【yuyuyuliang00】
基于Linux发行版提供了用简单和强大方式配置网络的命令行工具。这些命令集合从net-tools软件包获取,这个软件包在绝大多数发行版中存在了很长时间,并且包含像ifconfig, route, nameif, iwconfig, iptunnel, netstat, arp的命令。
这些命令对于任何新手或者linux专家在配置网络中基本已经够用了,但因为在过去几年Linux内核的进步以及未维护这个命令包集合,它们被弃用了并且一个能够替代所有这些命令的更强大替代品出现了。
这个替代品已经出现很长一段时间了并且要比任何这些命令更强大。余下部分将重点强调这个替代品并且把它与来自net-tools包一个命令(ifconfig)做比较。
ip用于替代ifconfig
ifconfig已经存在很长时间了,并且仍然被很多人用于配置,显示以及控制网络接口,但现在在Linux发行版上存在一个新的替代品,它比ifconfig要强大的多。这个替代品是来自iproute软件包的ip命令。
[[email protected] network-scripts]# yum whatprovides "ip"
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.lzu.edu.cn
* epel: ftp.iij.ad.jp
* extras: mirror.lzu.edu.cn
* updates: download.nus.edu.sg
iproute-4.11.0-30.el7.x86_64 : Advanced IP routing and network device configuration tools
Repo : base
Matched from:
Filename : /usr/sbin/ip
虽然这个命令起初看起来有点复杂,但功能上比ifconfig更加全面。在两层网络栈功能上组织它,即是第二层(数据链路层),第三层(IP层),并且具有来自net-tools软件包以上提及命令的所有功能。
ifconfig基本上显示或修改系统的接口,ip命令能够做以下任务:
- 显示或修改接口属性
- 添加、移除ARP缓存条目以及未主机创建新的静态ARP条目
- 显示与所有接口相关的MAC地址
- 显示和修改内核路由表
ip命令其中一个主要不同于ifconfig的重点是使用ioctl用于网络配置,ifconfig使用ioctl用于网络配置,这是一种与内核交互不受欢迎的方式,ip为相同目的利用netlink套接字机制,这是使用rtnetlink用于内核和用户空间之间内部通信的ioctl的更加灵活的继任者。
我们现在开始突出ifconfig的特性并且如何有效地用ip命令替代它们。
ip vs ifconfig命令
以下部分强调ifconfig命令以及使用ip命令替换:
1、在Linux中显示所有网络接口
ifconfig命令
[[email protected] network-scripts]# ifconfig
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.50.74 netmask 255.255.255.0 broadcast 192.168.50.255
inet6 fe80::755d:a1a5:8380:e9f9 prefixlen 64 scopeid 0x20<link>
ether 00:19:0f:3d:c9:3d txqueuelen 1000 (Ethernet)
RX packets 1079386 bytes 104138658 (99.3 MiB)
RX errors 0 dropped 1027598 overruns 0 frame 0
TX packets 7795 bytes 711277 (694.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 20 memory 0xf7f00000-f7f20000
...
enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.30 netmask 255.255.255.0 broadcast 192.168.3.255
inet6 fe80::53ff:e021:58e4:1629 prefixlen 64 scopeid 0x20<link>
ether c4:00:ad:54:a3:23 txqueuelen 1000 (Ethernet)
RX packets 21748 bytes 1311860 (1.2 MiB)
RX errors 0 dropped 21271 overruns 0 frame 0
TX packets 123 bytes 13015 (12.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xf6f00000-f6ffffff
...
ip命令
[[email protected] network-scripts]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether c4:00:ad:54:a3:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.30/24 brd 192.168.3.255 scope global noprefixroute enp3s0
valid_lft forever preferred_lft forever
inet6 fe80::53ff:e021:58e4:1629/64 scope link noprefixroute
valid_lft forever preferred_lft forever
...
8: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:19:0f:3d:c9:3d brd ff:ff:ff:ff:ff:ff
inet 192.168.50.74/24 brd 192.168.50.255 scope global noprefixroute dynamic eno1
valid_lft 81779sec preferred_lft 81779sec
inet6 fe80::755d:a1a5:8380:e9f9/64 scope link noprefixroute
valid_lft forever preferred_lft forever
...
2、添加或删除IP地址
ifconfig添加IP地址
[[email protected] network-scripts]# ifconfig enp3s0 add 192.168.3.31
[[email protected] network-scripts]# ip addr show enp3s0
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether c4:00:ad:54:a3:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.30/24 brd 192.168.3.255 scope global noprefixroute enp3s0
valid_lft forever preferred_lft forever
inet 192.168.3.31/24 brd 192.168.3.255 scope global secondary enp3s0:0
valid_lft forever preferred_lft forever
inet6 fe80::53ff:e021:58e4:1629/64 scope link noprefixroute
valid_lft forever preferred_lft forever
ifconfig删除IP地址
[[email protected] network-scripts]# ifconfig enp3s0 del 192.168.3.31
[[email protected] network-scripts]# ip addr show enp3s0
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether c4:00:ad:54:a3:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.30/24 brd 192.168.3.255 scope global noprefixroute enp3s0
valid_lft forever preferred_lft forever
inet6 fe80::53ff:e021:58e4:1629/64 scope link noprefixroute
valid_lft forever preferred_lft forever
ip添加IP地址
[[email protected] network-scripts]# ip addr add 192.168.3.31 dev enp3s0
[[email protected] network-scripts]# ip addr show enp3s0
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether c4:00:ad:54:a3:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.30/24 brd 192.168.3.255 scope global noprefixroute enp3s0
valid_lft forever preferred_lft forever
inet 192.168.3.31/32 scope global enp3s0
valid_lft forever preferred_lft forever
inet6 fe80::53ff:e021:58e4:1629/64 scope link noprefixroute
valid_lft forever preferred_lft forever
ip删除IP地址
[[email protected] network-scripts]# ip addr del 192.168.3.31 dev enp3s0
Warning: Executing wildcard deletion to stay compatible with old scripts.
Explicitly specify the prefix length (192.168.3.31/32) to avoid this warning.
This special behaviour is likely to disappear in further releases,
fix your scripts!
[[email protected] network-scripts]# ip addr show enp3s0
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether c4:00:ad:54:a3:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.30/24 brd 192.168.3.255 scope global noprefixroute enp3s0
valid_lft forever preferred_lft forever
inet6 fe80::53ff:e021:58e4:1629/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3、添加MAC硬件地址到网络接口
以下命令为接口enp3s0设置硬件地址为命令中指定的值。检查ifconfig命令输出中HWaddr可以确认。
使用ifconfig命令添加MAC地址的语法:
[[email protected] network-scripts]# ifconfig enp3s0 hw ether 00:aa:bb:cc:dd:ee
[[email protected] network-scripts]# ifconfig enp3s0
enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.30 netmask 255.255.255.0 broadcast 192.168.3.255
inet6 fe80::53ff:e021:58e4:1629 prefixlen 64 scopeid 0x20<link>
ether 00:aa:bb:cc:dd:ee txqueuelen 1000 (Ethernet)
RX packets 22661 bytes 1366894 (1.3 MiB)
RX errors 0 dropped 22182 overruns 0 frame 0
TX packets 158 bytes 17635 (17.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xf6f00000-f6ffffff
ip添加MAC地址
使用ip命令添加MAC地址的语法:
[[email protected] network-scripts]# ip link set dev enp3s0 address 00:ee:dd:cc:bb:aa
[[email protected] network-scripts]# ip addr show enp3s0
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:ee:dd:cc:bb:aa brd ff:ff:ff:ff:ff:ff
inet 192.168.3.30/24 brd 192.168.3.255 scope global noprefixroute enp3s0
valid_lft forever preferred_lft forever
inet6 fe80::53ff:e021:58e4:1629/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4、设置网络接口的其它配置
除了IP地址或硬件地址,能够应用于接口的其它配置包括:
- MTU
- 多播标记
- 传输队列长度
- 混杂模式
- 启用或禁用所有多播模式
a) 设置MTU值为2000
ifconfig --其它网络配置
[[email protected] network-scripts]# ifconfig enp3s0 mtu 2000
ip -- 其它网络配置
[[email protected] network-scripts]# ip link set dev enp3s0 mtu 2000
b) 启用或者禁用多播标记
ifconfig
[[email protected] network-scripts]# ifconfig enp3s0 multicast
ip
[[email protected] network-scripts]# ip link set dev enp3s0 multicast on
c) 设置传输队列长度
ifconfig
[[email protected] network-scripts]# ifconfig enp3s0 txqueuelen 1200
ip
[[email protected] network-scripts]# ip link set dev enp3s0 txqueuelen 1200
4) 启用或禁用混杂模式
ifconfig
[[email protected] network-scripts]# ifconfig enp3s0 promisc
ip
[[email protected] network-scripts]# ip link set dev enp3s0 promisc on
5、启用或禁用网络接口
ifconfig禁用特定网络接口
[[email protected] network-scripts]# ifconfig enp3s0 down
[[email protected] network-scripts]# ifconfig enp3s0
enp3s0: flags=4866<BROADCAST,PROMISC,ALLMULTI,MULTICAST> mtu 2000
ether 00:ee:dd:cc:bb:aa txqueuelen 1200 (Ethernet)
RX packets 23966 bytes 1445944 (1.3 MiB)
RX errors 0 dropped 23483 overruns 0 frame 0
TX packets 211 bytes 25494 (24.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xf6f00000-f6ffffff
ifconfig启用特定网络接口
[[email protected] network-scripts]# ifconfig enp3s0 up
[[email protected] network-scripts]# ifconfig enp3s0
enp3s0: flags=4931<UP,BROADCAST,RUNNING,PROMISC,ALLMULTI,MULTICAST> mtu 2000
inet 192.168.3.30 netmask 255.255.255.0 broadcast 192.168.3.255
inet6 fe80::53ff:e021:58e4:1629 prefixlen 64 scopeid 0x20<link>
ether c4:00:ad:54:a3:23 txqueuelen 1200 (Ethernet)
RX packets 23969 bytes 1446147 (1.3 MiB)
RX errors 0 dropped 23486 overruns 0 frame 0
TX packets 228 bytes 28022 (27.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xf6f00000-f6ffffff
ip禁用特定网络接口
[[email protected] network-scripts]# ip link set enp3s0 down
[[email protected] network-scripts]# ip addr show enp3s0
2: enp3s0: <BROADCAST,MULTICAST,ALLMULTI,PROMISC> mtu 2000 qdisc mq state DOWN group default qlen 1200
link/ether 00:ee:dd:cc:bb:aa brd ff:ff:ff:ff:ff:ff
ip启用特定网络接口
[[email protected] network-scripts]# ip link set enp3s0 up
[[email protected] network-scripts]# ip addr show enp3s0
2: enp3s0: <BROADCAST,MULTICAST,ALLMULTI,PROMISC,UP,LOWER_UP> mtu 2000 qdisc mq state UP group default qlen 1200
link/ether c4:00:ad:54:a3:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.30/24 brd 192.168.3.255 scope global noprefixroute enp3s0
valid_lft forever preferred_lft forever
inet6 fe80::53ff:e021:58e4:1629/64 scope link tentative noprefixroute
valid_lft forever preferred_lft forever
6、启用或者禁用ARP协议
以下命令对指定网卡接口启用或禁用ARP协议
ifconfig--启用/禁用ARP协议
以下命令使ARP协议能与接口enp3s0一起使用。要禁用这个选项,只要用-arp替代arp。
[[email protected] network-scripts]# ifconfig enp3s0 arp
[[email protected] network-scripts]# ifconfig enp3s0 -arp
ip--启用或禁用ARP协议
以下命令是ip使得ARP协议能用于接口enp3s0。要禁用它,只要用off替代on。
[[email protected] network-scripts]# ip link set dev enp3s0 arp on
边栏推荐
- [4G/5G/6G专题基础-154]: 5G无线准入控制RAC(Radio Admission Control)
- TRCX: doping process analysis
- 网络安全笔记第四天day4(kali基本操作)
- MySQL权限控制、分区表、快速复制表
- 架构篇(二)架构的复杂度来源
- Future Trends in Vulnerability Management Programs
- Pytorch/TensorFlow/Numpy常用函数汇总
- Oops novice template Framework project guide
- 软件测试面试题:单元测试的策略有哪些?
- Lianshengde W801 series 5-WeChat applet and W801 Bluetooth communication routine (read notes)
猜你喜欢
【oops-framework】模板项目【oops-game-kit】使用简介
117. 本地开发好的 SAP UI5 应用部署到 ABAP 服务器时,中文字符变成乱码的原因分析和解决方案
第二课第一周第4-6节 医学预后案例欣赏+作业解析
[Detailed explanation of C data storage] (1) - in-depth analysis of the storage of shaping data in memory
MySQL - an SQL in MySQL is how to be performed?
Matlab矩阵(数组)元素过滤常见方法详解
Vulnhub靶机:GEMINI INC_ 2
88Q2110 access C45 phy address through C22
[The method of calling the child page from the parent page of the iframe] Stepping on the pit: It is the key to use `[x]` when getting elements. You cannot use `.eq(x)`, otherwise it will not be obtai
学军中学推理社2017届招新试题
随机推荐
js原型和原型链及原型继承
OptiFDTD应用:用于光纤入波导耦合的硅纳米锥仿真
Summary of DDL routine operations in MySQL
通过热透镜聚焦的高斯光束
[4G/5G/6G专题基础-154]: 5G无线准入控制RAC(Radio Admission Control)
WeChat public account background management
Mysql_Note6
经典面试题 之 GC垃圾收集器
软件测试面试题:I P协议、RARP协议、ICMP协议与ARP协议的功能是什么?
Lianshengde W801 series 5-WeChat applet and W801 Bluetooth communication routine (read notes)
async和await的理解和用法
0 in the figure, etc. LeetCode565. Array nesting
How to realize the repeatable design of FPGA
ASEMI整流桥GBJ5010参数,GBJ5010电压,GBJ5010电流
如何解决高度塌陷
【PHP】入门知识
带你系统学习MySQL索引
Js prototype and prototype chain and prototype inheritance
How to create an index when sql uses where and groupby?
The classification of inter-process communication (IPC) and the development of communication methods