CentOS下ifconfig命令詳細解析

來源:互聯網
上載者:User

CentOS下ifconfig命令詳細解析

1.測試環境:

[root@lvskeep ~]# cat /etc/redhat-release

CentOS release 5.4 (Final)

[root@lvskeep ~]# uname -r

2.6.18-164.el5

[root@lvskeep ~]# ifconfig#原生網路設定

eth0Link encap:EthernetHWaddr 00:0C:29:BC:7A:11

inet addr:10.0.0.30Bcast:10.0.0.255Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:febc:7a11/64 Scope:Link

UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1

RX packets:893 errors:0 dropped:0 overruns:0 frame:0

TX packets:447 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:91733 (89.5 KiB)TX bytes:84456 (82.4 KiB)

Interrupt:185 Base address:0x1400

eth1Link encap:EthernetHWaddr00:0C:29:BC:7A:1B

inet addr:192.168.0.30Bcast:192.168.0.255Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:febc:7a1b/64 Scope:Link

UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1

RX packets:25 errors:0 dropped:0 overruns:0 frame:0

TX packets:44 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:6622 (6.4 KiB)TX bytes:7942 (7.7 KiB)

Interrupt:169 Base address:0x1480

loLink encap:Local Loopback

inet addr:127.0.0.1Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNINGMTU:16436Metric:1

RX packets:16 errors:0 dropped:0 overruns:0 frame:0

TX packets:16 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:1224 (1.1 KiB)TX bytes:1224 (1.1 KiB)

說明:

eth0表示第一塊網卡, 其中HWaddr表示網卡的物理地址,我們可以看到目前這

個網卡的物理地址(MAC地址)是00:0C:29:BC:7A:1B;inet addr用來表示網卡

的IP地址,此網卡的IP地址是10.0.0.30, 廣播位址,

Bcast:10.0.0.255,掩碼地址Mask:255.255.255.0

lo是表示主機的回壞地址,這個一般是用來測試一個網路程式,但又不想讓局域

網或外網的使用者能夠查看,只能在此台主機上運行和查看所用的網路介面。比如我

們把HTTPD伺服器的指定到回壞地址,在瀏覽器輸入127.0.0.1就能看到你所架

WEB網站了。但只是您能看得到,區域網路的其它主機或使用者無從知道;

2.通過man命令查看系統內建的協助

[root@lvskeep ~]# man ifconfig

NAME

ifconfig - configure a network interface

SYNOPSIS#摘要,概要,大意

ifconfig [interface]

ifconfig interface [aftype] options | address ...

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 tuningis 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 isgiven, it displays 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; otherwise, a leading implies octal; otherwise,the number is interpreted as decimal). Use of hexamedial and octal numbers is not RFC-compliant and therefore itsuse is discouraged and may go away.

OPTIONS

Interface#e.g eth0、eth1

Thename of the interface.This is usually a driver name followed by a unit number, for example eth0 for the first Ethernet interface.

e.g

[root@lvskeep ~]# ifconfig eth0

eth0Link encap:EthernetHWaddr 00:0C:29:BC:7A:11

inet addr:10.0.0.30Bcast:10.0.0.255Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:febc:7a11/64 Scope:Link

UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1

RX packets:673 errors:0 dropped:0 overruns:0 frame:0

TX packets:338 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:68647 (67.0 KiB)TX bytes:66442 (64.8 KiB)

Interrupt:185 Base address:0x1400

upThis flag causes the interface to be activated.It is implicitlyspecifiedifanaddressis assigned to the interface.

e.g

在虛擬機器上執行ifconfig eth0 up命令,啟用eth0

[root@lvskeep ~]# ifconfig eth0 up

[root@lvskeep ~]# ifconfig#驗證是否啟用

eth0Link encap:EthernetHWaddr 00:0C:29:BC:7A:11

inet addr:10.0.0.30Bcast:10.0.0.255Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:febc:7a11/64 Scope:Link

UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1

RX packets:893 errors:0 dropped:0 overruns:0 frame:0

TX packets:447 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:91733 (89.5 KiB)TX bytes:84456 (82.4 KiB)

Interrupt:185 Base address:0x1400

eth1Link encap:EthernetHWaddr 00:0C:29:BC:7A:1B

inet addr:192.168.0.30Bcast:192.168.0.255Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:febc:7a1b/64 Scope:Link

UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1

RX packets:25 errors:0 dropped:0 overruns:0 frame:0

TX packets:44 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:6622 (6.4 KiB)TX bytes:7942 (7.7 KiB)

Interrupt:169 Base address:0x1480

loLink encap:Local Loopback

inet addr:127.0.0.1Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNINGMTU:16436Metric:1

RX packets:16 errors:0 dropped:0 overruns:0 frame:0

TX packets:16 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:1224 (1.1 KiB)TX bytes:1224 (1.1 KiB)

看到eth0已經成功啟用

downThis flag causes the driver for this interface to be shut down.

e.g

SecureCRT軟體

[root@lvskeep ~]#ifconfig eth0 down

結果:游標不停閃爍

直接在虛擬機器裡操作

[root@lvskeep ~]# ifconfig

eth1Link encap:EthernetHWaddr 00:0C:29:BC:7A:1B

inet addr:192.168.0.30Bcast:192.168.0.255Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:febc:7a1b/64 Scope:Link

UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1

RX packets:25 errors:0 dropped:0 overruns:0 frame:0

TX packets:44 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:6622 (6.4 KiB)TX bytes:7942 (7.7 KiB)

Interrupt:169 Base address:0x1480

loLink encap:Local Loopback

inet addr:127.0.0.1Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNINGMTU:16436Metric:1

RX packets:16 errors:0 dropped:0 overruns:0 frame:0

TX packets:16 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:1224 (1.1 KiB)TX bytes:1224 (1.1 KiB)

說明:執行ifconfig eth0 down命令後,網卡eth0就停掉了,不工作了,已經斷開了串連,而SecureCRT就是通過eth0串連的虛擬機器,所以游標會一直閃爍;通過在虛擬機器上執行ifconfig命令驗證,eth0確實停掉了。

[-]arpEnable or disable the use of the ARP protocol on this interface.

e.g

[root@lvskeep ~]# ifconfig eth0 –arp#關閉了ARP協議

執行完此命令後,SecureCRT和虛擬機器中斷連線。關閉ARP,IP地址和MAC地址失去了對應關係,無法識別對應的主機。

[root@lvskeep ~]# ifconfig eth0 arp#開啟ARP協議

再次串連正常arp命令(附錄一)

[-]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 willbe received by the interface.

metric N#指定在計算資料包的轉送次數時,所要加上的數目

This parameter sets the interface metric.

mtu NThis parameter sets the Maximum Transfer Unit (MTU) of an interface.

#設定網路裝置的MTU

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 classA,BorC network mask (as derived from the interface IP address), but it can be set to any value.

e.g

[root@lvskeep ~]# ifconfig eth1 192.168.0.30 netmask255.255.0.0#子網路遮罩

[root@lvskeep ~]# ifconfig eth1

eth1Link encap:EthernetHWaddr 00:0C:29:BC:7A:1B

inet addr:192.168.0.30Bcast:192.168.255.255Mask:255.255.0.0

inet6 addr: fe80::20c:29ff:febc:7a1b/64 Scope:Link

UP BROADCAST RUNNING NOARP MULTICASTMTU:1500Metric:1

RX packets:25 errors:0 dropped:0 overruns:0 frame:0

TX packets:54 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:6622 (6.4 KiB)TX bytes:11144 (10.8 KiB)

Interrupt:169 Base address:0x1480

注意:netmask不能大寫

add addr/prefixlen

Add an IPv6 address to an interface.#設定網路裝置IPv6的IP地址

deladdr/prefixlen

Remove an IPv6 address from an interface.#刪除網路裝置IPv6的IP地址

tunnel aa.bb.cc.dd

Create a new SIT (IPv6-in-IPv4) device, tunnelling to the given destination.#建立IPv4與IPv6之間的隧道通訊地址

irq addr

Settheinterruptlineused by this device.Not all devices can dynamically change their IRQ setting.#置網路裝置的IRQ

io_addr addr#設定網路裝置的I/O地址

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 canchange this setting,andthosethatcanvaryinwhat values they support.Typical values for type are 10base2 (thin Ethernet), 10baseT (twisted-pair 10Mbps Ethernet), AUI (externaltransceiver)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.Other-wise, set (or clear) the IFF_BROADCAST flag for the interface.

[-]pointopoint [addr]#與指定地址的網路裝置建立直接連線,此模式具有保密功能。

Thiskeywordenablesthe 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 sideofthelink,justlike 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 supportsthisoperation.The

multicast

Setthemulticastflag on the interface. This should not normally be needed as the drivers set the flag correctly 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 valuesfor slowerdeviceswith a high latency (modem links, ISDN) to prevent fast bulk transfers from dis-

turbing interactive traffic like telnet too much.

NOTES

Since kernel release 2.2 there are no explicit interface statistics for aliasinterfacesanymore.The statisticsprintedfor the original address are shared with all alias addresses on the same device. Ifyou want per-address statistics you should add explicit accounting rules for the address usingthe ipchains(8) command.

Interruptproblemswith Ethernet device drivers fail with EAGAIN. See http://www.scyld.com/expert/irq-conflict.html for more information.

FILES

/proc/net/socket

/proc/net/dev

/proc/net/if_inet6

BUGS

While appletalk DDP and IPX addresses will be displayed they cannot be altered by this command.

SEE ALSO

route(8), netstat(8), arp(8), rarp(8), ipchains(8)

AUTHORS

Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>

Alan Cox, <Alan.Cox@linux.org>

Phil Blundell, <Philip.Blundell@pobox.com>

Andi Kleen

net-tools14 August 2000IFCONFIG(8)

執行個體:

1.如果我們想知道主機所有網路介面的情況,請用下面的命令:

[root@lvskeep ~]# ifconfig -a

eth0Link encap:EthernetHWaddr 00:0C:29:BC:7A:11

inet addr:10.0.0.30Bcast:10.0.0.255Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:febc:7a11/64 Scope:Link

UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1

RX packets:2974 errors:0 dropped:0 overruns:0 frame:0

TX packets:1342 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:280167 (273.6 KiB)TX bytes:214214 (209.1 KiB)

Interrupt:185 Base address:0x1400

eth1Link encap:EthernetHWaddr 00:0C:29:BC:7A:1B

inet addr:192.168.0.30Bcast:192.168.0.255Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:febc:7a1b/64 Scope:Link

UP BROADCAST RUNNING NOARP MULTICASTMTU:1500Metric:1

RX packets:25 errors:0 dropped:0 overruns:0 frame:0

TX packets:66 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:6622 (6.4 KiB)TX bytes:14376 (14.0 KiB)

Interrupt:169 Base address:0x1480

loLink encap:Local Loopback

inet addr:127.0.0.1Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNINGMTU:16436Metric:1

RX packets:108 errors:0 dropped:0 overruns:0 frame:0

TX packets:108 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:11816 (11.5 KiB)TX bytes:11816 (11.5 KiB)

sit0Link encap:IPv6-in-IPv4

NOARPMTU:1480Metric:1

RX packets:0 errors:0 dropped:0 overruns:0 frame:0

TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:0 (0.0 b)TX bytes:0 (0.0 b)

2.如果我們想查看某個連接埠,比如我們想查看eth1的狀態,就可以用下面的方法

[root@lvskeep ~]# ifconfig eth1

eth1Link encap:EthernetHWaddr 00:0C:29:BC:7A:1B

inet addr:192.168.0.30Bcast:192.168.0.255Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:febc:7a1b/64 Scope:Link

UP BROADCAST RUNNING NOARP MULTICASTMTU:1500Metric:1

RX packets:25 errors:0 dropped:0 overruns:0 frame:0

TX packets:66 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:6622 (6.4 KiB)TX bytes:14376 (14.0 KiB)

Interrupt:169 Base address:0x1480

ifconfig配置網路連接埠的方法

ifconfig工具配置網路介面的方法是通過指令的參數來達到目的的

ifconfig網路連接埠IP地址hw <HW>MAC地址netmask掩碼地址

broadcast廣播位址[up/down]

3.用ifconfig來調試eth1網卡的地址

[root@lvskeep ~]# ifconfig eth1 down

[root@lvskeep ~]# ifconfig eth1 192.168.1.30 broadcast 192.168.1.255 netmask 255.255.255.0

[root@lvskeep ~]# ifconfig eth1 up

[root@lvskeep ~]# ifconfig eth1

eth1Link encap:EthernetHWaddr 00:0C:29:BC:7A:1B

inet addr:192.168.1.30Bcast:192.168.1.255Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:febc:7a1b/64 Scope:Link

UP BROADCAST RUNNING NOARP MULTICASTMTU:1500Metric:1

RX packets:25 errors:0 dropped:0 overruns:0 frame:0

TX packets:91 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:6622 (6.4 KiB)TX bytes:21736 (21.2 KiB)

Interrupt:169 Base address:0x1480

說明:

第一行:ifconfig eth0 down表示如果eth0是啟用的,就把它DOWN掉。此命令等同於ifdown eth0;

第二行:用ifconfig來配置eth0的IP地址、廣播位址和網路遮罩;

第三行:用ifconfig eth0 up來啟用eth0; 此命令等同於ifup eth0

第四行:用ifconfig eth0來查看eth0的狀態;

也可以用直接在指令IP地址、網路遮罩、廣播位址的同時,啟用網卡;要加up參數

[root@lvskeep ~]# ifconfig eth1 192.168.1.30 broadcast 192.168.1.255 netmask 255.255.255.0 up

4.設定網卡eth1的IP地址、網路遮罩、廣播位址,物理地址並且啟用它

[root@lvskeep ~]# ifconfig eth1 192.168.0.30 hw ether 00:0C:29:BC:7A:11broadcast 192.168.0.255 netmask 255.255.255.0 up

SIOCSIFHWADDR: Device or resource busy

先停掉然後再改,MAC地址最好別改,很容易出錯,個人理解。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.