ifconfig命令的使用

2023-01-04,

ifconfig命令

用途:配置或显示TCP/IP网络的网络接口参数。

*1、通过--help学习ifconfig的使用

点击查看代码
[root@rocky8 ~]# ifconfig --help
Usage:
ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
[add <address>[/<prefixlen>]]
[del <address>[/<prefixlen>]]
[[-]broadcast [<address>]] [[-]pointopoint [<address>]]
[netmask <address>] [dstaddr <address>] [tunnel <address>]
[outfill <NN>] [keepalive <NN>]
[hw <HW> <address>] [mtu <NN>]
[[-]trailers] [[-]arp] [[-]allmulti]
[multicast] [[-]promisc]
[mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]
[txqueuelen <NN>]
[[-]dynamic]
[up|down] ... <HW>=Hardware Type.
List of possible hardware types:
loop (Local Loopback) slip (Serial Line IP) cslip (VJ Serial Line IP)
slip6 (6-bit Serial Line IP) cslip6 (VJ 6-bit Serial Line IP) adaptive (Adaptive Serial Line IP)
ash (Ash) ether (Ethernet) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) rose (AMPR ROSE) tunnel (IPIP Tunnel)
ppp (Point-to-Point Protocol) hdlc ((Cisco)-HDLC) lapb (LAPB)
arcnet (ARCnet) dlci (Frame Relay DLCI) frad (Frame Relay Access Device)
sit (IPv6-in-IPv4) fddi (Fiber Distributed Data Interface) hippi (HIPPI)
irda (IrLAP) x25 (generic X.25) infiniband (InfiniBand)
eui64 (Generic EUI-64)
<AF>=Address family. Default: inet
List of possible address families:
unix (UNIX Domain) inet (DARPA Internet) inet6 (IPv6)
ax25 (AMPR AX.25) netrom (AMPR NET/ROM) rose (AMPR ROSE)
ipx (Novell IPX) ddp (Appletalk DDP) ash (Ash)
x25 (CCITT X.25)

* 2、通过man学习ifconfig的使用

点击查看代码
[root@rocky8 ~]# man ifconfig
IFCONFIG(8) Linux System Administrator's Manual IFCONFIG(8) NAME
ifconfig - configure a network interface SYNOPSIS
ifconfig [-v] [-a] [-s] [interface]
ifconfig [-v] interface [aftype] options | address ... NOTE
This program is obsolete! For replacement check ip addr and ip link. For statistics use ip -s link. DESCRIPTION
Ifconfig is used to configure the kernel-resident network interfaces. It is used at boot time to set up interfaces
as necessary. After that, it is usually only needed when debugging or when system tuning is needed. If no arguments are given, ifconfig displays the status of the currently active interfaces. If a single interface
argument is given, it displays the status of the given interface only; if a single -a argument is given, it dis
plays the status of all interfaces, even those that are down. Otherwise, it configures an interface. Address Families
If the first argument after the interface name is recognized as the name of a supported address family, that
address family is used for decoding and displaying all protocol addresses. Currently supported address families
include inet (TCP/IP, default), inet6 (IPv6), ax25 (AMPR Packet Radio), ddp (Appletalk Phase 2), ipx (Novell IPX)
and netrom (AMPR Packet radio). All numbers supplied as parts in IPv4 dotted decimal notation may be decimal,
octal, or hexadecimal, as specified in the ISO C standard (that is, a leading 0x or 0X implies hexadecimal; other
wise, a leading '0' implies octal; otherwise, the number is interpreted as decimal). Use of hexadecimal and octal
numbers is not RFC-compliant and therefore its use is discouraged. OPTIONS
-a display all interfaces which are currently available, even if down -s display a short list (like netstat -i) -v be more verbose for some error conditions interface
The name of the interface. This is usually a driver name followed by a unit number, for example eth0 for
the first Ethernet interface. If your kernel supports alias interfaces, you can specify them with syntax
like eth0:0 for the first alias of eth0. You can use them to assign more addresses. To delete an alias
interface use ifconfig eth0:0 down. Note: for every scope (i.e. same net with address/netmask combination)
all aliases are deleted, if you delete the first (primary). up This flag causes the interface to be activated. It is implicitly specified if an address is assigned to the
interface; you can suppress this behavior when using an alias interface by appending an - to the alias (e.g.
eth0:0-). It is also suppressed when using the IPv4 0.0.0.0 address as the kernel will use this to implic
itly delete alias interfaces. down This flag causes the driver for this interface to be shut down. [-]arp Enable or disable the use of the ARP protocol on this interface. [-]promisc
Enable or disable the promiscuous mode of the interface. If selected, all packets on the network will be
received by the interface. [-]allmulti
Enable or disable all-multicast mode. If selected, all multicast packets on the network will be received by
the interface. mtu N This parameter sets the Maximum Transfer Unit (MTU) of an interface. dstaddr addr
Set the remote IP address for a point-to-point link (such as PPP). This keyword is now obsolete; use the
pointopoint keyword instead. netmask addr
Set the IP network mask for this interface. This value defaults to the usual class A, B or C network mask
(as derived from the interface IP address), but it can be set to any value. add addr/prefixlen
Add an IPv6 address to an interface. del addr/prefixlen
Remove an IPv6 address from an interface. tunnel ::aa.bb.cc.dd
Create a new SIT (IPv6-in-IPv4) device, tunnelling to the given destination. irq addr
Set the interrupt line used by this device. Not all devices can dynamically change their IRQ setting. io_addr addr
Set the start address in I/O space for this device. mem_start addr
Set the start address for shared memory used by this device. Only a few devices need this. media type
Set the physical port or medium type to be used by the device. Not all devices can change this setting, and
those that can vary in what values they support. Typical values for type are 10base2 (thin Ethernet),
10baseT (twisted-pair 10Mbps Ethernet), AUI (external transceiver) and so on. The special medium type of
auto can be used to tell the driver to auto-sense the media. Again, not all drivers can do this. [-]broadcast [addr]
If the address argument is given, set the protocol broadcast address for this interface. Otherwise, set (or
clear) the IFF_BROADCAST flag for the interface. [-]pointopoint [addr]
This keyword enables the point-to-point mode of an interface, meaning that it is a direct link between two
machines with nobody else listening on it.
If the address argument is also given, set the protocol address of the other side of the link, just like the
obsolete dstaddr keyword does. Otherwise, set or clear the IFF_POINTOPOINT flag for the interface. hw class address
Set the hardware address of this interface, if the device driver supports this operation. The keyword must
be followed by the name of the hardware class and the printable ASCII equivalent of the hardware address.
Hardware classes currently supported include ether (Ethernet), ax25 (AMPR AX.25), ARCnet and netrom (AMPR
NET/ROM). multicast
Set the multicast flag on the interface. This should not normally be needed as the drivers set the flag cor
rectly themselves. address
The IP address to be assigned to this interface. txqueuelen length
Set the length of the transmit queue of the device. It is useful to set this to small values for slower
devices with a high latency (modem links, ISDN) to prevent fast bulk transfers from disturbing interactive
traffic like telnet too much. NOTES
Since kernel release 2.2 there are no explicit interface statistics for alias interfaces anymore. The statistics
printed for the original address are shared with all alias addresses on the same device. If you want per-address
statistics you should add explicit accounting rules for the address using the iptables(8) command. Since net-tools 1.60-4 ifconfig is printing byte counters and human readable counters with IEC 60027-2 units. So 1
KiB are 2^10 byte. Note, the numbers are truncated to one decimal (which can by quite a large error if you consider
0.1 PiB is 112.589.990.684.262 bytes :) Interrupt problems with Ethernet device drivers fail with EAGAIN (SIOCSIIFLAGS: Resource temporarily unavailable)
it is most likely a interrupt conflict. See http://www.scyld.com/expert/irq-conflict.html for more information. FILES
/proc/net/dev
/proc/net/if_inet6 BUGS
Ifconfig uses the ioctl access method to get the full address information, which limits hardware addresses to 8
bytes. Because Infiniband hardware address has 20 bytes, only the first 8 bytes are displayed correctly. Please
use ip link command from iproute2 package to display link layer informations including the hardware address. While appletalk DDP and IPX addresses will be displayed they cannot be altered by this command. SEE ALSO
ip(8), iptables(8)
http://physics.nist.gov/cuu/Units/binary.html - Prefixes for binary multiples AUTHORS
Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
Alan Cox, <Alan.Cox@linux.org>
Phil Blundell, <Philip.Blundell@pobox.com>
Andi Kleen
Bernd Eckenfels, <net-tools@lina.inka.de> net-tools 2008-10-03 IFCONFIG(8)

* 3、参数解释

点击查看代码
-a        显示全部接口信息
-s 显示摘要信息(类似于 netstat -i)
-v 对某些错误条件更加详细
interface 接口名称。这通常是一个驱动程序名称后面跟着一个单元号,例如eth0表示第一个以太网接口。如果您的内核支持别名接口,您可以使
用类似eth0:0这样的语法来指定eth0的第一个别名。您可以使用它们分配更多的地址。使用ifconfig eth0:0 down命令删除别名
接口。注意:对于每个作用域(即地址/掩码组合相同的网络),如果你删除了第一个(主),所有的别名都会被删除。
up 该标志使接口被激活。如果将地址分配给接口,则隐式指定;在使用别名接口时,可以通过向别名追加-(例如eth0:0-)来抑制这种行
为。当使用IPv4 0.0.0.0地址时,它也会被抑制,因为内核将使用该地址隐式删除别名接口。
down 关闭指定网络设备/网卡。该参数可以有效地阻止通过指定接口的IP信息流,如果想永久地关闭一个接口,我们还需要从核心路由表中
将该接口的路由信息全部删除。
[-]arp 设置指定网卡是否支持ARP协议。
[-]promisc 设置是否支持网卡的promiscuous模式,如果选择此参数,网卡将接收网络中发给它所有的数据包
[-]allmulti 设置是否支持多播模式,如果选择此参数,网卡将接收网络中所有的多播数据包
mtu<字节数> 设置网卡的最大传输单元 (bytes)
dstaddr addr 设定一个远端地址,建立点对点通信
netmask addr 设置接口的IP网络掩码。该值默认为通常的A、B或C类网络掩码(源自接口IP地址),但可以设置为任何值。
add addr/prefixlen 给指定网卡配置IPv6地址
del addr/prefixlen 删除指定网卡的IPv6地址
tunnel<地址> 建立IPv4与IPv6之间的隧道通信地址。
irq<IRQ地址> 设置网络设备的IRQ。
io_addr<I/O地址> 设置网络设备的I/O地址。
netmask <子网掩码> 设置网卡的子网掩码。掩码可以是有前缀0x的32位十六进制数,也可以是用点分开的4个十进制数。如果不打算将网络分
成子网,可以不管这一选项;如果要使用子网,那么请记住,网络中每一个系统必须有相同子网掩码。
mem_start addr 设置此设备使用的共享内存的起始地址。只有少数设备需要这个功能。
media type 设置设备使用的物理端口或介质类型。并不是所有的设备都可以更改这个设置,而且那些设备支持的值也会有所不同。类型的
典型值是10base2(薄以太网)、10baseT(双绞线10Mbps以太网)、AUI(外部收发器)等等。驱动的特殊媒体类型可以用来告诉
驱动自动感知 媒体。同样,不是所有的驱动都能做到这一点。
-broadcast<地址> 为指定网卡设置广播协议
-pointtopoint<地址> 为网卡设置点对点通讯协议
hw class address 如果设备驱动支持此操作,请设置该接口的硬件地址。关键字后面必须跟硬件类的名称和硬件地址的可打印的等价ASCII
码。目前支持的硬件类包括ether (Ethernet)、ax25 (AMPR AX.25)、ARCnet和netrom (AMPR NET/ROM)。
multicast 为网卡设置组播标志
address 为网卡设置IPv4地址
txqueuelen<长度> 为网卡设置传输列队的长度

* 4、常用的参数
- a 显示当前可用的所有接口,即使是关闭的

点击查看代码
[root@rocky8 ~]# ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.130 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::20c:29ff:fee6:9baa prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:e6:9b:aa txqueuelen 1000 (Ethernet)
RX packets 9900 bytes 12885285 (12.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2713 bytes 261793 (255.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 86 bytes 11920 (11.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 86 bytes 11920 (11.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:a2:67:02 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

- s 显示一个简短的列表(如netstat -i),查看网卡收发包和MTU值等

点击查看代码
[root@rocky8 ~]# ifconfig -s
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
ens33 1500 9927 0 0 0 2730 0 0 0 BMRU
lo 65536 86 0 0 0 86 0 0 0 LRU
virbr0 1500 0 0 0 0 0 0 0 0 BMU

* 5、启动关闭指定网卡

点击查看代码
ifconfig ens33 up          # 启动ens33端口
ifconfig ens33 down # 关闭ens33端口

ifconfig命令的使用的相关教程结束。

《ifconfig命令的使用.doc》

下载本文的Word格式文档,以方便收藏与打印。